From f7970513f5336b26bf216d5bb925211e7ed0ae8f Mon Sep 17 00:00:00 2001 From: SamBachmann Date: Tue, 25 Nov 2025 15:07:46 +0100 Subject: [PATCH 001/105] [T2534] FEAT add a method to get payment info into ContractGroup --- my_compassion/models/contract_group.py | 72 +++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/my_compassion/models/contract_group.py b/my_compassion/models/contract_group.py index 39ca65c25..ad23c2e9f 100644 --- a/my_compassion/models/contract_group.py +++ b/my_compassion/models/contract_group.py @@ -6,7 +6,7 @@ # The licence is in the file __manifest__.py # ############################################################################## -from odoo import fields, models +from odoo import fields, models, _ class ContractGroup(models.Model): @@ -23,3 +23,73 @@ def _compute_total_amount(self): lambda s: s.state not in ["terminated", "cancelled"] ).mapped("total_amount") ) + + # TODO : Revise this method once final logic and needs are clarified + def get_payment_method_info(self): + """ + Returns a dict containing display info for the group's payment method. + Used in MyCompassion2.0 portal. + + Logic: + 1. Get the Payment Mode from the group. + 2. Find the associated Payment Acquirer via fixed_journal_id from account.payment.mode + 3. Check if the partner has a saved Payment Token for that Acquirer. + """ + self.ensure_one() + + # Default / Fallback values + info = { + 'icon_url': '/my_compassion/static/src/img/undefined.png', + 'label': _('Unknown Method'), + 'type': 'manual', # 'manual', 'mode', or 'token' + 'brand': False, + 'mode_id': self.payment_mode_id.id if self.payment_mode_id else False + } + + if not self.payment_mode_id: + return info + + # 1. Basic Mode Info + info['label'] = self.sudo().payment_mode_id.name + info['type'] = 'mode' + + # 2. Resolve Acquirer via Journal (The link between Mode and Provider) + # The 'fixed_journal_id' on payment mode usually points to the bank/provider journal + journal_id = self.sudo().payment_mode_id.fixed_journal_id.id + acquirer = False + + if journal_id: + acquirer = self.env['payment.acquirer'].sudo().search([ + ('journal_id', '=', journal_id) + ], limit=1) + + if acquirer: + # 3. Find active Token (Saved Card) for this user + acquirer + valid_token = self.env['payment.token'].sudo().search([ + ('partner_id', '=', self.partner_id.id), + ('acquirer_id', '=', acquirer.id), + # We usually want the default/active one. If multiple exist, taking the first is standard. + ], limit=1) + + if valid_token: + # We found a specific saved card + info.update({ + 'icon_url': f'/my_compassion/static/src/img/{acquirer.id}/image_128', + 'label': valid_token.name, + 'type': 'token', + 'token_id': valid_token.id, + + 'brand': valid_token.name.split(' ')[0] if valid_token.name else False + }) + else: + # We have an online provider (like Stripe) but no token found + info.update({ + 'icon_url': f'/web/image/payment.acquirer/{acquirer.id}/image_128', + 'label': acquirer.display_as or acquirer.name, + }) + + # 4. Special handling for offline methods (LSV / Direct Debit) + elif 'LSV' in self.payment_mode_id.name or 'DD' in self.payment_mode_id.name: + info['label'] = _('Direct Debit (LSV)') + + return info From 645112c2081574ccbca946e4f19a6b64a23124fc Mon Sep 17 00:00:00 2001 From: SamBachmann Date: Wed, 26 Nov 2025 16:14:17 +0100 Subject: [PATCH 002/105] [T2534] FEAT add a modal to update/add payment method --- my_compassion/__manifest__.py | 1 + .../my2_payment_method_selector.xml | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 my_compassion/templates/components/my2_payment_method_selector.xml diff --git a/my_compassion/__manifest__.py b/my_compassion/__manifest__.py index 4833f15cb..1223dcc62 100644 --- a/my_compassion/__manifest__.py +++ b/my_compassion/__manifest__.py @@ -90,6 +90,7 @@ "templates/components/my2_giving_limits_modal.xml", "templates/components/my2_checkout.xml", "templates/components/my2_weather_time_container.xml", + "templates/components/my2_payment_method_selector.xml", # Other data the depends on the templates "data/my2_new_sponsorship_wizard_steps.xml", ], diff --git a/my_compassion/templates/components/my2_payment_method_selector.xml b/my_compassion/templates/components/my2_payment_method_selector.xml new file mode 100644 index 000000000..f89eac088 --- /dev/null +++ b/my_compassion/templates/components/my2_payment_method_selector.xml @@ -0,0 +1,58 @@ + + + + + \ No newline at end of file From 92cb3fe7fc86c90cb882d74abde00af50076df99 Mon Sep 17 00:00:00 2001 From: SamBachmann Date: Wed, 26 Nov 2025 16:16:03 +0100 Subject: [PATCH 003/105] [T2534] FEAT update controller to handle the groups of sponsorships --- my_compassion/controllers/my2_donations.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/my_compassion/controllers/my2_donations.py b/my_compassion/controllers/my2_donations.py index 1eb723638..767d92d35 100644 --- a/my_compassion/controllers/my2_donations.py +++ b/my_compassion/controllers/my2_donations.py @@ -399,6 +399,9 @@ def my_donations(self, invoice_page=1, invoice_per_page=12, **kw): # Active sponsorships active_sponsorships = partner.get_portal_sponsorships("active") + # Group sponsorships by their backend Contract Group + sponsorship_groups = active_sponsorships.mapped('group_id') + # Due invoices date_filter_up_bound = datetime.today() + timedelta(days=30) due_invoices = ( @@ -417,16 +420,16 @@ def my_donations(self, invoice_page=1, invoice_per_page=12, **kw): ) ) - # Computing the total price of the active sponsorships grouped - # per sponsorship frequency and payment method. - # group_id groups the invoices that have the same payment method and frequency. + # Total cost calculation tot_cost_per_frequency = defaultdict(lambda: defaultdict(float)) for sponsorship in active_sponsorships: currency = sponsorship.pricelist_id.currency_id.name - tot_cost_per_frequency[sponsorship.group_id.month_interval][ - currency - ] += sponsorship.total_amount + # Ensure group exists + if sponsorship.group_id: + tot_cost_per_frequency[sponsorship.group_id.month_interval][ + currency + ] += sponsorship.total_amount paid_invoices_data = self._get_paginated_paid_invoices( partner, invoice_page, invoice_per_page @@ -436,6 +439,7 @@ def my_donations(self, invoice_page=1, invoice_per_page=12, **kw): values.update( { "active_sponsorships": active_sponsorships, + "sponsorship_groups": sponsorship_groups, "tot_cost_per_frequency": tot_cost_per_frequency, "due_invoices": due_invoices, "paid_invoices_subset": paid_invoices_data["paid_invoices_subset"], From 20dc6779106de2257568e85c5321eb5ff895b370 Mon Sep 17 00:00:00 2001 From: SamBachmann Date: Wed, 26 Nov 2025 18:21:28 +0100 Subject: [PATCH 004/105] [T2534] FEAT group sponsorships by payment methods --- my_compassion/__manifest__.py | 2 +- .../components/my2_payment_method.xml | 127 ++++++++++++++++++ .../my2_payment_method_selector.xml | 58 -------- .../templates/pages/my2_donations.xml | 66 ++++----- 4 files changed, 152 insertions(+), 101 deletions(-) create mode 100644 my_compassion/templates/components/my2_payment_method.xml delete mode 100644 my_compassion/templates/components/my2_payment_method_selector.xml diff --git a/my_compassion/__manifest__.py b/my_compassion/__manifest__.py index 1223dcc62..ca24793f7 100644 --- a/my_compassion/__manifest__.py +++ b/my_compassion/__manifest__.py @@ -90,7 +90,7 @@ "templates/components/my2_giving_limits_modal.xml", "templates/components/my2_checkout.xml", "templates/components/my2_weather_time_container.xml", - "templates/components/my2_payment_method_selector.xml", + "templates/components/my2_payment_method.xml", # Other data the depends on the templates "data/my2_new_sponsorship_wizard_steps.xml", ], diff --git a/my_compassion/templates/components/my2_payment_method.xml b/my_compassion/templates/components/my2_payment_method.xml new file mode 100644 index 000000000..28a8e0998 --- /dev/null +++ b/my_compassion/templates/components/my2_payment_method.xml @@ -0,0 +1,127 @@ + + + + + + + diff --git a/my_compassion/templates/components/my2_payment_method_selector.xml b/my_compassion/templates/components/my2_payment_method_selector.xml deleted file mode 100644 index f89eac088..000000000 --- a/my_compassion/templates/components/my2_payment_method_selector.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - \ No newline at end of file diff --git a/my_compassion/templates/pages/my2_donations.xml b/my_compassion/templates/pages/my2_donations.xml index 496c51bf4..8f8df8c24 100644 --- a/my_compassion/templates/pages/my2_donations.xml +++ b/my_compassion/templates/pages/my2_donations.xml @@ -17,6 +17,7 @@ Page: My Compassion 2 Donations Page Injected data: - active_sponsorships (recordset): Sponsorships in active state for the logged-in partner. + - sponsorship_groups (recordset): Sponsorship groups by payment methods linked to the partner. - tot_cost_per_frequency (dict): Total sponsorship cost grouped by frequency and currency. - due_invoices (recordset): Outstanding invoices not yet paid. - paid_invoices_subset (recordset): Subset of paid invoices for donation history. @@ -81,7 +82,19 @@ Page: My Compassion 2 Donations Page - + + +

My sponsorships

@@ -107,47 +120,10 @@ Page: My Compassion 2 Donations Page A payment slip is available for download for each of your sponsored children.

- - -
- - - - - - - - - - - - - - - -
+ + + +
@@ -191,6 +167,12 @@ Page: My Compassion 2 Donations Page + + + + + +