From 0950bca04b37c7fc9c6a8387f8c5b880d1e08176 Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Thu, 16 Mar 2023 15:04:41 +0100 Subject: [PATCH 1/4] [FIX]pattern_import_export: avoid deprecated method running unit test --- .../tests/test_pattern_constraint.py | 8 ++-- .../tests/test_pattern_import.py | 46 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/pattern_import_export/tests/test_pattern_constraint.py b/pattern_import_export/tests/test_pattern_constraint.py index c99bc758..74a86465 100644 --- a/pattern_import_export/tests/test_pattern_constraint.py +++ b/pattern_import_export/tests/test_pattern_constraint.py @@ -65,10 +65,10 @@ def test_field_o2m_required_three_level(self): ) def test_create_wrong_pattern(self): - with self.assertRaises(exceptions.ValidationError) as em: + with self.assertRaisesRegex( + exceptions.ValidationError, + "The field field2_id is empty for the line category_id" + ): self.env["ir.exports.line"].with_context(skip_check=False).create( {"export_id": self.pattern_config.export_id.id, "name": "category_id"} ) - self.assertEqual( - em.exception.name, "The field field2_id is empty for the line category_id" - ) diff --git a/pattern_import_export/tests/test_pattern_import.py b/pattern_import_export/tests/test_pattern_import.py index db4ecd97..f36f721d 100644 --- a/pattern_import_export/tests/test_pattern_import.py +++ b/pattern_import_export/tests/test_pattern_import.py @@ -49,7 +49,7 @@ def test_update_with_external_id(self): pattern_file = self.create_pattern(self.pattern_config_m2m, "import", data) records = self.run_pattern_file(pattern_file) self.assertFalse(records) - self.assertEquals(unique_name, self.user3.name) + self.assertEqual(unique_name, self.user3.name) def test_update_with_external_id_bad_data_1(self): """ @@ -96,9 +96,9 @@ def test_create_new_record(self): data = [{"name": unique_name, "login": unique_login}] pattern_file = self.create_pattern(self.pattern_config_m2m, "import", data) records = self.run_pattern_file(pattern_file) - self.assertEquals(len(records), 1) - self.assertEquals(unique_name, records.name) - self.assertEquals(unique_login, records.login) + self.assertEqual(len(records), 1) + self.assertEqual(unique_name, records.name) + self.assertEqual(unique_login, records.login) def test_empty_external_id(self): unique_name = str(uuid4()) @@ -146,9 +146,9 @@ def test_update_o2m_with_external_id(self): # Special case: as the name comes from the related res.partner and # we link these 3 users together, the name will be the one # set in last position - self.assertEquals(unique_name, self.partner_1.name) - self.assertEquals(partner2_name, self.partner_2.name) - self.assertEquals(partner3_name, self.partner_3.name) + self.assertEqual(unique_name, self.partner_1.name) + self.assertEqual(partner2_name, self.partner_2.name) + self.assertEqual(partner3_name, self.partner_3.name) self.assertIn(self.partner_2, self.partner_1.child_ids) self.assertIn(self.partner_3, self.partner_1.child_ids) @@ -203,23 +203,23 @@ def test_update_o2m_m2m_with_external_id(self): records = self.run_pattern_file(pattern_file) self.assertFalse(records) - self.assertEquals(unique_name, self.partner_1.name) + self.assertEqual(unique_name, self.partner_1.name) self.assertIn(self.partner_cat1, self.partner_1.category_id) self.assertIn(self.partner_cat2, self.partner_1.category_id) - self.assertEquals(self.country_be, self.partner_1.country_id) + self.assertEqual(self.country_be, self.partner_1.country_id) self.assertIn(self.partner_2, self.partner_1.child_ids) self.assertIn(self.partner_3, self.partner_1.child_ids) - self.assertEquals(user1_name, self.partner_2.name) - self.assertEquals(self.industry1, self.partner_2.industry_id) - self.assertEquals(self.country_be, self.partner_2.country_id) + self.assertEqual(user1_name, self.partner_2.name) + self.assertEqual(self.industry1, self.partner_2.industry_id) + self.assertEqual(self.country_be, self.partner_2.country_id) self.assertIn(self.partner_cat1, self.partner_2.category_id) self.assertIn(self.partner_cat2, self.partner_2.category_id) - self.assertEquals(user2_name, self.partner_3.name) - self.assertEquals(self.industry2, self.partner_3.industry_id) + self.assertEqual(user2_name, self.partner_3.name) + self.assertEqual(self.industry2, self.partner_3.industry_id) # Because if the country is edited on the parent, # so the country is updated automatically on children. - self.assertEquals(self.country_be, self.partner_3.country_id) - self.assertEquals(self.partner_cat2, self.partner_3.category_id) + self.assertEqual(self.country_be, self.partner_3.country_id) + self.assertEqual(self.partner_cat2, self.partner_3.category_id) def test_update_with_key(self): unique_name = str(uuid4()) @@ -227,7 +227,7 @@ def test_update_with_key(self): pattern_file = self.create_pattern(self.pattern_config_m2m, "import", data) records = self.run_pattern_file(pattern_file) self.assertFalse(records) - self.assertEquals(unique_name, self.user3.name) + self.assertEqual(unique_name, self.user3.name) def test_update_o2m_with_key(self): unique_name = str(uuid4()) @@ -251,9 +251,9 @@ def test_update_o2m_with_key(self): pattern_file = self.create_pattern(self.pattern_config, "import", data) self.run_pattern_file(pattern_file) self.assertPatternDone(pattern_file) - self.assertEquals(unique_name, self.partner_1.name) - self.assertEquals(contact_1_name, contact_1.name) - self.assertEquals(contact_2_name, contact_2.name) + self.assertEqual(unique_name, self.partner_1.name) + self.assertEqual(contact_1_name, contact_1.name) + self.assertEqual(contact_2_name, contact_2.name) def test_update_o2m_with_key_only_one_record(self): unique_name = str(uuid4()) @@ -271,7 +271,7 @@ def test_update_o2m_with_key_only_one_record(self): ] pattern_file = self.create_pattern(self.pattern_config, "import", data) self.run_pattern_file(pattern_file) - self.assertEquals(unique_name, self.partner_1.name) + self.assertEqual(unique_name, self.partner_1.name) @mute_logger("odoo.sql_db") def test_wrong_import(self): @@ -297,7 +297,7 @@ def test_m2m_with_empty_columns(self): self.assertPatternDone(pattern_file) self.assertEqual(len(partner), 1) self.assertEqual(partner.name, unique_name) - self.assertEquals(self.partner_cat1, partner.category_id) + self.assertEqual(self.partner_cat1, partner.category_id) def test_m2m_update(self): self.partner_1.category_id = self.partner_cat2 @@ -305,7 +305,7 @@ def test_m2m_update(self): pattern_file = self.create_pattern(self.pattern_config, "import", [item]) self.run_pattern_file(pattern_file) self.assertPatternDone(pattern_file) - self.assertEquals(self.partner_cat1, self.partner_1.category_id) + self.assertEqual(self.partner_cat1, self.partner_1.category_id) def test_o2m_with_empty_value(self): unique_name = str(uuid4()) From adc9ab3ab31f151b8357f422f7c678e1e11a6a90 Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Thu, 16 Mar 2023 16:07:20 +0100 Subject: [PATCH 2/4] =?UTF-8?q?[14.0][FIX]=20pattern=5Fimport=5Fexport:=20?= =?UTF-8?q?manage=20`.id`=C2=A0fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Odoo make difference between and , the former is the postgresql id the second is the external id, at least we should not raise exception in case of existing ir.exports.line refer to such fields --- pattern_import_export/models/ir_exports_line.py | 5 ++++- pattern_import_export/tests/test_pattern_constraint.py | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pattern_import_export/models/ir_exports_line.py b/pattern_import_export/models/ir_exports_line.py index 3ba735b8..08ddc447 100644 --- a/pattern_import_export/models/ir_exports_line.py +++ b/pattern_import_export/models/ir_exports_line.py @@ -58,9 +58,12 @@ def _get_last_relation_field(self, model, path, level=1): if "/" not in path: path = path + "/" field, path = path.split("/", 1) + # in standard export odoo use `.id` for internal pgsql id and `id` for + # external id, here we want the id as present in pgsql table + field = field.replace(".id", "id") if path: next_model = self.env[model]._fields[field]._related_comodel_name - next_field = path.split("/", 1)[0] + next_field = path.split("/", 1)[0].replace(".id", "id") if self.env[next_model]._fields[next_field]._related_comodel_name: return self._get_last_relation_field(next_model, path, level=level + 1) return field, model, level diff --git a/pattern_import_export/tests/test_pattern_constraint.py b/pattern_import_export/tests/test_pattern_constraint.py index 74a86465..b1746343 100644 --- a/pattern_import_export/tests/test_pattern_constraint.py +++ b/pattern_import_export/tests/test_pattern_constraint.py @@ -64,10 +64,18 @@ def test_field_o2m_required_three_level(self): CASE, "field2_id,field3_id,number_occurence,sub_pattern_config_id" ) + def test_field_id(self): + CASE = [".id"] + self._check_case(CASE, "") + + def test_field_x2m_id(self): + CASE = ["bank_ids/.id"] + self._check_case(CASE, "number_occurence,sub_pattern_config_id") + def test_create_wrong_pattern(self): with self.assertRaisesRegex( exceptions.ValidationError, - "The field field2_id is empty for the line category_id" + "The field field2_id is empty for the line category_id", ): self.env["ir.exports.line"].with_context(skip_check=False).create( {"export_id": self.pattern_config.export_id.id, "name": "category_id"} From 7f1fdbd297e556576276e2abd8bc91e98adf2bf7 Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Thu, 23 Mar 2023 15:44:45 +0100 Subject: [PATCH 3/4] [FIX] add missing test-requirements for time behing --- test-requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test-requirements.txt b/test-requirements.txt index e69de29b..dc902ed2 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -0,0 +1 @@ +doo-addon-base-export-manager @ git+https://github.com/OCA/server-ux.git@refs/pull/616/head#subdirectory=setup/base_export_manager From e895160e9602dfef5fa4b4de796e7ba7b5952da7 Mon Sep 17 00:00:00 2001 From: Pierre Verkest Date: Thu, 23 Mar 2023 16:22:26 +0100 Subject: [PATCH 4/4] [FIX] test-requirements.txt: typo in package name --- test-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-requirements.txt b/test-requirements.txt index dc902ed2..b7aaea5d 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1 +1 @@ -doo-addon-base-export-manager @ git+https://github.com/OCA/server-ux.git@refs/pull/616/head#subdirectory=setup/base_export_manager +odoo14-addon-base-export-manager @ git+https://github.com/OCA/server-ux.git@refs/pull/616/head#subdirectory=setup/base_export_manager