Skip to content

Commit e0471eb

Browse files
committed
fix(change_request): create phone records for new group members on apply (#876)
A new individual's captured phone numbers were only folded into the partner's single header phone field, not created as spp.phone.number records — so they didn't appear in the registry's Phone Numbers list. Attach the phone records on apply, the same way the group's phones are attached.
1 parent 87dc4d1 commit e0471eb

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

spp_change_request_v2/strategies/create_group.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def apply(self, change_request):
3232
group = self._create_group(detail)
3333

3434
# 2. Multi-value attachments tied to the group partner.
35-
self._attach_phones(detail, group)
35+
self._attach_phones(detail.phone_line_ids, group)
3636
self._attach_banks(detail, group)
3737
self._attach_id_docs(detail, group)
3838

@@ -144,12 +144,14 @@ def _create_group(self, detail):
144144
# ──────────────────────────────────────────────────────────────────────
145145
# Sub-record attachers
146146
# ──────────────────────────────────────────────────────────────────────
147-
def _attach_phones(self, detail, group):
147+
def _attach_phones(self, phone_lines, partner):
148+
"""Create spp.phone.number records (the registry's Phone Numbers list)
149+
on ``partner`` from the given phone rows."""
148150
SppPhone = self.env["spp.phone.number"]
149-
for line in detail.phone_line_ids:
151+
for line in phone_lines:
150152
SppPhone.create(
151153
{
152-
"partner_id": group.id,
154+
"partner_id": partner.id,
153155
"phone_no": line.phone_no,
154156
"country_id": line.country_id.id if line.country_id else False,
155157
"date_collected": fields.Date.today(),
@@ -197,6 +199,9 @@ def _attach_members(self, detail, group):
197199
# Some downstream modules format the partner's name on the fly.
198200
if hasattr(individual, "name_change"):
199201
individual.name_change()
202+
# Create the individual's phone records (the registry's Phone
203+
# Numbers list), the same way the group's phones are attached.
204+
self._attach_phones(line.phone_line_ids, individual)
200205
self._create_membership(Membership, group, individual, line.membership_type_id, now)
201206

202207
def _new_member_vals(self, line):

spp_change_request_v2/tests/test_create_group_strategy.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,12 @@ def test_new_member_full_profile_written(self):
553553
self.assertEqual(individual.email, "maria@example.com")
554554
self.assertEqual(individual.income, 12345.0)
555555
# Multiple captured phone numbers are folded (in entry order) into the
556-
# partner's single header phone field.
556+
# partner's single header phone field...
557557
self.assertEqual(individual.phone, "+63911, +63922")
558+
# ...and also created as proper phone records (the registry's Phone
559+
# Numbers list), one per captured number.
560+
phone_recs = self.env["spp.phone.number"].search([("partner_id", "=", individual.id)])
561+
self.assertEqual(sorted(phone_recs.mapped("phone_no")), ["+63911", "+63922"])
558562
if occupation:
559563
self.assertEqual(individual.occupation_id, occupation)
560564
if civil:

0 commit comments

Comments
 (0)