Skip to content
Merged
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
40 changes: 22 additions & 18 deletions child_compassion/models/compassion_hold.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,24 +486,28 @@ def postpone_no_money_hold(self, additional_text=None):
}
hold.write(hold_vals)

body = (
"The no money hold for child {local_id} was expiring on "
"{old_expiration} and was extended to {new_expiration} "
"({extension_description} extension).{additional_text}"
)
hold.message_post(
body=_(body.format(**values)),
subject=_("No money hold extension"),
subtype_xmlid="mail.mt_comment",
)

else:
body = _(
"The no money hold for child {local_id} is expiring on "
"{old_expiration} and will not be extended since "
"no sponsorship exists for this child."
)
hold.message_post(body=body.format(**values))
# ----------------------------------------------------
# NOTIFICATION (Only for NO_MONEY_HOLD)
# ----------------------------------------------------
if hold.type == HoldType.NO_MONEY_HOLD.value:
if hold.child_id.sponsor_id:
body = (
"The no money hold for child {local_id} was expiring on "
"{old_expiration} and was extended to {new_expiration} "
"({extension_description} extension).{additional_text}"
)
hold.message_post(
body=_(body.format(**values)),
subject=_("No money hold extension"),
subtype_xmlid="mail.mt_comment",
)
else:
body = _(
"The no money hold for child {local_id} is expiring on "
"{old_expiration} and will not be extended since "
"no sponsorship exists for this child."
)
hold.message_post(body=body.format(**values))
Comment on lines +492 to +510
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This change correctly restricts notifications to NO_MONEY_HOLD types. However, it introduces a duplicated check for hold.child_id.sponsor_id (first at line 479, then again at line 493). This makes the code less efficient and harder to maintain.

Consider refactoring the postpone_no_money_hold method to avoid this duplication. A better structure would be:

if hold.child_id.sponsor_id:  # Check that a sponsorship exists
    # ... (logic to extend the hold)
    hold.write(hold_vals)

    if hold.type == HoldType.NO_MONEY_HOLD.value:
        body = (
            "The no money hold for child {local_id} was expiring on "
            "{old_expiration} and was extended to {new_expiration} "
            "({extension_description} extension).{additional_text}"
        )
        hold.message_post(
            body=_(body.format(**values)),
            subject=_("No money hold extension"),
            subtype_xmlid="mail.mt_comment",
        )
else:
    if hold.type == HoldType.NO_MONEY_HOLD.value:
        body = _(
            "The no money hold for child {local_id} is expiring on "
            "{old_expiration} and will not be extended since "
            "no sponsorship exists for this child."
        )
        hold.message_post(body=body.format(**values))

This would require restructuring the logic starting from line 479.


##########################################################################
# Mapping METHOD #
Expand Down