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.

39 lines
1.2 KiB

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