Skip to content

Commit e7a8d29

Browse files
committed
fix(change_request): show real data (not counts) on Add Member review (#871)
The Add Member CR review page showed only counts for phones/bank/ID docs and omitted the added individual's details. Surface the full data via the generic _tables contract (shared with Create Group): - All individual fields are shown even when empty (name, role, date of birth, gender, civil status, occupation, birth place, income, area, address, email, location). - Phone Numbers / Bank Accounts / ID Documents render as their own tables. - Drop the phone/bank/id_doc count keys. The head-of-household replacement feature was reverted separately and deferred to #1006.
1 parent fbb2ca9 commit e7a8d29

2 files changed

Lines changed: 97 additions & 7 deletions

File tree

spp_change_request_v2/strategies/add_member.py

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,65 @@ def preview(self, change_request):
6464
detail = change_request.get_detail()
6565
if not detail:
6666
return {}
67+
68+
location = None
69+
if detail.latitude or detail.longitude:
70+
location = f"{detail.latitude}, {detail.longitude}"
71+
72+
# One2many lines render as their own tables on the review page, via the
73+
# generic "_tables" contract shared with Create Group (OP#871).
74+
tables = []
75+
phone_rows = [
76+
[p.phone_no or "", p.country_id.display_name or "", _("Yes") if p.is_primary else ""]
77+
for p in detail.phone_line_ids
78+
]
79+
if phone_rows:
80+
tables.append(
81+
{"title": _("Phone Numbers"), "columns": [_("Number"), _("Country"), _("Primary")], "rows": phone_rows}
82+
)
83+
bank_rows = [
84+
[b.acc_number or "", b.acc_holder_name or "", b.bank_id.display_name or ""] for b in detail.bank_line_ids
85+
]
86+
if bank_rows:
87+
tables.append(
88+
{
89+
"title": _("Bank Accounts"),
90+
"columns": [_("Account Number"), _("Account Holder"), _("Bank")],
91+
"rows": bank_rows,
92+
}
93+
)
94+
id_doc_rows = [
95+
[d.id_type_id.display_name or "", d.value or "", str(d.expiry_date) if d.expiry_date else ""]
96+
for d in detail.id_doc_line_ids
97+
]
98+
if id_doc_rows:
99+
tables.append(
100+
{
101+
"title": _("ID Documents"),
102+
"columns": [_("Type"), _("Number"), _("Expiry Date")],
103+
"rows": id_doc_rows,
104+
}
105+
)
106+
107+
# Show every individual field even when empty (QA #871) — empty values
108+
# render as a "-" placeholder through the action-summary formatter.
67109
return {
68110
"_action": "create_member",
69111
"_header": _("The following individual is to be added:"),
70-
"member_name": detail.member_name,
71-
"group": change_request.registrant_id.name,
72-
"role": detail.membership_type_id.display if detail.membership_type_id else None,
73-
"address": detail.address,
74-
"phone_count": len(detail.phone_line_ids),
75-
"bank_count": len(detail.bank_line_ids),
76-
"id_doc_count": len(detail.id_doc_line_ids),
112+
_("Group"): change_request.registrant_id.name,
113+
_("Name"): detail.member_name,
114+
_("Role"): detail.membership_type_id.display if detail.membership_type_id else None,
115+
_("Date of Birth"): str(detail.birthdate) if detail.birthdate else None,
116+
_("Gender"): detail.gender_id.display_name if detail.gender_id else None,
117+
_("Civil Status"): detail.civil_status_id.display_name if detail.civil_status_id else None,
118+
_("Occupation"): detail.occupation_id.display_name if detail.occupation_id else None,
119+
_("Birth Place"): detail.birth_place or None,
120+
_("Income"): detail.income or None,
121+
_("Area"): detail.area_id.display_name if detail.area_id else None,
122+
_("Address"): detail.address or None,
123+
_("Email"): detail.email or None,
124+
_("Location"): location,
125+
"_tables": tables,
77126
}
78127

79128
# ──────────────────────────────────────────────────────────────────────

spp_change_request_v2/tests/test_add_member_strategy.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,47 @@ def test_preview_returns_create_member_action(self):
222222
# The review banner header is sourced from the preview (OP#871 QA round 1).
223223
self.assertIn("individual", (preview.get("_header") or "").lower())
224224

225+
def test_preview_shows_fields_and_tables(self):
226+
"""OP#871: the review preview shows the added individual's fields (even
227+
when empty) and renders phones/bank/ID docs as tables, not counts."""
228+
id_type = self.env["spp.vocabulary.code"].search(
229+
[("vocabulary_id.namespace_uri", "=", "urn:openspp:vocab:id-type")], limit=1
230+
)
231+
cr = self._make_cr(
232+
given_name="Maria",
233+
family_name="Santos",
234+
birthdate="1995-03-12",
235+
email="maria@example.com",
236+
phone_line_ids=[(0, 0, {"phone_no": "+63900000001", "is_primary": True})],
237+
bank_line_ids=[(0, 0, {"acc_number": "ACCT-22"})],
238+
id_doc_line_ids=([(0, 0, {"id_type_id": id_type.id, "value": "DOC-3"})] if id_type else []),
239+
)
240+
preview = cr.action_preview_changes()
241+
242+
# Counts are replaced by actual data.
243+
for removed in ("phone_count", "bank_count", "id_doc_count"):
244+
self.assertNotIn(removed, preview)
245+
246+
# Individual fields present, including ones left empty (render as "-" later).
247+
self.assertEqual(preview["Name"], "SANTOS, Maria")
248+
self.assertEqual(preview["Date of Birth"], "1995-03-12")
249+
self.assertEqual(preview["Email"], "maria@example.com")
250+
self.assertIn("Occupation", preview)
251+
self.assertIn("Civil Status", preview)
252+
253+
titles = [t["title"] for t in preview["_tables"]]
254+
self.assertIn("Phone Numbers", titles)
255+
self.assertIn("Bank Accounts", titles)
256+
phones = next(t for t in preview["_tables"] if t["title"] == "Phone Numbers")
257+
self.assertIn("+63900000001", phones["rows"][0])
258+
259+
# Rendered review HTML shows the data + field labels, no leaked count keys.
260+
html = cr._generate_review_comparison_html()
261+
self.assertIn("Maria", html)
262+
self.assertIn("+63900000001", html)
263+
self.assertIn("Occupation", html)
264+
self.assertNotIn("phone_count", html)
265+
225266
def test_add_member_writes_single_address(self):
226267
"""The single Address field maps to the registry's res.partner.address
227268
on apply, matching how the registry stores it (OP#871 QA round 1)."""

0 commit comments

Comments
 (0)