diff --git a/mgmtsystem_nonconformity/models/mgmtsystem_nonconformity_cause.py b/mgmtsystem_nonconformity/models/mgmtsystem_nonconformity_cause.py index 9edaa33778f..1b379f1b0e1 100644 --- a/mgmtsystem_nonconformity/models/mgmtsystem_nonconformity_cause.py +++ b/mgmtsystem_nonconformity/models/mgmtsystem_nonconformity_cause.py @@ -25,13 +25,10 @@ class MgmtsystemNonconformityCause(models.Model): ) ref_code = fields.Char("Reference Code") - @api.depends("name", "parent_id.name") + @api.depends("name", "parent_id.display_name") def _compute_display_name(self): - res = [] for obj in self: if obj.parent_id: - name = obj.parent_id.display_name + " / " + obj.name + obj.display_name = f"{obj.parent_id.display_name} / {obj.name}" else: - name = obj.name - res.append((obj.id, name)) - return res + obj.display_name = obj.name diff --git a/mgmtsystem_nonconformity/models/mgmtsystem_nonconformity_origin.py b/mgmtsystem_nonconformity/models/mgmtsystem_nonconformity_origin.py index 9f864dfbeed..97ef27ef32c 100644 --- a/mgmtsystem_nonconformity/models/mgmtsystem_nonconformity_origin.py +++ b/mgmtsystem_nonconformity/models/mgmtsystem_nonconformity_origin.py @@ -26,10 +26,8 @@ class MgmtsystemNonconformityOrigin(models.Model): @api.depends("name", "parent_id.name") def _compute_display_name(self): - res = [] for obj in self: name = obj.name if obj.parent_id: - name = obj.parent_id.display_name + " / " + name - res.append((obj.id, name)) - return res + name = f"{obj.parent_id.display_name} / {name}" + obj.display_name = name diff --git a/mgmtsystem_nonconformity/tests/test_cause.py b/mgmtsystem_nonconformity/tests/test_cause.py index 7487428e756..8349bc72d32 100644 --- a/mgmtsystem_nonconformity/tests/test_cause.py +++ b/mgmtsystem_nonconformity/tests/test_cause.py @@ -24,17 +24,20 @@ def test_create_cause(self): self.assertNotEqual(self.record.id, None) def test_display_name(self): - name_assoc = self.record.display_name - self.assertEqual(name_assoc[0][1], "TestCause") - self.assertEqual(name_assoc[0][0], self.record.id) - - name_assoc = self.record2.display_name - self.assertEqual(name_assoc[0][1], "TestCause / test2") - self.assertEqual(name_assoc[0][0], self.record2.id) - - name_assoc = self.record3.name_get() - self.assertEqual(name_assoc[0][1], "TestCause / test2 / test3") - self.assertEqual(name_assoc[0][0], self.record3.id) + name_assoc = self.record + name_assoc._compute_display_name() + self.assertEqual(name_assoc.display_name, "TestCause") + self.assertEqual(name_assoc.id, self.record.id) + + name_assoc = self.record2 + name_assoc._compute_display_name() + self.assertEqual(name_assoc.display_name, "TestCause / test2") + self.assertEqual(name_assoc.id, self.record2.id) + + name_assoc = self.record3 + name_assoc._compute_display_name() + self.assertEqual(name_assoc.display_name, "TestCause / test2 / test3") + self.assertEqual(name_assoc.id, self.record3.id) def test_recursion(self): parent = self.env["mgmtsystem.nonconformity.cause"].create( diff --git a/mgmtsystem_nonconformity/tests/test_origin.py b/mgmtsystem_nonconformity/tests/test_origin.py index b4b9b2fa714..cff12f9d1e8 100644 --- a/mgmtsystem_nonconformity/tests/test_origin.py +++ b/mgmtsystem_nonconformity/tests/test_origin.py @@ -23,14 +23,17 @@ def test_create_origin(self): self.assertNotEqual(self.record.id, None) def test_display_name(self): - name_assoc = self.record.display_name - self.assertEqual(name_assoc[0][1], "TestOrigin") - self.assertEqual(name_assoc[0][0], self.record.id) + name_assoc = self.record + name_assoc._compute_display_name() + self.assertEqual(name_assoc.display_name, "TestOrigin") + self.assertEqual(name_assoc.id, self.record.id) - name_assoc = self.record2.display_name - self.assertEqual(name_assoc[0][1], "TestOrigin / test2") - self.assertEqual(name_assoc[0][0], self.record2.id) + name_assoc = self.record2 + name_assoc._compute_display_name() + self.assertEqual(name_assoc.display_name, "TestOrigin / test2") + self.assertEqual(name_assoc.id, self.record2.id) - name_assoc = self.record3.display_name - self.assertEqual(name_assoc[0][1], "TestOrigin / test2 / test3") - self.assertEqual(name_assoc[0][0], self.record3.id) + name_assoc = self.record3 + name_assoc._compute_display_name() + self.assertEqual(name_assoc.display_name, "TestOrigin / test2 / test3") + self.assertEqual(name_assoc.id, self.record3.id)