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.

52 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2015 Therp BV (<http://therp.nl>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. import base64
  22. from openerp import models, api
  23. class AccountBankStatementImport(models.TransientModel):
  24. _inherit = 'account.bank.statement.import'
  25. @api.model
  26. def _import_file(self, data_file):
  27. (statement_ids, notifications) = \
  28. super(AccountBankStatementImport, self)._import_file(data_file)
  29. if statement_ids:
  30. self.env['account.bank.statement'].browse(statement_ids).write({
  31. 'import_file': self.env['ir.attachment'].create(
  32. self._create_import_file_attachment_data(
  33. data_file, statement_ids[0], notifications)).id,
  34. })
  35. return (statement_ids, notifications)
  36. @api.model
  37. def _create_import_file_attachment_data(self, data_file, statement_id,
  38. notifications):
  39. return {
  40. 'name': '<unknown>',
  41. 'res_model': 'account.bank.statement',
  42. 'res_id': statement_id,
  43. 'type': 'binary',
  44. 'datas': base64.b64encode(data_file),
  45. 'description': '\n'.join(
  46. '%(type)s: %(message)s' % notification
  47. for notification in notifications) or False,
  48. }