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.

56 lines
1.9 KiB

  1. # Copyright 2019 Camptocamp SA
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. import base64
  4. import logging
  5. from odoo import api, fields, models
  6. from odoo.exceptions import UserError
  7. _logger = logging.getLogger(__name__)
  8. class AccountBankStatementImport(models.TransientModel):
  9. _inherit = "account.bank.statement.import"
  10. check_journal = fields.Boolean(default=True)
  11. check_message = fields.Char(readonly=True)
  12. force_journal = fields.Boolean(
  13. string="Do you want to force this import ?", default=False
  14. )
  15. @api.multi
  16. def import_file(self):
  17. """ Override to make the import in 2 step.
  18. To provide to user possiblity to bypass the journal check.
  19. """
  20. self.ensure_one()
  21. currency_code, account_number, stmts_vals = self.with_context(
  22. active_id=self.ids[0]
  23. )._parse_file(base64.b64decode(self.data_file))
  24. if self.check_journal:
  25. try:
  26. self._find_additional_data(currency_code, account_number)
  27. # _find_additional_data() call _check_journal_bank_account()
  28. # so the self.check_journal value can evolve
  29. except UserError as u_error:
  30. if not self.check_journal:
  31. msg = u_error.args[0]
  32. _logger.info(msg)
  33. self.check_message = str(msg)
  34. action = self.env.ref(
  35. "account_bank_statement_import."
  36. "action_account_bank_statement_import"
  37. ).read([])[0]
  38. action["res_id"] = self.id
  39. return action
  40. return super().import_file()
  41. def _check_journal_bank_account(self, journal, account_number):
  42. check = super()._check_journal_bank_account(journal, account_number)
  43. if self.check_journal:
  44. self.check_journal = False
  45. if self.force_journal:
  46. return True
  47. return check