From 0e93985c2cb834399bf3944e95348f46a97bb041 Mon Sep 17 00:00:00 2001 From: Luc De Meyer Date: Tue, 13 Aug 2024 15:56:49 +0200 Subject: [PATCH] [IMP]account_ebics_oca_statement_import - match journal Remove currency from local bank accounts to find journal. --- .../__manifest__.py | 2 +- .../wizards/account_statement_import.py | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/account_ebics_oca_statement_import/__manifest__.py b/account_ebics_oca_statement_import/__manifest__.py index d305694..f7408c9 100644 --- a/account_ebics_oca_statement_import/__manifest__.py +++ b/account_ebics_oca_statement_import/__manifest__.py @@ -4,7 +4,7 @@ { "name": "account_ebics with OCA Bank Statement Imoort", "summary": "Use OCA Bank Statement Import with account_ebics", - "version": "17.0.1.0.0", + "version": "17.0.1.0.1", "author": "Noviat", "website": "https://www.noviat.com", "category": "Hidden", 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 0258b78..659b984 100644 --- a/account_ebics_oca_statement_import/wizards/account_statement_import.py +++ b/account_ebics_oca_statement_import/wizards/account_statement_import.py @@ -6,12 +6,44 @@ from datetime import date, datetime from odoo import _, models +from odoo.addons.base.models.res_bank import sanitize_account_number + _logger = logging.getLogger(__name__) class AccountStatementImport(models.TransientModel): _inherit = "account.statement.import" + def _match_journal(self, account_number, currency): + 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): + 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 + def _check_parsed_data(self, stmts_vals): """Basic and structural verifications""" if self.env.context.get("active_model") == "ebics.file":