From 996763d76f16b0c196ed350a50eb53a9acbf7db7 Mon Sep 17 00:00:00 2001 From: Pierrick Muller Date: Wed, 4 Sep 2024 08:52:20 +0200 Subject: [PATCH] T1710 Add survival sponsorship correspondent --- .../views/sponsorship_contract_view.xml | 2 +- .../models/__init__.py | 1 + .../models/res_partner.py | 37 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 survival_sponsorship_compassion/models/res_partner.py diff --git a/sponsorship_compassion/views/sponsorship_contract_view.xml b/sponsorship_compassion/views/sponsorship_contract_view.xml index c0aeed59a..bee8e01cf 100644 --- a/sponsorship_compassion/views/sponsorship_contract_view.xml +++ b/sponsorship_compassion/views/sponsorship_contract_view.xml @@ -45,7 +45,7 @@ diff --git a/survival_sponsorship_compassion/models/__init__.py b/survival_sponsorship_compassion/models/__init__.py index d4676a0b7..05d387b93 100644 --- a/survival_sponsorship_compassion/models/__init__.py +++ b/survival_sponsorship_compassion/models/__init__.py @@ -5,3 +5,4 @@ from . import res_config_settings from . import recurring_contract_line from . import wordpress_configuration +from . import res_partner diff --git a/survival_sponsorship_compassion/models/res_partner.py b/survival_sponsorship_compassion/models/res_partner.py new file mode 100644 index 000000000..7e1b7f6a2 --- /dev/null +++ b/survival_sponsorship_compassion/models/res_partner.py @@ -0,0 +1,37 @@ +from odoo import models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + def _compute_related_contracts(self): + super()._compute_related_contracts() + contract_obj = self.env["recurring.contract"] + for partner in self: + partner.contracts_correspondant += contract_obj.search( + [ + ("correspondent_id", "=", partner.id), + ("type", "=", "CSP"), + ("fully_managed", "=", False), + ], + order="start_date desc", + ) + partner.contracts_paid += contract_obj.search( + [ + ("partner_id", "=", partner.id), + ("type", "=", "CSP"), + ("fully_managed", "=", False), + ], + order="start_date desc", + ) + partner.contracts_fully_managed += contract_obj.search( + [ + ("partner_id", "=", partner.id), + ("type", "=", "CSP"), + ("fully_managed", "=", True), + ], + order="start_date desc", + ) + partner.other_contract_ids = partner.other_contract_ids.filtered( + lambda c: c.type != "CSP" + )