From 5599ff4edd2d121ede45d95b9af48a2f95fd5e8d Mon Sep 17 00:00:00 2001
From: jordan <jordan@le-filament.com>
Date: Mon, 15 Mar 2021 18:06:24 +0100
Subject: [PATCH] [add] wizard to confirm update bordereau

---
 __manifest__.py                               |  1 +
 views/scop_bordereau_cg.xml                   | 13 --------
 wizard/__init__.py                            |  1 +
 wizard/scop_bordereau_update_confirm.py       | 26 ++++++++++++++++
 wizard/scop_bordereau_update_confirm_view.xml | 31 +++++++++++++++++++
 5 files changed, 59 insertions(+), 13 deletions(-)
 create mode 100644 wizard/scop_bordereau_update_confirm.py
 create mode 100644 wizard/scop_bordereau_update_confirm_view.xml

diff --git a/__manifest__.py b/__manifest__.py
index a2b45d0..49e0a1f 100755
--- a/__manifest__.py
+++ b/__manifest__.py
@@ -21,6 +21,7 @@
         "views/scop_bordereau_cg.xml",
         "views/scop_cotisation_cg.xml",
         "wizard/scop_cotisation_cg_wizard.xml",
+        "wizard/scop_bordereau_update_confirm_view.xml",
         "wizard/scop_bordereau_validate_confirm_view.xml",
         "report/report_scop_bordereau.xml",
     ]
diff --git a/views/scop_bordereau_cg.xml b/views/scop_bordereau_cg.xml
index f181f44..769a1d0 100644
--- a/views/scop_bordereau_cg.xml
+++ b/views/scop_bordereau_cg.xml
@@ -4,19 +4,6 @@
 <odoo>
     <data>
 
-        <!-- Ajoute l'action "Mettre à jour les cotisations" dans le menu du modèle -->
-        <record id="action_bordereau_update_cotiz_action" model="ir.actions.server">
-            <field name="name">Mettre à jour les cotisations</field>
-            <field name="type">ir.actions.server</field>
-            <field name="model_id" ref="model_scop_bordereau"/>
-            <field name="binding_model_id" ref="model_scop_bordereau"/>
-            <field name="state">code</field>
-            <field name="code">
-                if records:
-                action = records.update_cotiz_and_lines()
-            </field>
-        </record>
-
         <!-- Form -->
         <record id="scop_bordereau_form_view" model="ir.ui.view">
             <field name="name">scop.bordereau.form</field>
diff --git a/wizard/__init__.py b/wizard/__init__.py
index 9efc537..ed12f46 100644
--- a/wizard/__init__.py
+++ b/wizard/__init__.py
@@ -2,5 +2,6 @@
 # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
 
 from . import account_invoice_refund
+from . import scop_bordereau_update_confirm
 from . import scop_bordereau_validate_confirm
 from . import scop_cotisation_cg_wizard
diff --git a/wizard/scop_bordereau_update_confirm.py b/wizard/scop_bordereau_update_confirm.py
new file mode 100644
index 0000000..0779da1
--- /dev/null
+++ b/wizard/scop_bordereau_update_confirm.py
@@ -0,0 +1,26 @@
+# © 2021 Le Filament (<http://www.le-filament.com>)
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
+
+from odoo import models, api, _
+from odoo.exceptions import UserError
+
+
+class ScopBordereauUpdate(models.TransientModel):
+    """
+    This wizard will update all the selected bordereaux
+    """
+
+    _name = "scop.bordereau.update"
+    _description = "Mettre à jour les bordereaux sélectionnés"
+
+    @api.multi
+    def bordereau_update(self):
+        context = dict(self._context or {})
+        active_ids = context.get('active_ids', []) or []
+
+        for record in self.env['scop.bordereau'].browse(active_ids):
+            if record.state != 'new':
+                raise UserError(_("Impossible de mettre à jour un bordereau "
+                                  "qui n'est pas à l'état de brouillon"))
+            record.update_cotiz_and_lines()
+        return {'type': 'ir.actions.act_window_close'}
diff --git a/wizard/scop_bordereau_update_confirm_view.xml b/wizard/scop_bordereau_update_confirm_view.xml
new file mode 100644
index 0000000..a68680b
--- /dev/null
+++ b/wizard/scop_bordereau_update_confirm_view.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!-- Copyright 2021 Le Filament
+     License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
+
+<odoo>
+    <data>
+
+        <record id="account_invoice_update_view" model="ir.ui.view">
+            <field name="name">scop.bordereau.update.form</field>
+            <field name="model">scop.bordereau.update</field>
+            <field name="arch" type="xml">
+                <form string="Mettre à jour les cotisations">
+                    <p class="oe_grey">
+                        Cette action est susceptible de modifier les montants des cotisations !
+                    </p>
+                    <footer>
+                        <button string="Valider" name="bordereau_update" type="object" default_focus="1" class="btn-primary"/>
+                        <button string="Annuler" class="btn-secondary" special="cancel"/>
+                    </footer>
+                </form>
+            </field>
+        </record>
+
+        <act_window id="action_scop_bordereau_update"
+            multi="True"
+            name="Mettre le(s) cotisation(s) à jour"
+            res_model="scop.bordereau.update" src_model="scop.bordereau"
+            view_mode="form" target="new" view_type="form" />
+
+    </data>
+</odoo>
-- 
GitLab