You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3 KiB

  1. # Copyright 2019 Tecnativa - Vicent Cubells
  2. # Copyright 2019 Eficent Business and IT Consulting Services, S.L.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. import csv
  5. import base64
  6. from odoo import api, fields, models
  7. from io import StringIO
  8. class WizardTxtMapCreate(models.TransientModel):
  9. _name = 'wizard.txt.map.create'
  10. _description = 'Wizard Txt Map Create'
  11. data_file = fields.Binary(
  12. string='Bank Statement File',
  13. required=True,
  14. )
  15. filename = fields.Char()
  16. @api.multi
  17. def create_map_lines(self):
  18. statement_obj = self.env['account.bank.statement.import.map']
  19. data_file = base64.b64decode(self.data_file)
  20. if not isinstance(data_file, str):
  21. data_file = data_file.decode('utf-8-sig').strip()
  22. file = StringIO(data_file)
  23. file.seek(0)
  24. reader = csv.reader(file)
  25. headers = []
  26. for row in reader:
  27. headers = row
  28. break
  29. lines = []
  30. for idx, title in enumerate(headers):
  31. lines.append((0, 0, {'sequence': idx, 'name': title}))
  32. if lines:
  33. for statement in statement_obj.browse(
  34. self.env.context.get('active_ids')):
  35. statement.map_line_ids = lines