diff --git a/base_import_match/README.rst b/base_import_match/README.rst index eea5cad9e..604fba150 100644 --- a/base_import_match/README.rst +++ b/base_import_match/README.rst @@ -14,13 +14,13 @@ Base Import Match :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github - :target: https://github.com/OCA/server-backend/tree/13.0/base_import_match + :target: https://github.com/OCA/server-backend/tree/14.0/base_import_match :alt: OCA/server-backend .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png :target: https://translation.odoo-community.org/projects/server-backend-13-0/server-backend-13-0-base_import_match :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/253/13.0 + :target: https://runbot.odoo-community.org/runbot/253/14.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -151,6 +151,6 @@ 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/server-backend `_ project on GitHub. +This module is part of the `OCA/server-backend `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_import_match/models/base.py b/base_import_match/models/base.py index 57b589fbd..327818c96 100644 --- a/base_import_match/models/base.py +++ b/base_import_match/models/base.py @@ -35,6 +35,7 @@ class Base(models.AbstractModel): if xmlid: # Skip rows with ID, they do not need all this row["id"] = xmlid + newdata.append(tuple(row[f] for f in clean_fields)) continue elif dbid: # Find the xmlid for this dbid diff --git a/base_import_match/models/base_import.py b/base_import_match/models/base_import.py index 84c53f6c8..16f4e6a5f 100644 --- a/base_import_match/models/base_import.py +++ b/base_import_match/models/base_import.py @@ -160,13 +160,16 @@ class BaseImportMatchField(models.Model): ) @api.depends("conditional", "field_id", "imported_value") - def _compute_display_name(self): + def name_get(self): + result = [] for one in self: pattern = u"{name} ({cond})" if one.conditional else u"{name}" - one.display_name = pattern.format( + name = pattern.format( name=one.field_id.name, cond=one.imported_value, ) + result.append((one.id, name)) + return result @api.onchange("field_id", "match_id", "conditional", "imported_value") def _onchange_match_id_name(self): diff --git a/base_import_match/tests/import_data/res_partner_dbid.csv b/base_import_match/tests/import_data/res_partner_dbid.csv new file mode 100644 index 000000000..b150ad4e8 --- /dev/null +++ b/base_import_match/tests/import_data/res_partner_dbid.csv @@ -0,0 +1,2 @@ +.id,vat,name +10,BE099999999,Deco Addict External DBID Changed diff --git a/base_import_match/tests/import_data/res_partner_external_id.csv b/base_import_match/tests/import_data/res_partner_external_id.csv new file mode 100644 index 000000000..4ef0a4b6b --- /dev/null +++ b/base_import_match/tests/import_data/res_partner_external_id.csv @@ -0,0 +1,2 @@ +id,vat,name +base.res_partner_2,BE077777777,Deco Addict External ID Changed diff --git a/base_import_match/tests/import_data/res_partner_invalid_combination_vat.csv b/base_import_match/tests/import_data/res_partner_invalid_combination_vat.csv new file mode 100644 index 000000000..90fabf2cb --- /dev/null +++ b/base_import_match/tests/import_data/res_partner_invalid_combination_vat.csv @@ -0,0 +1,2 @@ +name,vat,is_company +Deco Addict Changed,BE0477472701,False diff --git a/base_import_match/tests/test_import.py b/base_import_match/tests/test_import.py index 43a5ff4c9..b234e8b60 100644 --- a/base_import_match/tests/test_import.py +++ b/base_import_match/tests/test_import.py @@ -27,6 +27,22 @@ class ImportCase(TransactionCase): } ) + def test_res_partner_external_id(self): + """Change name based on External ID.""" + deco_addict = self.env.ref("base.res_partner_2") + record = self._base_import_record("res.partner", "res_partner_external_id") + record.do(["id", "vat", "name"], [], OPTIONS) + deco_addict.env.cache.invalidate() + self.assertEqual(deco_addict.name, "Deco Addict External ID Changed") + + def test_res_partner_dbid(self): + """Change name based on DB ID.""" + deco_addict = self.env.ref("base.res_partner_2") + record = self._base_import_record("res.partner", "res_partner_dbid") + record.do([".id", "vat", "name"], [], OPTIONS) + deco_addict.env.cache.invalidate() + self.assertEqual(deco_addict.name, "Deco Addict External DBID Changed") + def test_res_partner_vat(self): """Change name based on VAT.""" deco_addict = self.env.ref("base.res_partner_2") @@ -36,6 +52,17 @@ class ImportCase(TransactionCase): deco_addict.env.cache.invalidate() self.assertEqual(deco_addict.name, "Deco Addict Changed") + def test_res_partner_invalid_combination_vat(self): + """Change name based on VAT.""" + deco_addict = self.env.ref("base.res_partner_2") + deco_addict.vat = "BE0477472701" + record = self._base_import_record( + "res.partner", "res_partner_invalid_combination_vat" + ) + record.do(["name", "vat", "is_company"], [], OPTIONS) + deco_addict.env.cache.invalidate() + self.assertEqual(deco_addict.name, deco_addict.name) + def test_res_partner_parent_name_is_company(self): """Change email based on parent_id, name and is_company.""" record = self._base_import_record( @@ -63,6 +90,16 @@ class ImportCase(TransactionCase): self.env.ref("base.res_partner_address_4").function, "Function Changed" ) + def test_res_partner_name_duplicated(self): + """Change function based on name.""" + record = self._base_import_record("res.partner", "res_partner_name") + partner_1 = self.env.ref("base.res_partner_address_4") + partner_2 = self.env.ref("base.res_partner_2") + function = partner_1.function + partner_2.name = partner_1.name + record.do(["function", "name"], [], OPTIONS) + self.assertEqual(self.env.ref("base.res_partner_address_4").function, function) + def test_res_users_login(self): """Change name based on login.""" record = self._base_import_record("res.users", "res_users_login") diff --git a/base_import_match/views/base_import_match_view.xml b/base_import_match/views/base_import_match_view.xml index ce5ec9477..e32abcf3a 100644 --- a/base_import_match/views/base_import_match_view.xml +++ b/base_import_match/views/base_import_match_view.xml @@ -69,6 +69,13 @@ - + + + ir.actions.act_window + Import Match + base_import.match + tree,form + +