From 0717980660ef11da1c268622005e50dcd92c7c5b Mon Sep 17 00:00:00 2001 From: BT-cjimeno Date: Tue, 29 Aug 2023 09:12:09 +0200 Subject: [PATCH] [MOD] MIG V16 | add helper methods from account_statement_import_helper --- .../wizards/account_statement_import.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/account_ebics_oca_statement_import/wizards/account_statement_import.py b/account_ebics_oca_statement_import/wizards/account_statement_import.py index 3f1519d..9aeacb4 100644 --- a/account_ebics_oca_statement_import/wizards/account_statement_import.py +++ b/account_ebics_oca_statement_import/wizards/account_statement_import.py @@ -4,6 +4,8 @@ import logging from odoo import _, models +from odoo.addons.base.models.res_bank import sanitize_account_number + _logger = logging.getLogger(__name__) @@ -78,3 +80,35 @@ class AccountStatementImport(models.TransientModel): """ Inherit this method to set your own statement naming policy. """ + + def _match_journal(self, account_number, currency): + # These changes will probably appear in noviat-apps-1/account_statement_import_helper once migrated + journal = self.env["account.journal"] + sanitized_account_number = self._sanitize_account_number(account_number) + fin_journals = self.env["account.journal"].search( + [ + ("type", "=", "bank"), + "|", + ("currency_id", "=", currency.id), + ("company_id.currency_id", "=", currency.id), + ] + ) + fin_journal = fin_journals.filtered( + lambda r: sanitized_account_number + in (r.bank_account_id.sanitized_acc_number or "") + ) + if len(fin_journal) == 1: + journal = fin_journal + if not journal: + journal = super()._match_journal(account_number, currency) + return journal + + def _sanitize_account_number(self, account_number): + # These changes will probably appear in noviat-apps-1/account_statement_import_helper once migrated + sanitized_number = sanitize_account_number(account_number) + check_curr = sanitized_number[-3:] + if check_curr.isalpha(): + all_currencies = self.env["res.currency"].search([]) + if check_curr in all_currencies.mapped("name"): + sanitized_number = sanitized_number[:-3] + return sanitized_number