Skip to content

Commit

Permalink
[FIX] mgmtsystem_nonconformity: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EdgarRetes committed Sep 24, 2024
1 parent fe806fb commit 612d5ca
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 14 additions & 11 deletions mgmtsystem_nonconformity/tests/test_cause.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
21 changes: 12 additions & 9 deletions mgmtsystem_nonconformity/tests/test_origin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 612d5ca

Please sign in to comment.