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

Fix name change function #210

Open
wants to merge 3 commits into
base: 17.0-develop
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
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
Loading