Merge branch '16-imp-account-matching' into '16.0'

[IMP]account_ebics_oca_statement_import - match journal

See merge request Noviat/Noviat_Generic/accounting-ebics!64
This commit is contained in:
Luc De Meyer 2024-08-13 14:04:32 +00:00
commit 8de08fb4ba
2 changed files with 35 additions and 3 deletions

View File

@ -1,10 +1,10 @@
# Copyright 2020-2023 Noviat. # Copyright 2020-2024 Noviat.
# License LGPL-3 or later (http://www.gnu.org/licenses/lgpl). # License LGPL-3 or later (http://www.gnu.org/licenses/lgpl).
{ {
"name": "account_ebics with OCA Bank Statement Imoort", "name": "account_ebics with OCA Bank Statement Imoort",
"summary": "Use OCA Bank Statement Import with account_ebics", "summary": "Use OCA Bank Statement Import with account_ebics",
"version": "16.0.1.0.2", "version": "16.0.1.0.3",
"author": "Noviat", "author": "Noviat",
"website": "https://www.noviat.com/", "website": "https://www.noviat.com/",
"category": "Hidden", "category": "Hidden",

View File

@ -1,4 +1,4 @@
# Copyright 2009-2023 Noviat. # Copyright 2009-2024 Noviat.
# License LGPL-3 or later (http://www.gnu.org/licenses/lgpl). # License LGPL-3 or later (http://www.gnu.org/licenses/lgpl).
import logging import logging
@ -6,12 +6,44 @@ from datetime import date, datetime
from odoo import _, models from odoo import _, models
from odoo.addons.base.models.res_bank import sanitize_account_number
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
class AccountStatementImport(models.TransientModel): class AccountStatementImport(models.TransientModel):
_inherit = "account.statement.import" _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): def _check_parsed_data(self, stmts_vals):
"""Basic and structural verifications""" """Basic and structural verifications"""
if self.env.context.get("active_model") == "ebics.file": if self.env.context.get("active_model") == "ebics.file":