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.

38 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. data_file = fields.Binary(
  10. string='Bank Statement File',
  11. required=True,
  12. )
  13. filename = fields.Char()
  14. @api.multi
  15. def create_map_lines(self):
  16. statement_obj = self.env['account.bank.statement.import.paypal.map']
  17. data_file = base64.b64decode(self.data_file)
  18. if not isinstance(data_file, str):
  19. data_file = data_file.decode('utf-8-sig').strip()
  20. file = StringIO(data_file)
  21. file.seek(0)
  22. reader = csv.reader(file)
  23. headers = []
  24. for row in reader:
  25. headers = row
  26. break
  27. lines = []
  28. for idx, title in enumerate(headers):
  29. lines.append((0, 0, {'sequence': idx, 'name': title}))
  30. if lines:
  31. for statement in statement_obj.browse(
  32. self.env.context.get('active_ids')):
  33. statement.map_line_ids = lines