Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion gift_compassion/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions gift_compassion/i18n/de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions gift_compassion/i18n/fr_CH.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions gift_compassion/i18n/it_IT.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion gift_compassion/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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")
Expand All @@ -36,6 +41,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()
Expand Down
3 changes: 2 additions & 1 deletion gift_compassion/models/sponsorship_gift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions gift_compassion/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_gift_from_payment
112 changes: 112 additions & 0 deletions gift_compassion/tests/test_gift_from_payment.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 3 additions & 1 deletion sponsorship_compassion/models/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading