From af58495a675cd08283bf7542e503e8d24622157c Mon Sep 17 00:00:00 2001 From: Daniel Palumbo Date: Wed, 11 Nov 2026 08:35:01 +0100 Subject: [PATCH 1/4] [T3675] FIX gift merge crash when the new gift has no message Merging a second pending gift (same sponsorship, type and year) read other_gift_vals["instructions"], which gift creation from a payment never provides: the gift job failed with KeyError and the gift was never created. Also decorate account.move.line.create with api.model_create_multi. --- gift_compassion/models/account_move_line.py | 3 ++- gift_compassion/models/sponsorship_gift.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gift_compassion/models/account_move_line.py b/gift_compassion/models/account_move_line.py index c0c6a7106..8b3a9bae2 100644 --- a/gift_compassion/models/account_move_line.py +++ b/gift_compassion/models/account_move_line.py @@ -7,7 +7,7 @@ # The licence is in the file __manifest__.py # ############################################################################## -from odoo import fields, models +from odoo import api, fields, models class AccountMoveLine(models.Model): @@ -36,6 +36,7 @@ def _trigger_gifts(self): identity_key=f"gift_from_inv_line_{move_line.id}", ) + @api.model_create_multi def create(self, vals_list): res = super().create(vals_list) res.mapped("move_id")._filter_move_lines_to_gift()._trigger_gifts() diff --git a/gift_compassion/models/sponsorship_gift.py b/gift_compassion/models/sponsorship_gift.py index 750d43200..0dc129690 100644 --- a/gift_compassion/models/sponsorship_gift.py +++ b/gift_compassion/models/sponsorship_gift.py @@ -291,7 +291,7 @@ def _blend_in_other_gift(self, other_gift_vals): else: aggregated_amounts = self.amount + other_gift_vals.get("amount", 0) self.write({"amount": aggregated_amounts}) - instructions = [self.instructions, other_gift_vals["instructions"]] + instructions = [self.instructions, other_gift_vals.get("instructions")] self.instructions = "; ".join([x for x in instructions if x]) return self From 43c3678c3e43363ea31c5ebcbdc86ffc62562011 Mon Sep 17 00:00:00 2001 From: Daniel Palumbo Date: Wed, 11 Nov 2026 08:35:01 +0100 Subject: [PATCH 2/4] [T3675] Gift message from the payment line New journal item field gift_instructions ("Gift message"), copied into the gift's instructions when the gift is created from a payment line. --- gift_compassion/__manifest__.py | 2 +- gift_compassion/i18n/de_DE.po | 10 ++++++++++ gift_compassion/i18n/fr_CH.po | 10 ++++++++++ gift_compassion/i18n/it_IT.po | 10 ++++++++++ gift_compassion/models/account_move_line.py | 5 +++++ gift_compassion/models/sponsorship_gift.py | 1 + 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/gift_compassion/__manifest__.py b/gift_compassion/__manifest__.py index e956cec65..0ac5c7303 100644 --- a/gift_compassion/__manifest__.py +++ b/gift_compassion/__manifest__.py @@ -28,7 +28,7 @@ # pylint: disable=C8101 { "name": "Compassion Sponsorship Gifts", - "version": "18.0.1.0.0", + "version": "18.0.1.0.1", "category": "Compassion", "author": "Compassion CH", "license": "AGPL-3", diff --git a/gift_compassion/i18n/de_DE.po b/gift_compassion/i18n/de_DE.po index accde20b8..c2a27044c 100644 --- a/gift_compassion/i18n/de_DE.po +++ b/gift_compassion/i18n/de_DE.po @@ -253,6 +253,11 @@ msgstr "Geschenk nicht zustellbar" msgid "Gift Undeliverable Notification" msgstr "Benachrichtigung: Geschenk nicht zustellbar" +#. module: gift_compassion +#: model:ir.model.fields,field_description:gift_compassion.field_account_move_line__gift_instructions +msgid "Gift message" +msgstr "Geschenknachricht" + #. module: gift_compassion #: model:ir.model.fields,field_description:gift_compassion.field_gift_threshold_settings__gift_type_id msgid "Gift type" @@ -395,6 +400,11 @@ msgstr "Maximalbetrag" msgid "Message Delivery error" msgstr "Fehler beim Senden der Nachricht" +#. module: gift_compassion +#: model:ir.model.fields,help:gift_compassion.field_account_move_line__gift_instructions +msgid "Message sent with the gift to the child." +msgstr "Nachricht, die mit dem Geschenk an das Kind geschickt wird." + #. module: gift_compassion #: model:ir.model.fields,field_description:gift_compassion.field_sponsorship_gift__message_ids msgid "Messages" diff --git a/gift_compassion/i18n/fr_CH.po b/gift_compassion/i18n/fr_CH.po index 441be3390..4f72bf0a6 100644 --- a/gift_compassion/i18n/fr_CH.po +++ b/gift_compassion/i18n/fr_CH.po @@ -253,6 +253,11 @@ msgstr "Cadeau non livrable" msgid "Gift Undeliverable Notification" msgstr "Notification de cadeau non livrable" +#. module: gift_compassion +#: model:ir.model.fields,field_description:gift_compassion.field_account_move_line__gift_instructions +msgid "Gift message" +msgstr "Message du cadeau" + #. module: gift_compassion #: model:ir.model.fields,field_description:gift_compassion.field_gift_threshold_settings__gift_type_id msgid "Gift type" @@ -393,6 +398,11 @@ msgstr "Montant maximum" msgid "Message Delivery error" msgstr "Erreur d'envoi du message" +#. module: gift_compassion +#: model:ir.model.fields,help:gift_compassion.field_account_move_line__gift_instructions +msgid "Message sent with the gift to the child." +msgstr "Message envoyé à l'enfant avec le cadeau." + #. module: gift_compassion #: model:ir.model.fields,field_description:gift_compassion.field_sponsorship_gift__message_ids msgid "Messages" diff --git a/gift_compassion/i18n/it_IT.po b/gift_compassion/i18n/it_IT.po index c1cac2dd4..dd496231f 100644 --- a/gift_compassion/i18n/it_IT.po +++ b/gift_compassion/i18n/it_IT.po @@ -253,6 +253,11 @@ msgstr "Regalo non consegnabile" msgid "Gift Undeliverable Notification" msgstr "Notifica di regalo non consegnabile" +#. module: gift_compassion +#: model:ir.model.fields,field_description:gift_compassion.field_account_move_line__gift_instructions +msgid "Gift message" +msgstr "Messaggio del regalo" + #. module: gift_compassion #: model:ir.model.fields,field_description:gift_compassion.field_gift_threshold_settings__gift_type_id msgid "Gift type" @@ -393,6 +398,11 @@ msgstr "Importo massimo" msgid "Message Delivery error" msgstr "Errore di consegna messaggio" +#. module: gift_compassion +#: model:ir.model.fields,help:gift_compassion.field_account_move_line__gift_instructions +msgid "Message sent with the gift to the child." +msgstr "Messaggio inviato al bambino insieme al regalo." + #. module: gift_compassion #: model:ir.model.fields,field_description:gift_compassion.field_sponsorship_gift__message_ids msgid "Messages" diff --git a/gift_compassion/models/account_move_line.py b/gift_compassion/models/account_move_line.py index 8b3a9bae2..eff9dc4c7 100644 --- a/gift_compassion/models/account_move_line.py +++ b/gift_compassion/models/account_move_line.py @@ -16,6 +16,11 @@ class AccountMoveLine(models.Model): gift_id = fields.Many2one( "sponsorship.gift", "GMC Gift", readonly=False, copy=False ) + gift_instructions = fields.Char( + "Gift message", + copy=False, + help="Message sent with the gift to the child.", + ) def _trigger_gifts(self): gift_category = self.env.ref("sponsorship_compassion.product_category_gift") diff --git a/gift_compassion/models/sponsorship_gift.py b/gift_compassion/models/sponsorship_gift.py index 0dc129690..676a2f8b6 100644 --- a/gift_compassion/models/sponsorship_gift.py +++ b/gift_compassion/models/sponsorship_gift.py @@ -349,6 +349,7 @@ def create_from_invoice_line(self, invoice_line_id): } if invoice_line.debit == 0 and invoice_line.credit > 0: + gift_vals["instructions"] = invoice_line.gift_instructions or False gift = self.create(gift_vals) eligible, message = gift.is_eligible() if not eligible: From 3f4519c5047f1baa98e475cf816cd52bd8623af3 Mon Sep 17 00:00:00 2001 From: Daniel Palumbo Date: Wed, 11 Nov 2026 08:35:01 +0100 Subject: [PATCH 3/4] [T3675] Tests for the gift message and the gift merge --- gift_compassion/tests/__init__.py | 1 + .../tests/test_gift_from_payment.py | 112 ++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 gift_compassion/tests/__init__.py create mode 100644 gift_compassion/tests/test_gift_from_payment.py diff --git a/gift_compassion/tests/__init__.py b/gift_compassion/tests/__init__.py new file mode 100644 index 000000000..e555ed1aa --- /dev/null +++ b/gift_compassion/tests/__init__.py @@ -0,0 +1 @@ +from . import test_gift_from_payment diff --git a/gift_compassion/tests/test_gift_from_payment.py b/gift_compassion/tests/test_gift_from_payment.py new file mode 100644 index 000000000..a81ca911a --- /dev/null +++ b/gift_compassion/tests/test_gift_from_payment.py @@ -0,0 +1,112 @@ +from odoo.tests import TransactionCase, tagged + + +@tagged("post_install", "-at_install") +class TestGiftFromPayment(TransactionCase): + """Runs on a database with real sponsorships (no demo data needed).""" + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, no_upsert=True)) + cls.gift_obj = cls.env["sponsorship.gift"] + cls.gift_type = cls.env["sponsorship.gift.type"].search( + [("product_id", "!=", False)], limit=1 + ) + cls.sponsorship = cls.env["recurring.contract"].search( + [ + ("state", "=", "active"), + ("child_id", "!=", False), + ("company_id", "=", cls.env.company.id), + ], + limit=1, + ) + cls.partner_1 = cls.sponsorship.gift_partner_id + + def setUp(self): + super().setUp() + if not self.gift_type or not self.sponsorship: + self.skipTest("Needs an active sponsorship and a gift type with product") + # Start from a sponsorship without pending gifts of that type + self.gift_obj.search( + [ + ("sponsorship_id", "=", self.sponsorship.id), + ("gift_type_id", "=", self.gift_type.id), + ("state", "in", ["draft", "verify"]), + ] + ).write({"state": "Undeliverable"}) + + def _gift_vals(self, **kwargs): + vals = { + "sponsorship_id": self.sponsorship.id, + "gift_type_id": self.gift_type.id, + "amount": 10.0, + "gift_date": "2026-11-10", + } + vals.update(kwargs) + return vals + + def _create_payment_line(self, instructions): + company = self.env.company + income = self.env["account.account"].search( + [ + ("account_type", "=", "income"), + ("company_ids", "in", company.id), + ], + limit=1, + ) + journal = self.env["account.journal"].search( + [("type", "=", "general"), ("company_id", "=", company.id)], limit=1 + ) + move = self.env["account.move"].create( + { + "move_type": "entry", + "journal_id": journal.id, + "line_ids": [ + ( + 0, + 0, + { + "account_id": journal.default_account_id.id or income.id, + "debit": 10.0, + }, + ), + ( + 0, + 0, + { + "account_id": income.id, + "partner_id": self.partner_1.id, + "credit": 10.0, + "product_id": self.gift_type.product_id.id, + "contract_id": self.sponsorship.id, + "gift_instructions": instructions, + }, + ), + ], + } + ) + return move.line_ids.filtered("credit") + + def test_merge_pending_gift_without_instructions(self): + """A second pending gift for the same sponsorship, type and year is + merged into the first one, even when no message is given.""" + first = self.gift_obj.create(self._gift_vals(instructions="Happy birthday")) + second = self.gift_obj.create(self._gift_vals()) + self.assertEqual(second, first) + self.assertEqual(first.amount, 20.0) + self.assertEqual(first.instructions, "Happy birthday") + + def test_gift_message_from_payment_line(self): + """The gift created from a payment line gets the line's message, and + a second payment adds its message to the pending gift.""" + line = self._create_payment_line("Happy birthday") + gift = self.gift_obj.create_from_invoice_line(line.id) + self.assertEqual(gift.instructions, "Happy birthday") + self.assertEqual(gift.invoice_line_ids, line) + + other_line = self._create_payment_line("God bless you") + merged = self.gift_obj.create_from_invoice_line(other_line.id) + self.assertEqual(merged, gift) + self.assertEqual(gift.instructions, "Happy birthday; God bless you") + self.assertEqual(gift.invoice_line_ids, line + other_line) From 74ee09bfdc9007f2f1cb7dea7335ea476bbfbfba Mon Sep 17 00:00:00 2001 From: Daniel Palumbo Date: Wed, 11 Nov 2026 09:10:06 +0100 Subject: [PATCH 4/4] [T3675] Search contracts by sponsor ref and child code Contract fields (e.g. in the reconcile view) only searched the contract reference, while the contract name shows the sponsor ref and the child code: typing what is displayed found nothing. --- sponsorship_compassion/models/contracts.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sponsorship_compassion/models/contracts.py b/sponsorship_compassion/models/contracts.py index 5fcfa0905..33cb8dac7 100644 --- a/sponsorship_compassion/models/contracts.py +++ b/sponsorship_compassion/models/contracts.py @@ -30,9 +30,11 @@ class SponsorshipContract(models.Model): _inherit = ["recurring.contract", "compassion.mapped.model"] _name = "recurring.contract" + # Search contracts by what their name shows (sponsor ref - child code) + _rec_names_search = ["reference", "partner_id.ref", "child_id.local_id"] ########################################################################## - # FIELDS # + # FIELDS # ########################################################################## correspondent_id = fields.Many2one( "res.partner",