From 6418bc396f53b45840ac0effd7efc3ef18c54878 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 8 Aug 2022 00:05:18 +0200 Subject: [PATCH] Add module account_statement_import_base The 2 modules account_statement_import_online and account_statement_import depend on account_statement_import_base (and not on each other) and share common code, in particular a hook to update the statement line. So we can now have reconciliation modules that use this hook and therefore work both on file import and online import. More details on https://github.com/OCA/bank-statement-import/issues/481. Improve bank statement line form view and journal form view. --- account_statement_import/__manifest__.py | 3 +- account_statement_import/models/__init__.py | 1 - .../models/account_bank_statement_line.py | 22 ----------- .../views/account_bank_statement_line.xml | 25 ------------ .../wizard/account_statement_import.py | 38 +++---------------- 5 files changed, 6 insertions(+), 83 deletions(-) delete mode 100644 account_statement_import/models/account_bank_statement_line.py delete mode 100644 account_statement_import/views/account_bank_statement_line.xml diff --git a/account_statement_import/__manifest__.py b/account_statement_import/__manifest__.py index 42718d45..a958bb2d 100644 --- a/account_statement_import/__manifest__.py +++ b/account_statement_import/__manifest__.py @@ -8,7 +8,7 @@ "category": "Accounting", "version": "14.0.2.1.0", "license": "LGPL-3", - "depends": ["account"], + "depends": ["account_statement_import_base"], "author": "Odoo SA, Akretion, Odoo Community Association (OCA)", "maintainers": ["alexis-via"], "development_status": "Mature", @@ -17,7 +17,6 @@ "security/ir.model.access.csv", "wizard/account_statement_import_view.xml", "views/account_journal.xml", - "views/account_bank_statement_line.xml", ], "demo": [ "demo/partner_bank.xml", diff --git a/account_statement_import/models/__init__.py b/account_statement_import/models/__init__.py index 16a78ca3..2388e119 100644 --- a/account_statement_import/models/__init__.py +++ b/account_statement_import/models/__init__.py @@ -1,2 +1 @@ from . import account_journal -from . import account_bank_statement_line diff --git a/account_statement_import/models/account_bank_statement_line.py b/account_statement_import/models/account_bank_statement_line.py deleted file mode 100644 index 71be92c0..00000000 --- a/account_statement_import/models/account_bank_statement_line.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2004-2020 Odoo S.A. -# Copyright 2020 Akretion France (http://www.akretion.com/) -# @author: Alexis de Lattre -# Licence LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0). - -from odoo import fields, models - - -class AccountBankStatementLine(models.Model): - _inherit = "account.bank.statement.line" - - # Ensure transactions can be imported only once - # (if the import format provides unique transaction ids) - unique_import_id = fields.Char(string="Import ID", readonly=True, copy=False) - - _sql_constraints = [ - ( - "unique_import_id", - "unique(unique_import_id)", - "A bank account transaction can be imported only once!", - ) - ] diff --git a/account_statement_import/views/account_bank_statement_line.xml b/account_statement_import/views/account_bank_statement_line.xml deleted file mode 100644 index cac1e93f..00000000 --- a/account_statement_import/views/account_bank_statement_line.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - account.bank.statement.line - - - - - - - - - - - - - - - diff --git a/account_statement_import/wizard/account_statement_import.py b/account_statement_import/wizard/account_statement_import.py index 16e29bb9..604b91ca 100644 --- a/account_statement_import/wizard/account_statement_import.py +++ b/account_statement_import/wizard/account_statement_import.py @@ -277,43 +277,15 @@ class AccountStatementImport(models.TransientModel): ) return journal - @api.model - def _update_partner_from_account_number(self, lvals): - partner_bank = self.env["res.partner.bank"].search( - [("acc_number", "=", lvals["account_number"])], limit=1 - ) - if partner_bank: - lvals["partner_bank_id"] = partner_bank.id - lvals["partner_id"] = partner_bank.partner_id.id - def _complete_stmts_vals(self, stmts_vals, journal, account_number): + speeddict = journal._statement_line_import_speeddict() for st_vals in stmts_vals: st_vals["journal_id"] = journal.id for lvals in st_vals["transactions"]: - unique_import_id = lvals.get("unique_import_id") - if unique_import_id: - sanitized_account_number = sanitize_account_number(account_number) - lvals["unique_import_id"] = ( - ( - sanitized_account_number - and sanitized_account_number + "-" - or "" - ) - + str(journal.id) - + "-" - + unique_import_id - ) - - if ( - not lvals.get("partner_bank_id") - and lvals.get("account_number") - and not lvals.get("partner_id") - ): - # Find the partner from his bank account number - # The partner selected during the - # reconciliation process will be linked to the bank account - # when the statement is closed (code in the account module) - self._update_partner_from_account_number(lvals) + journal._statement_line_import_update_unique_import_id( + lvals, account_number + ) + journal._statement_line_import_update_hook(lvals, speeddict) if not lvals.get("payment_ref"): raise UserError(_("Missing payment_ref on a transaction.")) return stmts_vals