diff --git a/account_statement_import_online/__manifest__.py b/account_statement_import_online/__manifest__.py index 2bb5aff0..0f58bf6b 100644 --- a/account_statement_import_online/__manifest__.py +++ b/account_statement_import_online/__manifest__.py @@ -23,6 +23,7 @@ "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 56bd827c..d3f9d0d6 100644 --- a/account_statement_import_online/models/__init__.py +++ b/account_statement_import_online/models/__init__.py @@ -1,4 +1,5 @@ # 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 new file mode 100644 index 00000000..1fc457bd --- /dev/null +++ b/account_statement_import_online/models/account_bank_statement_line.py @@ -0,0 +1,18 @@ +# 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" + + 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 00cdb6b4..3b03f54e 100644 --- a/account_statement_import_online/models/online_bank_statement_provider.py +++ b/account_statement_import_online/models/online_bank_statement_provider.py @@ -292,13 +292,11 @@ class OnlineBankStatementProvider(models.Model): continue bank_account_number = line_values.get("account_number") if bank_account_number: - line_values.update( - { - "account_number": ( - self._sanitize_bank_account_number(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") filtered_lines.append(line_values) @@ -365,6 +363,14 @@ class OnlineBankStatementProvider(models.Model): self.ensure_one() return sanitize_account_number(bank_account_number) + def _update_partner_from_account_number(self, line_values): + partner_bank = self.env["res.partner.bank"].search( + [("acc_number", "=", line_values["account_number"])], 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 new file mode 100644 index 00000000..88d13b36 --- /dev/null +++ b/account_statement_import_online/views/account_bank_statement_line.xml @@ -0,0 +1,21 @@ + + + + account.bank.statement.line + + + + + + + + + + + + + +