From 78e5d3d621724dcd123628f1442cd67edd5a8c19 Mon Sep 17 00:00:00 2001
From: benjamin <benjamin@le-filament.com>
Date: Thu, 6 Jun 2024 10:46:22 +0200
Subject: [PATCH] [UPD] add refund_contribution_type & button to refresh
 contribution on liasse

---
 models/account_move.py                     |  8 ++++++
 models/scop_bordereau_cg.py                | 14 +++++-----
 models/scop_liasse_fiscale.py              | 31 +++++++++++++++++-----
 views/account_move.xml                     |  4 +++
 views/scop_liasse_fiscale.xml              |  8 ++++++
 wizard/scop_bordereau_refund_wizard.py     |  8 ++++++
 wizard/scop_bordereau_refund_wizard.xml    |  1 +
 wizard/scop_cotisation_cg_regul.py         | 10 +++++++
 wizard/scop_cotisation_cg_regul_wizard.xml |  1 +
 9 files changed, 70 insertions(+), 15 deletions(-)

diff --git a/models/account_move.py b/models/account_move.py
index 72c850a..88d554c 100644
--- a/models/account_move.py
+++ b/models/account_move.py
@@ -30,6 +30,14 @@ class ScopAccountMove(models.Model):
         currency_field="company_currency_id",
         compute="_compute_amount_called",
     )
+    refund_contribution_type = fields.Selection(
+        [
+            ("correction", "Correction"),
+            ("exemption", "Exonération"),
+            ("cancel", "Annulation"),
+        ],
+        string="Type d'avoir de cotisation",
+    )
 
     # ------------------------------------------------------
     # Compute fields
diff --git a/models/scop_bordereau_cg.py b/models/scop_bordereau_cg.py
index 6e23718..0962467 100644
--- a/models/scop_bordereau_cg.py
+++ b/models/scop_bordereau_cg.py
@@ -835,16 +835,14 @@ class Bordereau(models.Model):
                 "cgscop_partner.cotiz_fede_indus"
             ).id
             # Calcul de la cotisation de la fédé de l'industrie
-            if partner.staff_last == 0:
-                # Forfait de 4 € si pas de salariés
+            if liasse:
+                amount_fede_indus = base_cotiz.round_to_closest_multiple(
+                    liasse.contribution_indus, 4
+                )
+            elif partner.staff_last == 0:
                 amount_fede_indus = 4
             else:
-                if liasse:
-                    amount_fede_indus = base_cotiz.round_to_closest_multiple(
-                        liasse.contribution_indus, 4
-                    )
-                else:
-                    amount_fede_indus = 120
+                amount_fede_indus = 120
 
             # Création des factures associées
             self.create_contribution(
diff --git a/models/scop_liasse_fiscale.py b/models/scop_liasse_fiscale.py
index ccc9780..b9c821c 100644
--- a/models/scop_liasse_fiscale.py
+++ b/models/scop_liasse_fiscale.py
@@ -311,14 +311,18 @@ class ScopLiasseFiscale(models.Model):
         """
         for liasse in self:
             if liasse.is_federation_indus:
-                va = liasse.get_va()
-                contrib = round(va * 0.0003, 2)
-                if contrib < 120:
-                    liasse.contribution_indus = 120
-                elif contrib >= 1000:
-                    liasse.contribution_indus = 1000
+                if liasse.partner_id.staff_last == 0:
+                    # Forfait de 4 € si pas de salariés
+                    liasse.contribution_indus = 4
                 else:
-                    liasse.contribution_indus = contrib
+                    va = liasse.get_va()
+                    contrib = round(va * 0.0003, 2)
+                    if contrib < 120:
+                        liasse.contribution_indus = 120
+                    elif contrib >= 1000:
+                        liasse.contribution_indus = 1000
+                    else:
+                        liasse.contribution_indus = contrib
 
     @api.depends("contribution_cg")
     def _compute_contribution_idf(self):
@@ -341,6 +345,19 @@ class ScopLiasseFiscale(models.Model):
                 else:
                     liasse.contribution_idf = contribution_idf
 
+    # ------------------------------------------------------
+    # Action button
+    # ------------------------------------------------------
+    def action_recompute_contribution(self):
+        for liasse in self:
+            liasse._compute_contribution_cg()
+            liasse._compute_contribution_hdf()
+            liasse._compute_contribution_med()
+            liasse._compute_contribution_com()
+            liasse._compute_contribution_cae()
+            liasse._compute_contribution_indus()
+            liasse._compute_contribution_idf()
+
     # ------------------------------------------------------
     # Business Function
     # ------------------------------------------------------
diff --git a/views/account_move.xml b/views/account_move.xml
index a747249..a92faa1 100644
--- a/views/account_move.xml
+++ b/views/account_move.xml
@@ -42,6 +42,10 @@
                     <group>
                         <field name="liasse_fiscale_id" readonly="1" />
                         <field name="bordereau_id" readonly="1" />
+                        <field
+                            name="refund_contribution_type"
+                            attrs="{'invisible': [('move_type', '!=', 'out_refund')]}"
+                        />
                     </group>
                     <group>
                         <field name="amount_cg_calculated" readonly="1" />
diff --git a/views/scop_liasse_fiscale.xml b/views/scop_liasse_fiscale.xml
index 46959c2..80000bd 100644
--- a/views/scop_liasse_fiscale.xml
+++ b/views/scop_liasse_fiscale.xml
@@ -19,7 +19,15 @@
                         <strong><u>Cotisations théoriques</u></strong><br />
                         Cette section donne les montants théoriques des diverses cotisations en fonction des valeurs de la liasse fiscale.
                     </div>
+                    <button
+                        name="action_recompute_contribution"
+                        type="object"
+                        string="Recalculer les cotisations"
+                        class="btn-outline-primary"
+                        groups="cgscop_partner.group_cg_administrative"
+                    />
                     <group name="simulation">
+
                         <group>
                             <field
                                 name="contribution_base_type"
diff --git a/wizard/scop_bordereau_refund_wizard.py b/wizard/scop_bordereau_refund_wizard.py
index 93c7f3f..fbd29ac 100644
--- a/wizard/scop_bordereau_refund_wizard.py
+++ b/wizard/scop_bordereau_refund_wizard.py
@@ -32,6 +32,14 @@ class ScopBordereauRefundWizard(models.TransientModel):
         comodel_name="scop.bordereau.refund.wizard.quarter",
         string="Trimestres",
     )
+    refund_contribution_type = fields.Selection(
+        [
+            ("correction", "Correction"),
+            ("exemption", "Exonération"),
+            ("cancel", "Annulation"),
+        ],
+        string="Type d'avoir de cotisation",
+    )
 
     # ------------------------------------------------------
     # Constrains
diff --git a/wizard/scop_bordereau_refund_wizard.xml b/wizard/scop_bordereau_refund_wizard.xml
index e20305b..70c4ae9 100644
--- a/wizard/scop_bordereau_refund_wizard.xml
+++ b/wizard/scop_bordereau_refund_wizard.xml
@@ -14,6 +14,7 @@
                             <field name="cotiz_reminder" />
                             <hr />
                             <field name="type_cotiz" />
+                            <field name="refund_contribution_type" required="True" />
                             <field name="date_refund" />
                             <separator />
                             <field name="amount_refund" />
diff --git a/wizard/scop_cotisation_cg_regul.py b/wizard/scop_cotisation_cg_regul.py
index 3b00820..f5df5b4 100644
--- a/wizard/scop_cotisation_cg_regul.py
+++ b/wizard/scop_cotisation_cg_regul.py
@@ -70,6 +70,16 @@ class ScopCotisationRegul(models.TransientModel):
     amount_fede_indus = fields.Float(related="liasse_fiscale_new_id.contribution_indus")
 
     is_payment = fields.Boolean("Paiements liés")
+    refund_contribution_type = fields.Selection(
+        [
+            ("correction", "Correction"),
+            ("exemption", "Exonération"),
+            ("cancel", "Annulation"),
+        ],
+        string="Type d'avoir de cotisation",
+        default="correction",
+        required=True
+    )
 
     # ------------------------------------------------------
     # Constrains
diff --git a/wizard/scop_cotisation_cg_regul_wizard.xml b/wizard/scop_cotisation_cg_regul_wizard.xml
index 66ad93c..2bfb1de 100644
--- a/wizard/scop_cotisation_cg_regul_wizard.xml
+++ b/wizard/scop_cotisation_cg_regul_wizard.xml
@@ -58,6 +58,7 @@
                             <div class="col-6">
                                 <group string="Nouveaux calculs">
                                     <field name="date_regul" required="1" />
+                                    <field name="refund_contribution_type" required="1" />
                                     <separator />
                                     <field
                                         name="liasse_fiscale_new_id"
-- 
GitLab