From 728041e693f37a30eeb8b1fe84253726c3a88954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20-=20Le=20Filament?= <remi@le-filament.com> Date: Tue, 16 Jul 2024 12:39:07 +0200 Subject: [PATCH] [UPD] recalculate bamboos as well and update category accessory data --- data/product_category.xml | 5 ++++- models/sale_intervention.py | 14 +++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/data/product_category.xml b/data/product_category.xml index f0a8f08..a3bd03f 100644 --- a/data/product_category.xml +++ b/data/product_category.xml @@ -10,7 +10,8 @@ name="parent_id" ref="ap_sale_project.product_category_plantation_supply" /> - <field name="name">Paillage</field> + <field name="name">Paillage</field> + <field name="accessory_label">Agrafes</field> </record> <record id="product_category_stake" model="product.category"> <field @@ -25,6 +26,7 @@ ref="ap_sale_project.product_category_plantation_supply" /> <field name="name">Protections Hautes</field> + <field name="accessory_label">Piquets</field> </record> <record id="product_category_protection_low" model="product.category"> <field @@ -32,6 +34,7 @@ ref="ap_sale_project.product_category_plantation_supply" /> <field name="name">Protections Basses</field> + <field name="accessory_label">Bambous</field> </record> <record id="product_category_marker" model="product.category"> <field diff --git a/models/sale_intervention.py b/models/sale_intervention.py index ecafe2f..61b102e 100644 --- a/models/sale_intervention.py +++ b/models/sale_intervention.py @@ -580,7 +580,12 @@ class SaleIntervention(models.Model): @api.onchange("low_protection_qty") def _onchange_low_protection_qty(self): - self.bamboo_qty = self.low_protection_qty * 2 + if self.low_protection_id.nb_accesories: + stake_multiplier = self.low_protection_id.nb_accesories + else: + stake_multiplier = 2 + + self.bamboo_qty = stake_multiplier * self.low_protection_qty @api.constrains("plant_interval") def _check_plant_interval(self): @@ -607,8 +612,9 @@ class SaleIntervention(models.Model): raise UserError( _( "La quantité de plants renseignée '%d' est différente de" - "la quantité de plants calculée '%d'.\n " - "Les quantités doivent être identiques, vérifier votre compositon." + " la quantité de plants calculée '%d'.\n " + "Les quantités doivent être identiques," + " vérifier votre compositon." ) % (rec.plant_qty, rec.plants_qty) ) @@ -676,6 +682,7 @@ class SaleIntervention(models.Model): ): # We retrieve pricelist from subvention where # intervention_type_id = our type of intervention + # ruff: noqa: B023 pricelist = rec.project_subvention_id.product_pricelist_ids.filtered( lambda i: i.intervention_type_id == forfait )[0] @@ -701,6 +708,7 @@ class SaleIntervention(models.Model): # of all interventions of the same type # Get all interventions of same type in the same project + # ruff: noqa: B023 interventions = self.project_id.intervention_ids.filtered( lambda r: r.intervention_type_id == rec.intervention_type_id ) -- GitLab