Skip to content

Commit

Permalink
Merge pull request #210 from OpenG2P/fix-name-change
Browse files Browse the repository at this point in the history
Fix name change function
  • Loading branch information
shibu-narayanan authored Dec 17, 2024
2 parents c6f1736 + 6ad4a4d commit cb71958
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 32 deletions.
18 changes: 11 additions & 7 deletions g2p_registry_individual/models/individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ def _get_dynamic_selection(self):
def name_change(self):
vals = {}
if not self.is_group:
name = ""
if self.family_name:
name += self.family_name + ", "
if self.given_name:
name += self.given_name + " "
if self.addl_name:
name += self.addl_name + " "
name_vals = [
f"{self.family_name},"
if self.family_name and (self.given_name or self.addl_name)
else f"{self.family_name}"
if self.family_name
else "",
self.given_name,
self.addl_name,
]

name = " ".join(filter(None, name_vals))
vals.update({"name": name.upper()})
self.update(vals)

Expand Down
74 changes: 49 additions & 25 deletions g2p_registry_individual/tests/test_individuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,56 @@ def setUpClass(cls):
"is_registrant": True,
}
)
cls.registrant_no_given_name = cls.env["res.partner"].create(
{
"name": "Josephine Demophon",
"family_name": "Demophon",
"given_name": "",
"addl_name": "Josephine",
"is_group": False,
"is_registrant": True,
}
)
cls.registrant_no_addl_name = cls.env["res.partner"].create(
{
"name": "Amaphia Demophon",
"family_name": "Demophon",
"given_name": "Amaphia",
"addl_name": "",
"is_group": False,
"is_registrant": True,
}
)
cls.registrant_all_names = cls.env["res.partner"].create(
{
"name": "Amaphia Jospehine Demophon",
"family_name": "Demophon",
"given_name": "Amaphia",
"addl_name": "Josephine",
"is_group": False,
"is_registrant": True,
}
)
cls.registrant_no_family_name = cls.env["res.partner"].create(
{
"name": "Amaphia Jospehine",
"family_name": "",
"given_name": "Amaphia",
"addl_name": "Josephine",
"is_group": False,
"is_registrant": True,
}
)

def test_01_check_names(self):
self.registrant_1.name_change()
message = "NAME FAILED (EXPECTED {} but RESULT is {})".format(
"JADDRANKA, HEIDI ",
self.registrant_1.name,
)
self.assertEqual(self.registrant_1.name, "JADDRANKA, HEIDI ", message)
self.registrant_2.name_change()
message = "NAME FAILED (EXPECTED {} but RESULT is {})".format(
"KLEITOS, ANGUS ",
self.registrant_2.name,
)
self.assertEqual(self.registrant_2.name, "KLEITOS, ANGUS ", message)
self.registrant_3.name_change()
message = "NAME FAILED (EXPECTED {} but RESULT is {})".format(
"CARATACOS, SORA ",
self.registrant_3.name,
)
self.assertEqual(self.registrant_3.name, "CARATACOS, SORA ", message)
self.registrant_4.name_change()
message = "NAME FAILED (EXPECTED {} but RESULT is {})".format(
"DEMOPHON, AMAPHIA ",
self.registrant_4.name,
)
self.assertEqual(self.registrant_4.name, "DEMOPHON, AMAPHIA ", message)
def test_01_check_name_change(self):
self.registrant_no_family_name.name_change()
self.assertEqual(self.registrant_no_family_name.name, "AMAPHIA JOSEPHINE")
self.registrant_all_names.name_change()
self.assertEqual(self.registrant_all_names.name, "DEMOPHON, AMAPHIA JOSEPHINE")
self.registrant_no_addl_name.name_change()
self.assertEqual(self.registrant_no_addl_name.name, "DEMOPHON, AMAPHIA")
self.registrant_no_given_name.name_change()
self.assertEqual(self.registrant_no_given_name.name, "DEMOPHON, JOSEPHINE")

def test_02_age_calculation(self):
start_date = date(2000, 1, 1)
Expand Down

0 comments on commit cb71958

Please sign in to comment.