From da5cdcc9c8a819af3dea4818d1b933fb01eec14f 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. --- .../__manifest__.py | 6 +-- .../models/__init__.py | 1 - .../models/account_bank_statement_line.py | 18 -------- .../models/online_bank_statement_provider.py | 46 +++---------------- .../views/account_bank_statement_line.xml | 25 ---------- .../views/account_journal.xml | 4 +- 6 files changed, 10 insertions(+), 90 deletions(-) delete mode 100644 account_statement_import_online/models/account_bank_statement_line.py delete mode 100644 account_statement_import_online/views/account_bank_statement_line.xml diff --git a/account_statement_import_online/__manifest__.py b/account_statement_import_online/__manifest__.py index 177135c9..8d5f5ad9 100644 --- a/account_statement_import_online/__manifest__.py +++ b/account_statement_import_online/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Online Bank Statements", - "version": "14.0.2.1.1", + "version": "14.0.3.0.0", "author": "CorporateHub, Odoo Community Association (OCA)", "maintainers": ["alexey-pelykh"], "website": "https://github.com/OCA/bank-statement-import", @@ -13,8 +13,7 @@ "summary": "Online bank statements update", "external_dependencies": {"python": ["odoo_test_helper"]}, "depends": [ - "account", - "account_statement_import", + "account_statement_import_base", "web_widget_dropdown_dynamic", ], "data": [ @@ -24,7 +23,6 @@ "wizards/online_bank_statement_pull_wizard.xml", "views/actions.xml", "views/account_journal.xml", - "views/account_bank_statement_line.xml", "views/online_bank_statement_provider.xml", ], "installable": True, diff --git a/account_statement_import_online/models/__init__.py b/account_statement_import_online/models/__init__.py index d3f9d0d6..56bd827c 100644 --- a/account_statement_import_online/models/__init__.py +++ b/account_statement_import_online/models/__init__.py @@ -1,5 +1,4 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import account_journal -from . import account_bank_statement_line from . import online_bank_statement_provider diff --git a/account_statement_import_online/models/account_bank_statement_line.py b/account_statement_import_online/models/account_bank_statement_line.py deleted file mode 100644 index 7f0c7f08..00000000 --- a/account_statement_import_online/models/account_bank_statement_line.py +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2021 Therp BV . -# @author: Ronald Portier . -# Licence LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0). -"""Add raw data to statement line, to solve import issues.""" - -from odoo import fields, models - - -class AccountBankStatementLine(models.Model): - """Add raw data to statement line, to solve import issues.""" - - _inherit = "account.bank.statement.line" - - online_raw_data = fields.Text( - help="The complete data retrieved online for this transaction", - readonly=True, - copy=False, - ) diff --git a/account_statement_import_online/models/online_bank_statement_provider.py b/account_statement_import_online/models/online_bank_statement_provider.py index 2366fb72..11021f47 100644 --- a/account_statement_import_online/models/online_bank_statement_provider.py +++ b/account_statement_import_online/models/online_bank_statement_provider.py @@ -12,7 +12,6 @@ from pytz import timezone, utc from odoo import _, api, fields, models -from odoo.addons.base.models.res_bank import sanitize_account_number from odoo.addons.base.models.res_partner import _tz_get _logger = logging.getLogger(__name__) @@ -259,6 +258,8 @@ class OnlineBankStatementProvider(models.Model): """Get lines from line data, but only for the right date.""" AccountBankStatementLine = self.env["account.bank.statement.line"] provider_tz = timezone(self.tz) if self.tz else utc + journal = self.journal_id + speeddict = journal._statement_line_import_speeddict() filtered_lines = [] for line_values in lines_data: date = line_values["date"] @@ -282,23 +283,18 @@ class OnlineBankStatementProvider(models.Model): date = date.replace(tzinfo=utc) date = date.astimezone(provider_tz).replace(tzinfo=None) line_values["date"] = date + journal._statement_line_import_update_unique_import_id( + line_values, self.account_number + ) unique_import_id = line_values.get("unique_import_id") if unique_import_id: - unique_import_id = self._generate_unique_import_id(unique_import_id) - line_values.update({"unique_import_id": unique_import_id}) if AccountBankStatementLine.sudo().search( [("unique_import_id", "=", unique_import_id)], limit=1 ): continue - bank_account_number = line_values.get("account_number") - if bank_account_number: - sanitized_account_number = self._sanitize_bank_account_number( - bank_account_number - ) - line_values["account_number"] = sanitized_account_number - self._update_partner_from_account_number(line_values) if not line_values.get("payment_ref"): line_values["payment_ref"] = line_values.get("ref") + journal._statement_line_import_update_hook(line_values, speeddict) filtered_lines.append(line_values) return filtered_lines @@ -349,36 +345,6 @@ class OnlineBankStatementProvider(models.Model): date_since = date_since.replace(tzinfo=utc).astimezone(tz) return date_since.date() - def _generate_unique_import_id(self, unique_import_id): - self.ensure_one() - return ( - (self.account_number and self.account_number + "-" or "") - + str(self.journal_id.id) - + "-" - + unique_import_id - ) - - def _sanitize_bank_account_number(self, bank_account_number): - """Hook for extension""" - self.ensure_one() - return sanitize_account_number(bank_account_number) - - def _update_partner_from_account_number(self, line_values): - """Lookup partner using account number.""" - self.ensure_one() - partner_bank = self.env["res.partner.bank"].search( - [ - ("acc_number", "=", line_values["account_number"]), - "|", - ("company_id", "=", False), - ("company_id", "=", self.company_id.id), - ], - limit=1, - ) - if partner_bank: - line_values["partner_bank_id"] = partner_bank.id - line_values["partner_id"] = partner_bank.partner_id.id - def _get_next_run_period(self): self.ensure_one() if self.interval_type == "minutes": diff --git a/account_statement_import_online/views/account_bank_statement_line.xml b/account_statement_import_online/views/account_bank_statement_line.xml deleted file mode 100644 index 1b7dd2f9..00000000 --- a/account_statement_import_online/views/account_bank_statement_line.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - account.bank.statement.line - - - - - - - - - - - - - - diff --git a/account_statement_import_online/views/account_journal.xml b/account_statement_import_online/views/account_journal.xml index f2b7bf83..98044288 100644 --- a/account_statement_import_online/views/account_journal.xml +++ b/account_statement_import_online/views/account_journal.xml @@ -11,7 +11,7 @@ account.journal - + - +