From 357223a7db1bf1c1942c757fe014b8318ea453d2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20-=20Le=20Filament?= <remi@le-filament.com>
Date: Thu, 16 Jun 2022 15:35:17 +0200
Subject: [PATCH] [ADD] destockage fields

---
 models/sale_intervention_stock.py      | 24 +++++++++++++++++++++++-
 views/sale_intervention_stock_view.xml | 23 +++++++++++++++++++----
 2 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/models/sale_intervention_stock.py b/models/sale_intervention_stock.py
index 3ab72a7..4aded96 100644
--- a/models/sale_intervention_stock.py
+++ b/models/sale_intervention_stock.py
@@ -37,6 +37,24 @@ class SaleInterventionStock(models.Model):
     admin_state_id = fields.Many2one(
         related="project_id.admin_state_id", string="Étape du projet", store=True
     )
+    plants_qty = fields.Integer(
+        related="sale_intervention_id.plants_qty",
+        string="Nb de plants",
+        store=True,
+        group_operator="sum",
+    )
+    intervention_length = fields.Float(
+        related="sale_intervention_id.intervention_length",
+        string="Longueur haie",
+        group_operator="sum",
+        store=True,
+    )
+    surface = fields.Integer(
+        related="sale_intervention_id.surface",
+        string="Surface",
+        group_operator="sum",
+        store=True,
+    )
 
     sale_order_id = fields.Many2one(
         related="project_id.sale_order_id",
@@ -54,7 +72,11 @@ class SaleInterventionStock(models.Model):
     name = fields.Char(string="Article", related="product_id.name")
     categ_id = fields.Many2one(related="product_template_id.categ_id", store=True)
     product_uom_qty = fields.Float(
-        string="Quantité", digits="Product Unit of Measure", required=True, default=1.0
+        string="Quantité",
+        digits="Product Unit of Measure",
+        required=True,
+        default=1.0,
+        group_operator="sum",
     )
     price_unit = fields.Float(
         "Prix Unitaire", required=True, digits="Product Price", default=0.0
diff --git a/views/sale_intervention_stock_view.xml b/views/sale_intervention_stock_view.xml
index 6c857cb..2bdb26c 100644
--- a/views/sale_intervention_stock_view.xml
+++ b/views/sale_intervention_stock_view.xml
@@ -20,14 +20,21 @@
                     <field name="saison_id" optional="show" />
                     <field name="partner_id" optional="show" />
                     <field name="user_id" optional="show" />
-                    <field name="admin_state_id" optional="show" />
+                    <field name="admin_state_id" optional="hide" />
                     <field name="sale_intervention_id" optional="hide" />
-                    <field name="intervention_type_id" optional="hide" />
+                    <field name="intervention_type_id" optional="show" />
                     <field name="sale_order_id" optional="hide" />
                     <field name="categ_id" optional="hide" />
-                    <field name="product_uom_qty" sum="Total" />
+                    <field name="product_uom_qty" sum="Total" optional="show" />
                     <field name="price_unit" optional="hide" />
                     <field name="price_total" sum="Total" optional="hide" />
+                    <field name="plants_qty" sum="Nb de Plants" optional="show" />
+                    <field
+                        name="intervention_length"
+                        sum="Longeur haie"
+                        optional="show"
+                    />
+                    <field name="surface" sum="Surface" optional="show" />
                 </tree>
             </field>
         </record>
@@ -78,6 +85,12 @@
                             domain="[]"
                             context="{'group_by':'product_id'}"
                         />
+                        <filter
+                            name="group_by_product_categ_id"
+                            string="Catégorie d'Article"
+                            domain="[]"
+                            context="{'group_by':'categ_id'}"
+                        />
                         <filter
                             name="group_by_intervention"
                             string="Intervention"
@@ -122,7 +135,9 @@
             <field name="res_model">sale.intervention.stock</field>
             <field name="view_mode">tree,pivot,graph</field>
             <field name="search_view_id" ref="sale_intervention_stock_search" />
-            <field name="context">{"search_default_group_by_partner": True}</field>
+            <field
+                name="context"
+            >{"search_default_group_by_partner": True, "search_default_group_by_project": True}</field>
             <field name="help" type="html">
               <p class="o_view_nocontent_empty_folder">
                 Aucun article à déstocker trouvé. Créez un nouveau projet depuis un devis
-- 
GitLab