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.

41 lines
1.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015 Therp BV (<http://therp.nl>).
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import base64
  5. from odoo import models, api
  6. class AccountBankStatementImport(models.TransientModel):
  7. _inherit = 'account.bank.statement.import'
  8. @api.multi
  9. def import_file(self):
  10. action = \
  11. super(AccountBankStatementImport, self).import_file()
  12. statement_ids = action.get('context', {}).get('statement_ids')
  13. notifications = action.get('context', {}).get('notifications')
  14. data_file = base64.b64decode(self.data_file)
  15. if statement_ids:
  16. self.env['account.bank.statement'].browse(statement_ids).write({
  17. 'import_file': self.env['ir.attachment'].create(
  18. self._create_import_file_attachment_data(
  19. data_file, statement_ids[0], notifications,
  20. self.filename)).id,
  21. })
  22. return action
  23. @api.model
  24. def _create_import_file_attachment_data(self, data_file, statement_id,
  25. notifications, filename=None):
  26. return {
  27. 'name': filename or '<unknown>',
  28. 'res_model': 'account.bank.statement',
  29. 'res_id': statement_id,
  30. 'type': 'binary',
  31. 'datas': base64.b64encode(data_file),
  32. 'datas_fname': filename or '<unknown>',
  33. 'description': '\n'.join(
  34. '%(type)s: %(message)s' % notification
  35. for notification in notifications) or False,
  36. }