From a684912df7932e1e3e4141b3037ee9bfa79b7cd7 Mon Sep 17 00:00:00 2001
From: benjamin <benjamin@le-filament.com>
Date: Thu, 24 Aug 2023 14:38:37 +0200
Subject: [PATCH] [update] add registration wizard & cancel membership process

---
 __manifest__.py                     |  1 +
 models/res_partner.py               |  4 +++
 views/res_partner.xml               | 13 ++++++++++
 wizard/__init__.py                  |  1 +
 wizard/scop_registration_wizard.py  | 29 +++++++++++++++++++++
 wizard/scop_registration_wizard.xml | 39 +++++++++++++++++++++++++++++
 6 files changed, 87 insertions(+)
 create mode 100644 wizard/scop_registration_wizard.py
 create mode 100644 wizard/scop_registration_wizard.xml

diff --git a/__manifest__.py b/__manifest__.py
index 4fb1fe5..7e66065 100644
--- a/__manifest__.py
+++ b/__manifest__.py
@@ -26,6 +26,7 @@
         "wizard/scop_membership_liasse_wizard.xml",
         "wizard/scop_membership_staff_wizard.xml",
         "wizard/scop_membership_submit_wizard.xml",
+        "wizard/scop_registration_wizard.xml",
         # views
         "views/assets.xml",
         "views/res_config_settings.xml",
diff --git a/models/res_partner.py b/models/res_partner.py
index 1f87989..92f2468 100644
--- a/models/res_partner.py
+++ b/models/res_partner.py
@@ -161,6 +161,10 @@ class ScopPartner(models.Model):
             "target": "new",
         }
 
+    def scop_cancel_membership(self):
+        for partner in self:
+            partner.update({"member_status": "not_member"})
+
     # ------------------------------------------------------
     # Business methods
     # ------------------------------------------------------
diff --git a/views/res_partner.xml b/views/res_partner.xml
index 6464898..5bd7b3d 100644
--- a/views/res_partner.xml
+++ b/views/res_partner.xml
@@ -57,6 +57,19 @@
                         attrs="{'invisible': [('membership_status', '!=', 'soumis_cg')]}"
                         groups="cgscop_partner.group_cg_administrator"
                     />
+                    <button
+                        string="Projet d'adhésion abandonné"
+                        type="object"
+                        name="scop_cancel_membership"
+                        attrs="{'invisible': [('membership_status', '!=', 'adhesion')]}"
+                        confirm="Valider l'abandon du projet d'adhésion ?"
+                    />
+                    <button
+                        string="Immatriculation"
+                        type="object"
+                        name="scop_cancel_membership"
+                        attrs="{'invisible': [('is_registration_in_progress', '!=', True)]}"
+                    />
                 </xpath>
 
                 <!-- Alert pour les données du process d'adhésion -->
diff --git a/wizard/__init__.py b/wizard/__init__.py
index fb836cd..05afc06 100644
--- a/wizard/__init__.py
+++ b/wizard/__init__.py
@@ -5,3 +5,4 @@ from . import scop_compulsory_fields_suivi_wizard
 from . import scop_membership_liasse_wizard
 from . import scop_membership_staff_wizard
 from . import scop_membership_submit_wizard
+from . import scop_registration_wizard
diff --git a/wizard/scop_registration_wizard.py b/wizard/scop_registration_wizard.py
new file mode 100644
index 0000000..5e2d337
--- /dev/null
+++ b/wizard/scop_registration_wizard.py
@@ -0,0 +1,29 @@
+# © 2021 Le Filament (<http://www.le-filament.com>)
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+from odoo import _, fields, models
+from odoo.exceptions import UserError
+
+
+class ScopCompulsoryFieldsSuiviWizard(models.TransientModel):
+    _name = "scop.compulsory.fields.suivi.wizard"
+    _description = "Wizard: Confirmer les champs obligatoires pour passage en suivi "
+
+    partner_id = fields.Many2one(
+        comodel_name="res.partner", string="Coop", required=True
+    )
+    naf_id = fields.Many2one(related="partner_id.naf_id", readonly=False)
+    registration_date = fields.Date(
+        related="partner_id.registration_date", readonly=False
+    )
+    siret = fields.Char(related="partner_id.siret", readonly=False)
+
+    # ------------------------------------------------------
+    # Actions / Buttons
+    # ------------------------------------------------------
+    def confirm_registration(self):
+        """
+        Passe la coop en statut "4_suivi"
+        """
+        self.partner_id.sudo()._create_period(self.partner_id)
+        return {"type": "ir.actions.act_window_close"}
diff --git a/wizard/scop_registration_wizard.xml b/wizard/scop_registration_wizard.xml
new file mode 100644
index 0000000..23ea516
--- /dev/null
+++ b/wizard/scop_registration_wizard.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" ?>
+<!-- Copyright 2021 Le Filament
+     License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
+<odoo>
+    <data>
+
+        <record
+            model="ir.ui.view"
+            id="scop_registration_wizard_form"
+        >
+            <field name="name">scop.registration.wizard.form</field>
+            <field name="model">scop.registration.wizard</field>
+            <field name="arch" type="xml">
+                <form string="Immatriculation">
+                    <group>
+                        <field
+                            name="partner_id"
+                            readonly="1"
+                            options="{'no_create': True, 'no_edit': True}"
+                        />
+                        <field name="registration_date" required="1" />
+                        <field name="siret" required="1" />
+                        <field name="naf_id" required="1" />
+                    </group>
+                    <footer>
+                        <button
+                            name="confirm_registration"
+                            type="object"
+                            string="Valider"
+                            class="oe_highlight"
+                        />
+                        <button special="cancel" string="Annuler" />
+                    </footer>
+                </form>
+            </field>
+        </record>
+
+    </data>
+</odoo>
-- 
GitLab