From bce8556a93bb89bc432f70336962e431d17ffa9f Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Tue, 29 Mar 2022 09:03:05 +0200 Subject: [PATCH 1/6] [ADD] account_bank_statement_import_guess_partner --- .../README.rst | 74 +++ .../__init__.py | 3 + .../__manifest__.py | 11 + .../models/__init__.py | 3 + .../models/account_bank_statement_import.py | 38 ++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 2 + .../static/description/index.html | 420 ++++++++++++++++++ .../tests/__init__.py | 2 + ...unt_bank_statement_import_guess_partner.py | 109 +++++ ...ccount_bank_statement_import_guess_partner | 1 + .../setup.py | 6 + 12 files changed, 670 insertions(+) create mode 100644 account_bank_statement_import_guess_partner/README.rst create mode 100644 account_bank_statement_import_guess_partner/__init__.py create mode 100644 account_bank_statement_import_guess_partner/__manifest__.py create mode 100644 account_bank_statement_import_guess_partner/models/__init__.py create mode 100644 account_bank_statement_import_guess_partner/models/account_bank_statement_import.py create mode 100644 account_bank_statement_import_guess_partner/readme/CONTRIBUTORS.rst create mode 100644 account_bank_statement_import_guess_partner/readme/DESCRIPTION.rst create mode 100644 account_bank_statement_import_guess_partner/static/description/index.html create mode 100644 account_bank_statement_import_guess_partner/tests/__init__.py create mode 100644 account_bank_statement_import_guess_partner/tests/test_account_bank_statement_import_guess_partner.py create mode 120000 setup/account_bank_statement_import_guess_partner/odoo/addons/account_bank_statement_import_guess_partner create mode 100644 setup/account_bank_statement_import_guess_partner/setup.py diff --git a/account_bank_statement_import_guess_partner/README.rst b/account_bank_statement_import_guess_partner/README.rst new file mode 100644 index 00000000..014d4f3b --- /dev/null +++ b/account_bank_statement_import_guess_partner/README.rst @@ -0,0 +1,74 @@ +========================================== +Guess partner on import of statement lines +========================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github + :target: https://github.com/OCA/bank-statement-import/tree/13.0/account_bank_statement_import_guess_partner + :alt: OCA/bank-statement-import +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/bank-statement-import-13-0/bank-statement-import-13-0-account_bank_statement_import_guess_partner + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/174/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module uses the ref in an imported transaction to find the partner from the +invoice if possible, and if not set already. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Therp BV + +Contributors +~~~~~~~~~~~~ + +* Ronald Portier - Therp BV + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/bank-statement-import `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_bank_statement_import_guess_partner/__init__.py b/account_bank_statement_import_guess_partner/__init__.py new file mode 100644 index 00000000..31660d6a --- /dev/null +++ b/account_bank_statement_import_guess_partner/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/account_bank_statement_import_guess_partner/__manifest__.py b/account_bank_statement_import_guess_partner/__manifest__.py new file mode 100644 index 00000000..ad1853e8 --- /dev/null +++ b/account_bank_statement_import_guess_partner/__manifest__.py @@ -0,0 +1,11 @@ +# Copyright 2022 Therp BV . +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Guess partner on import of statement lines", + "version": "13.0.1.0.0", + "category": "Invoicing Management", + "website": "https://github.com/OCA/bank-statement-import", + "author": "Therp BV, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["account_bank_statement_import"], +} diff --git a/account_bank_statement_import_guess_partner/models/__init__.py b/account_bank_statement_import_guess_partner/models/__init__.py new file mode 100644 index 00000000..6e0045ad --- /dev/null +++ b/account_bank_statement_import_guess_partner/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +"""Import models.""" +from . import account_bank_statement_import diff --git a/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py b/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py new file mode 100644 index 00000000..4b2eff8a --- /dev/null +++ b/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py @@ -0,0 +1,38 @@ +# Copyright 2022 Therp BV . +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +"""Try to determine partner from ref in transaction and from invoice.""" +from odoo import models + + +class AccountBankStatementImport(models.TransientModel): + """Try to determine partner from ref in transaction and from invoice.""" + + _inherit = "account.bank.statement.import" + + def _complete_stmts_vals(self, stmts_vals, journal, account_number): + """Try to find partner for each transaction.""" + stmts_vals = super()._complete_stmts_vals(stmts_vals, journal, account_number) + # Loop over statements. + for statement in stmts_vals: + # Loop over transactions in statement. + for transaction in statement["transactions"]: + self._complete_transaction(transaction) + return stmts_vals + + def _complete_transaction(self, transaction): + """Try to find partner by searching invoice with reference.""" + if transaction.get("partner_id", False): + return + if not transaction.get("ref", False): + return + ref = transaction["ref"] + invoice_model = self.env["account.move"] + # We search each possibility in a separate statement, to prioritize + # invoice_origin over ref, and ref over name. + invoice = invoice_model.search([("invoice_origin", "=", ref)], limit=1) + if not invoice: + invoice = invoice_model.search([("ref", "=", ref)], limit=1) + if not invoice: + invoice = invoice_model.search([("name", "=", ref)], limit=1) + if invoice: + transaction["partner_id"] = invoice.partner_id.id diff --git a/account_bank_statement_import_guess_partner/readme/CONTRIBUTORS.rst b/account_bank_statement_import_guess_partner/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..6ee4d1d6 --- /dev/null +++ b/account_bank_statement_import_guess_partner/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Ronald Portier - Therp BV diff --git a/account_bank_statement_import_guess_partner/readme/DESCRIPTION.rst b/account_bank_statement_import_guess_partner/readme/DESCRIPTION.rst new file mode 100644 index 00000000..9f1b8257 --- /dev/null +++ b/account_bank_statement_import_guess_partner/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module uses the ref in an imported transaction to find the partner from the +invoice if possible, and if not set already. diff --git a/account_bank_statement_import_guess_partner/static/description/index.html b/account_bank_statement_import_guess_partner/static/description/index.html new file mode 100644 index 00000000..05e13685 --- /dev/null +++ b/account_bank_statement_import_guess_partner/static/description/index.html @@ -0,0 +1,420 @@ + + + + + + +Guess partner on import of statement lines + + + +
+

Guess partner on import of statement lines

+ + +

Beta License: AGPL-3 OCA/bank-statement-import Translate me on Weblate Try me on Runbot

+

This module uses the ref in an imported transaction to find the partner from the +invoice if possible, and if not set already.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Therp BV
  • +
+
+
+

Contributors

+
    +
  • Ronald Portier - Therp BV
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/bank-statement-import project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_bank_statement_import_guess_partner/tests/__init__.py b/account_bank_statement_import_guess_partner/tests/__init__.py new file mode 100644 index 00000000..e8899ee0 --- /dev/null +++ b/account_bank_statement_import_guess_partner/tests/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import test_account_bank_statement_import_guess_partner diff --git a/account_bank_statement_import_guess_partner/tests/test_account_bank_statement_import_guess_partner.py b/account_bank_statement_import_guess_partner/tests/test_account_bank_statement_import_guess_partner.py new file mode 100644 index 00000000..ff5f8a43 --- /dev/null +++ b/account_bank_statement_import_guess_partner/tests/test_account_bank_statement_import_guess_partner.py @@ -0,0 +1,109 @@ +# Copyright 2022 Therp BV . +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0 +"""Test determining partner from ref in transaction.""" +from odoo.tests import common + +REF = "SO0001" +STMTS_VALS = [ + { + "name": "Test000123", + "date": "2022-03-29", + "transactions": [ + { + "name": "Bla000123", + "date": "2022-03-30", + "amount": 23.95, + "unique_import_id": "random0001", + "ref": REF, + }, + ], + } +] + + +class TestAccountBankStatementImportGuessPartner(common.SavepointCase): + """Test determining partner from ref in transaction.""" + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.account_type = cls.env["account.account.type"].create( + {"name": "Test Account Type", "type": "other", "internal_group": "asset"} + ) + cls.a_receivable = cls.env["account.account"].create( + { + "code": "TAA", + "name": "Test Receivable Account", + "internal_type": "receivable", + "user_type_id": cls.account_type.id, + } + ) + cls.partner = cls.env["res.partner"].create( + {"name": "Test Partner 2", "parent_id": False} + ) + cls.journal = cls.env["account.journal"].create( + {"name": "Test Journal", "type": "sale", "code": "TJS0"} + ) + + def test_invoice_invoice_origin(self): + """Test invoice.invoice_origin = transaction["ref"].""" + self._create_invoice("invoice_origin", REF) + transaction = self._get_completed_transaction() + self.assertIn("partner_id", transaction) + self.assertEqual(transaction["partner_id"], self.partner.id) + + def test_invoice_ref(self): + """Test invoice.ref = transaction["ref"].""" + self._create_invoice("ref", REF) + transaction = self._get_completed_transaction() + self.assertIn("partner_id", transaction) + self.assertEqual(transaction["partner_id"], self.partner.id) + + def test_invoice_name(self): + """Test invoice.name = transaction["ref"].""" + self._create_invoice("name", REF) + transaction = self._get_completed_transaction() + self.assertIn("partner_id", transaction) + self.assertEqual(transaction["partner_id"], self.partner.id) + + def test_invoice_unknown_ref(self): + """Test no value in invoice for transaction["ref"].""" + self._create_invoice("invoice_origin", "DoesAbsolutelyNotExist") + transaction = self._get_completed_transaction() + self.assertNotIn("partner_id", transaction) + + def _get_completed_transaction(self): + """Complete statements and return first transaction in first statement.""" + # pylint: disable=protected-access + absi_model = self.env["account.bank.statement.import"] + # Make sure dictionary is "incompleted". + transaction = STMTS_VALS[0]["transactions"][0] + if "partner_id" in transaction: + del transaction["partner_id"] + absi_model._complete_stmts_vals(STMTS_VALS, self.journal, "BNK0001") + return transaction + + def _create_invoice(self, ref_field, ref_value): + """Create an invoice with some reference information.""" + invoice = self.env["account.move"].create( + { + "name": "Test Invoice 3", + "partner_id": self.partner.id, + "type": "out_invoice", + "journal_id": self.journal.id, + "invoice_line_ids": [ + ( + 0, + 0, + { + "account_id": self.a_receivable.id, + "name": "Test line", + "quantity": 1.0, + "price_unit": 100.00, + }, + ) + ], + } + ) + invoice[ref_field] = ref_value # Might also override name. + invoice.post() diff --git a/setup/account_bank_statement_import_guess_partner/odoo/addons/account_bank_statement_import_guess_partner b/setup/account_bank_statement_import_guess_partner/odoo/addons/account_bank_statement_import_guess_partner new file mode 120000 index 00000000..da7b03cc --- /dev/null +++ b/setup/account_bank_statement_import_guess_partner/odoo/addons/account_bank_statement_import_guess_partner @@ -0,0 +1 @@ +../../../../account_bank_statement_import_guess_partner \ No newline at end of file diff --git a/setup/account_bank_statement_import_guess_partner/setup.py b/setup/account_bank_statement_import_guess_partner/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/account_bank_statement_import_guess_partner/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 8b2e2d2a3a0e8e2bea76dfe32454d3a746220cd1 Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Wed, 30 Mar 2022 10:47:12 +0200 Subject: [PATCH 2/6] [IMP] *_guess_partner: Also try to check on transaction['name'] --- .../models/account_bank_statement_import.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py b/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py index 4b2eff8a..be485fea 100644 --- a/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py +++ b/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py @@ -23,16 +23,16 @@ class AccountBankStatementImport(models.TransientModel): """Try to find partner by searching invoice with reference.""" if transaction.get("partner_id", False): return - if not transaction.get("ref", False): - return - ref = transaction["ref"] invoice_model = self.env["account.move"] - # We search each possibility in a separate statement, to prioritize - # invoice_origin over ref, and ref over name. - invoice = invoice_model.search([("invoice_origin", "=", ref)], limit=1) - if not invoice: - invoice = invoice_model.search([("ref", "=", ref)], limit=1) - if not invoice: - invoice = invoice_model.search([("name", "=", ref)], limit=1) - if invoice: - transaction["partner_id"] = invoice.partner_id.id + invoice = None + transaction_keys = ["ref", "name"] + invoice_fields = ["invoice_origin", "ref", "name"] + for key in transaction_keys: + value = transaction.get(key, False) + if not value: + continue + for fieldname in invoice_fields: + invoice = invoice_model.search([(fieldname, "=", value)], limit=1) + if invoice: + transaction["partner_id"] = invoice.partner_id.id + return From 95d2b24e686e29ec4654760b51a45dca2d756fc6 Mon Sep 17 00:00:00 2001 From: ntsirintanis Date: Wed, 15 Jun 2022 15:30:11 +0200 Subject: [PATCH 3/6] [IMP] also try to fetch sale order by name key, if no invoice is found --- .../models/account_bank_statement_import.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py b/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py index be485fea..ca4ff978 100644 --- a/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py +++ b/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py @@ -20,7 +20,7 @@ class AccountBankStatementImport(models.TransientModel): return stmts_vals def _complete_transaction(self, transaction): - """Try to find partner by searching invoice with reference.""" + """Find partner by searching invoice with reference or so name.""" if transaction.get("partner_id", False): return invoice_model = self.env["account.move"] @@ -36,3 +36,14 @@ class AccountBankStatementImport(models.TransientModel): if invoice: transaction["partner_id"] = invoice.partner_id.id return + # In case there is not an invoice, check sale order + sale_order_name = transaction.get("name") + if sale_order_name: + sale_order = self.env["sale.order"].search( + [("name", "=", sale_order_name)], limit=1 + ) + if not sale_order: + return + transaction["partner_id"] = ( + sale_order.partner_invoice_id.id or sale_order.partner_id.id + ) From ba893a7f55421b05046584a9407aabb8858c8b22 Mon Sep 17 00:00:00 2001 From: ntsirintanis Date: Wed, 22 Jun 2022 15:42:04 +0200 Subject: [PATCH 4/6] [UPD] set as transaction partner the parent record of invoice_address, or the customer if there is a sales order --- .../models/account_bank_statement_import.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py b/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py index ca4ff978..0a37923f 100644 --- a/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py +++ b/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py @@ -34,7 +34,9 @@ class AccountBankStatementImport(models.TransientModel): for fieldname in invoice_fields: invoice = invoice_model.search([(fieldname, "=", value)], limit=1) if invoice: - transaction["partner_id"] = invoice.partner_id.id + # We need parent here because of reconciliation. + # Lines cannot be reconciled if partner is an address + transaction["partner_id"] = invoice.partner_id.parent_id.id return # In case there is not an invoice, check sale order sale_order_name = transaction.get("name") @@ -44,6 +46,5 @@ class AccountBankStatementImport(models.TransientModel): ) if not sale_order: return - transaction["partner_id"] = ( - sale_order.partner_invoice_id.id or sale_order.partner_id.id - ) + # Same as above + transaction["partner_id"] = sale_order.partner_id.id From 6a5d36cac99c349ef1515e1120464c4611e088bc Mon Sep 17 00:00:00 2001 From: ntsirintanis Date: Thu, 30 Jun 2022 16:05:48 +0200 Subject: [PATCH 5/6] [UPD] identify for invoice, sale order, an effective partner --- .../models/account_bank_statement_import.py | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py b/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py index 0a37923f..3d50f888 100644 --- a/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py +++ b/account_bank_statement_import_guess_partner/models/account_bank_statement_import.py @@ -24,9 +24,11 @@ class AccountBankStatementImport(models.TransientModel): if transaction.get("partner_id", False): return invoice_model = self.env["account.move"] + sale_order_model = self.env["sale.order"] invoice = None transaction_keys = ["ref", "name"] invoice_fields = ["invoice_origin", "ref", "name"] + sale_order_fields = ["client_order_ref", "name"] for key in transaction_keys: value = transaction.get(key, False) if not value: @@ -34,17 +36,24 @@ class AccountBankStatementImport(models.TransientModel): for fieldname in invoice_fields: invoice = invoice_model.search([(fieldname, "=", value)], limit=1) if invoice: - # We need parent here because of reconciliation. + # We need a partner of type contact here because of reconciliation. # Lines cannot be reconciled if partner is an address - transaction["partner_id"] = invoice.partner_id.parent_id.id + partner = self._get_effective_partner(invoice.partner_id) + transaction["partner_id"] = partner.id return - # In case there is not an invoice, check sale order - sale_order_name = transaction.get("name") - if sale_order_name: - sale_order = self.env["sale.order"].search( - [("name", "=", sale_order_name)], limit=1 - ) - if not sale_order: - return - # Same as above - transaction["partner_id"] = sale_order.partner_id.id + for fieldname in sale_order_fields: + sale_order = sale_order_model.search([(fieldname, "=", value)], limit=1) + if sale_order: + partner = self._get_effective_partner(sale_order.partner_id) + transaction["partner_id"] = partner.id + return + + def _get_effective_partner(self, partner): + """Find contact partner for invoice, sale order""" + if partner.type == "contact": + return partner + if partner.parent_id.type == "contact": + return partner.parent_id + # If there's no contact, + # return original partner + return partner From 08876359ca257082551b6dcbb9cddcbde92d8951 Mon Sep 17 00:00:00 2001 From: ntsirintanis Date: Mon, 19 Sep 2022 14:39:05 +0200 Subject: [PATCH 6/6] [UPD] missing dependency and increase unit test coverage --- .../__manifest__.py | 2 +- ...unt_bank_statement_import_guess_partner.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/account_bank_statement_import_guess_partner/__manifest__.py b/account_bank_statement_import_guess_partner/__manifest__.py index ad1853e8..171aae44 100644 --- a/account_bank_statement_import_guess_partner/__manifest__.py +++ b/account_bank_statement_import_guess_partner/__manifest__.py @@ -7,5 +7,5 @@ "website": "https://github.com/OCA/bank-statement-import", "author": "Therp BV, Odoo Community Association (OCA)", "license": "AGPL-3", - "depends": ["account_bank_statement_import"], + "depends": ["account_bank_statement_import", "sale"], } diff --git a/account_bank_statement_import_guess_partner/tests/test_account_bank_statement_import_guess_partner.py b/account_bank_statement_import_guess_partner/tests/test_account_bank_statement_import_guess_partner.py index ff5f8a43..c57ba5bd 100644 --- a/account_bank_statement_import_guess_partner/tests/test_account_bank_statement_import_guess_partner.py +++ b/account_bank_statement_import_guess_partner/tests/test_account_bank_statement_import_guess_partner.py @@ -72,6 +72,20 @@ class TestAccountBankStatementImportGuessPartner(common.SavepointCase): transaction = self._get_completed_transaction() self.assertNotIn("partner_id", transaction) + def test_sale_order_name(self): + """Test sale_order.name = transaction["ref"].""" + self._create_sale_order("name", REF) + transaction = self._get_completed_transaction() + self.assertIn("partner_id", transaction) + self.assertEqual(transaction["partner_id"], self.partner.id) + + def test_sale_order_client_order_ref(self): + """Test sale_order.client_order_ref = transaction["ref"].""" + self._create_sale_order("client_order_ref", REF) + transaction = self._get_completed_transaction() + self.assertIn("partner_id", transaction) + self.assertEqual(transaction["partner_id"], self.partner.id) + def _get_completed_transaction(self): """Complete statements and return first transaction in first statement.""" # pylint: disable=protected-access @@ -107,3 +121,8 @@ class TestAccountBankStatementImportGuessPartner(common.SavepointCase): ) invoice[ref_field] = ref_value # Might also override name. invoice.post() + + def _create_sale_order(self, ref_field, ref_value): + """Create a sale order with some reference information.""" + sale_order = self.env["sale.order"].create({"partner_id": self.partner.id}) + sale_order[ref_field] = ref_value # Might also override name.