From be8b4219e2cbd8ca600d068133c4b266ebc8236a Mon Sep 17 00:00:00 2001 From: Daniel Gergely Date: Thu, 19 Mar 2026 16:17:49 +0100 Subject: [PATCH 1/2] [T2747] FIX: moved state update to after payment configuration - FIX: changing state triggers the creation of the communication job, but the payment information/pdf is not yet in the db at the time. This should solve that issue. Testing is still needed! --- 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 d2730b84f..c74b32931 100644 --- a/sponsorship_compassion/models/contracts.py +++ b/sponsorship_compassion/models/contracts.py @@ -802,7 +802,6 @@ def contract_active(self): not_active = self.filtered(lambda c: not c.is_active) if not_active: not_active.write({"activation_date": fields.Datetime.now()}) - self.write({"state": "active"}) last_line_id = self.search( [("sponsorship_line_id", "!=", False)], order="sponsorship_line_id desc", @@ -816,6 +815,13 @@ def contract_active(self): last_line_id += 1 contract.sponsorship_line_id = last_line_id + # Flush env so db reflects payment mode + self.env['res.partner'].flush() + self.env['recurring.contract'].flush() + + # trigger auto comm job after payment info is written to the db + self.write({"state": "active"}) + # Cancel the old invoices if a contract is activated delay = datetime.now() + relativedelta(seconds=30) self.with_delay( From d24b7b61022694ca659e7937427c8e80d52fc437 Mon Sep 17 00:00:00 2001 From: ecino Date: Wed, 25 Mar 2026 09:38:46 +0100 Subject: [PATCH 2/2] Update sponsorship_compassion/models/contracts.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- intervention_compassion/data/account.analytic.group.csv | 2 +- sponsorship_compassion/models/contracts.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/intervention_compassion/data/account.analytic.group.csv b/intervention_compassion/data/account.analytic.group.csv index 2e60925db..75c4b9d2a 100644 --- a/intervention_compassion/data/account.analytic.group.csv +++ b/intervention_compassion/data/account.analytic.group.csv @@ -31,4 +31,4 @@ analytic_group_unrestricted,unrestricted fund,analytic_group_fund analytic_group_christmas,christmas fund,analytic_group_fund analytic_group_local,local fund,analytic_group_fund analytic_group_ldp,ldp fund,analytic_group_fund -analytic_group_usp,unsponsored fund,analytic_group_fund \ No newline at end of file +analytic_group_usp,unsponsored fund,analytic_group_fund diff --git a/sponsorship_compassion/models/contracts.py b/sponsorship_compassion/models/contracts.py index c74b32931..e6c882f64 100644 --- a/sponsorship_compassion/models/contracts.py +++ b/sponsorship_compassion/models/contracts.py @@ -816,8 +816,8 @@ def contract_active(self): contract.sponsorship_line_id = last_line_id # Flush env so db reflects payment mode - self.env['res.partner'].flush() - self.env['recurring.contract'].flush() + self.mapped("partner_id").flush() + self.flush() # trigger auto comm job after payment info is written to the db self.write({"state": "active"})