Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] fix pattern import export id fields #118

Open
wants to merge 4 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pattern_import_export/models/ir_exports_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions pattern_import_export/tests/test_pattern_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,19 @@ 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.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"
)
46 changes: 23 additions & 23 deletions pattern_import_export/tests/test_pattern_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -203,31 +203,31 @@ 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())
data = [{"login#key": self.user3.login, "name": unique_name}]
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())
Expand All @@ -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())
Expand All @@ -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):
Expand All @@ -297,15 +297,15 @@ 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
item = {".id": self.partner_1.id, "category_id|1|name": self.partner_cat1.name}
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())
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
odoo14-addon-base-export-manager @ git+https://github.com/OCA/server-ux.git@refs/pull/616/head#subdirectory=setup/base_export_manager