From 3cb03789dccbe9a0ae6b9b93eaa81023e3b85a4b Mon Sep 17 00:00:00 2001
From: jordan <jordan@le-filament.com>
Date: Wed, 2 Feb 2022 16:27:36 +0100
Subject: [PATCH] [update] add invoice_adhesion_id in res_partner model +
 update scop_valid_cg to use it

---
 models/res_partner.py | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/models/res_partner.py b/models/res_partner.py
index aedbe0c..ebcda5c 100644
--- a/models/res_partner.py
+++ b/models/res_partner.py
@@ -58,6 +58,9 @@ class ScopPartner(models.Model):
         string="Année dossier adhésion",
         related='lm_adhesion_id.year'
     )
+    invoice_adhesion_id = fields.Many2one(
+        comodel_name='account.invoice',
+        string='Facture d\'adhésion')
 
     # Dossier UE
     file_fse_open = fields.Boolean("Dossier FSE ouvert Oui/Non")
@@ -490,13 +493,14 @@ class ScopPartner(models.Model):
         - create period adhesion CG
         - create period adhesion Fédé if needed
         - create invoice adhesion
-        - send email to coop (letter and invoice adhesion on extranet)
+        - set liasse_fiscale_adhesion as qualified
         """
-        # Important to call get_lm_adhesion() first so we can use specific
-        # adhesion process to create lm if needed instead of process define
-        # in cgscop_liste_ministere module
-        lm_adhesion = self.get_lm_adhesion()
-        super(ScopPartner, self).scop_valid_cg()
+
+        if not self.lm_adhesion_id:
+            raise ValidationError(
+                'Cette coopérative n\'a pas de dossier d\'inscription')
+
+        res = super(ScopPartner, self).scop_valid_cg()
 
         # Create period adhésions with num adherent
         num_adherent = self.create_num_adherent()
@@ -505,8 +509,15 @@ class ScopPartner(models.Model):
         # TODO : check pour fede CAE si coop is CAE ?
 
         # Create invoice adhésion
-        invoice = self.create_invoice_adhesion(lm_adhesion)
-        return invoice
+        invoice = self.create_invoice_adhesion(self.lm_adhesion_id)
+        self.invoice_adhesion_id = invoice
+
+        # set liasse_fiscale_adhesion as qualified
+        self.lm_adhesion_id.scop_liasse_fiscale_id.write({
+            'is_qualified': True
+        })
+
+        return res
 
 
 class ResPartnerPrescriberCanal(models.Model):
-- 
GitLab