From 9f077231e32dd8908a2e97980a161a6ced0565d5 Mon Sep 17 00:00:00 2001 From: davidwul Date: Mon, 30 Sep 2024 09:47:56 +0200 Subject: [PATCH] Update contracts.py (#1971) * Update contracts.py avoid to generate infinitely gift/christmas invoices when there are correspondent AND send_gift is set to correspondent * Update contracts.py --- sponsorship_compassion/models/contracts.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sponsorship_compassion/models/contracts.py b/sponsorship_compassion/models/contracts.py index 857def1b8..77ef69762 100644 --- a/sponsorship_compassion/models/contracts.py +++ b/sponsorship_compassion/models/contracts.py @@ -1099,11 +1099,17 @@ def _generate_gifts(self, invoicer, gift_type): # checks if there is already a gift for this year which has been cancelled gift_this_year = self.env["account.move.line"].search( [ - ("partner_id", "=", contract.partner_id.id), ("product_id", "=", product_id), ("date", ">=", start_of_year), ("date", "<=", end_of_year), ("contract_id", "=", contract.id), + "|", + "&", + ("partner_id", "=", contract.correspondent_id.id), + ("contract_id.send_gifts_to", "=", "correspondent_id"), + "&", + ("partner_id", "=", contract.partner_id.id), + ("contract_id.send_gifts_to", "=", "partner_id"), ] ) if gift_this_year: