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.

44 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. """Add process_camt method to account.bank.statement.import."""
  3. ##############################################################################
  4. #
  5. # Copyright (C) 2013-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 published
  9. # by the Free Software Foundation, either version 3 of the License, or
  10. # (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 logging
  22. from openerp import models
  23. from openerp.addons.bank_statement_parse.parserlib import convert_statements
  24. from .camt import CamtParser as Parser
  25. _logger = logging.getLogger(__name__)
  26. class AccountBankStatementImport(models.TransientModel):
  27. """Add process_camt method to account.bank.statement.import."""
  28. _inherit = 'account.bank.statement.import'
  29. def _parse_file(self, cr, uid, data_file, context=None):
  30. """Parse a CAMT053 XML file."""
  31. parser = Parser()
  32. try:
  33. _logger.debug("Try parsing with camt.")
  34. return convert_statements(parser.parse(data_file))
  35. except ValueError:
  36. # Not a camt file, returning super will call next candidate:
  37. _logger.debug("Statement file was not a camt file.")
  38. return super(AccountBankStatementImport, self)._parse_file(
  39. cr, uid, data_file, context=context)