Skip to content

[T3236] FIX: gift recipient dropdown must only show accepted sponsorships#336

Merged
ecino merged 3 commits into
14.0from
T3236-child-list-gift
Jun 17, 2026
Merged

[T3236] FIX: gift recipient dropdown must only show accepted sponsorships#336
ecino merged 3 commits into
14.0from
T3236-child-list-gift

Conversation

@Danielgergely

Copy link
Copy Markdown
Member

Proposed children (sub-sponsorships not yet accepted by the sponsor) are now not selectabel as gift recipients on the donation pages.

  • The dropdown list is filtered, like the children page
  • The recipient is also validated server-side on gift submission

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a helper method _get_gift_eligible_sponsorships to filter sponsorships eligible for gifts and adds validation to ensure the recipient is valid and eligible, raising a BadRequest otherwise. The review feedback suggests changing _get_gift_eligible_sponsorships from a static method to an instance method to support Odoo's inheritance, and adding an optional partner parameter to _extract_donation_order_line_fields to allow correct validation when editing order lines for different partners.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread my_compassion/controllers/my2_donations.py Outdated
Comment thread my_compassion/controllers/my2_donations.py
Comment thread my_compassion/controllers/my2_donations.py
@greptile-apps

greptile-apps Bot commented Jun 5, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

Safe to merge — the change closes a real data-access gap with both a consistent frontend filter and a server-side check, and no regressions were found.

The logic is straightforward: a single shared helper replaces bare sponsorship_ids access in every affected endpoint, and the server-side validation in _extract_donation_order_line_fields closes the bypass path. The filter correctly uses can_show_on_my_compassion (which already excludes sub-sponsorships with a parent in non-active states) plus an extra guard on fully-exited terminated contracts. No incorrect recipients can be accepted — if a recipient is ineligible, BadRequest is raised before any write occurs.

No files require special attention.

Important Files Changed

Filename Overview
my_compassion/controllers/my2_donations.py Adds _get_gift_eligible_sponsorships helper and server-side validation for gift recipient; replaces all bare sponsorship_ids accesses with the filtered helper; changes _extract_donation_order_line_fields from static to instance method.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Browser
    participant Controller as my2_donations.py
    participant Helper as _get_gift_eligible_sponsorships
    participant DB as recurring.contract

    Browser->>Controller: "GET /my2/gifts/<product> (render page)"
    Controller->>Helper: _get_gift_eligible_sponsorships(partner)
    Helper->>DB: partner.sponsorship_ids
    DB-->>Helper: all sponsorships
    Helper-->>Controller: filtered (can_show_on_my_compassion + not fully terminated)
    Controller-->>Browser: render form with filtered sponsorship dropdown

    Browser->>Controller: POST /my2/gifts/new (submit gift)
    Controller->>Controller: _extract_donation_order_line_fields(product, post)
    Controller->>Helper: _get_gift_eligible_sponsorships(partner)
    Helper-->>Controller: eligible sponsorship IDs
    alt recipient_id in eligible.ids
        Controller-->>Browser: gift added to cart
    else recipient_id not in eligible.ids
        Controller-->>Browser: 400 BadRequest
    end
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Browser
    participant Controller as my2_donations.py
    participant Helper as _get_gift_eligible_sponsorships
    participant DB as recurring.contract

    Browser->>Controller: "GET /my2/gifts/<product> (render page)"
    Controller->>Helper: _get_gift_eligible_sponsorships(partner)
    Helper->>DB: partner.sponsorship_ids
    DB-->>Helper: all sponsorships
    Helper-->>Controller: filtered (can_show_on_my_compassion + not fully terminated)
    Controller-->>Browser: render form with filtered sponsorship dropdown

    Browser->>Controller: POST /my2/gifts/new (submit gift)
    Controller->>Controller: _extract_donation_order_line_fields(product, post)
    Controller->>Helper: _get_gift_eligible_sponsorships(partner)
    Helper-->>Controller: eligible sponsorship IDs
    alt recipient_id in eligible.ids
        Controller-->>Browser: gift added to cart
    else recipient_id not in eligible.ids
        Controller-->>Browser: 400 BadRequest
    end
Loading

Reviews (3): Last reviewed commit: "Merge branch '14.0' into T3236-child-lis..." | Re-trigger Greptile

Comment thread my_compassion/controllers/my2_donations.py
- STYLE: pre commit fix from previous change
@Danielgergely

Copy link
Copy Markdown
Member Author

@NoeBerdoz
FYI I know you are migrating branch the my_compassion module, but this change is quite important. It should prevent users from donating to inactive children. You might want to integrate these changes as well

@ecino ecino left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@ecino ecino merged commit a1ffe59 into 14.0 Jun 17, 2026
1 check passed
@ecino ecino deleted the T3236-child-list-gift branch June 17, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants