diff --git a/models/sale_intervention.py b/models/sale_intervention.py index b899ca3a346e88aad395a5dc637bc47e14f0f65e..7c5c564e65300ab44cd670bc50a6d34f0f9a344b 100644 --- a/models/sale_intervention.py +++ b/models/sale_intervention.py @@ -415,6 +415,10 @@ class SaleIntervention(models.Model): related="project_id.sale_order_id", string="Devis/Commande", ) + partner_id = fields.Many2one( + related="project_id.partner_id", + string="Client", + ) state = fields.Selection(related="sale_order_id.state", store=True) sale_intervention_stock_ids = fields.One2many( comodel_name="sale.intervention.stock", @@ -495,21 +499,27 @@ class SaleIntervention(models.Model): # ------------------------------------------------------ # Onchange / Constraints # ------------------------------------------------------ - @api.onchange("plant_qty", "intervention_length", "mulch_id") + @api.onchange( + "plant_qty", "intervention_length", "plant_interval", "mulch_id") def _onchange_mulch_id(self): self.mulch_has_staples = False if self.mulch_unit == self.env.ref("uom.product_uom_meter"): - self.mulch_qty = self.intervention_length + self.mulch_qty = ( + math.ceil(self.intervention_length / self.plant_interval) + 1 + ) elif self.mulch_unit == self.env.ref("uom.product_uom_unit"): self.mulch_qty = self.plant_qty else: self.mulch_qty = 0.0 - @api.onchange("plant_qty", "intervention_length", "mulch2_id") + @api.onchange( + "plant_qty", "intervention_length", "plant_interval", "mulch2_id") def _onchange_mulch2_id(self): self.mulch2_has_staples = False if self.mulch2_unit == self.env.ref("uom.product_uom_meter"): - self.mulch2_qty = self.intervention_length + self.mulch2_qty = ( + math.ceil(self.intervention_length / self.plant_interval) + 1 + ) elif self.mulch2_unit == self.env.ref("uom.product_uom_unit"): self.mulch2_qty = self.plant_qty else: @@ -548,12 +558,14 @@ class SaleIntervention(models.Model): % rec.plant_interval ) - @api.constrains("plant_qty", "plants_qty") + @api.constrains( + "plant_qty", "plants_qty", "intervention_length", "plant_interval") def _check_plant_qty(self): for rec in self: if ( rec.plant_qty != rec.plants_qty and rec.sequence_type == "list" + and rec.plant_list_ids and rec.intervention_uom_name == "Unité(s)" ): raise UserError( @@ -564,6 +576,23 @@ class SaleIntervention(models.Model): ) % (rec.plant_qty, rec.plants_qty) ) + if rec.intervention_uom_name == "m" and rec.plant_interval > 0: + lg_intervention = ( + math.ceil(rec.intervention_length / rec.plant_interval) + 1 + ) + if ( + lg_intervention != rec.plants_qty + and rec.sequence_type == "list" + and rec.plant_list_ids + ): + 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." + ) + % (lg_intervention, rec.plants_qty) + ) @api.depends( "project_subvention_id", diff --git a/views/sale_intervention_view.xml b/views/sale_intervention_view.xml index b48b50ef7f5faf2d5bb8403e097f961b8a0de437..125d883a1dbe6997429fb896d828d8b8eb44cbb5 100644 --- a/views/sale_intervention_view.xml +++ b/views/sale_intervention_view.xml @@ -14,6 +14,7 @@ <field name="state" invisible="1" /> <field name="project_id" invisible="True" /> <field name="sale_order_id" invisible="True" /> + <field name="partner_id"/> <field name="intervention_type_id" options="{'no_open': True, 'no_create': True}" @@ -80,121 +81,84 @@ <group string="Fournitures"> <group name="collarette"> - <group> - <field name="is_collarette" /> - </group> - <group> - <field - name="collarette_qty" - attrs="{'invisible': [('is_collarette', '!=', True)]}" - /> - </group> + <field name="is_collarette" /> + <field + name="collarette_qty" + attrs="{'invisible': [('is_collarette', '!=', True)]}" + /> </group> <group name="marker"> - <group> - <field - name="marker_id" - options="{'no_open': True, 'no_create': True}" - /> - </group> - <group - attrs="{'invisible': [('marker_id', '=', False)]}" - > - <field name="marker_qty" /> - </group> + <field + name="marker_id" + options="{'no_open': True, 'no_create': True}" + /> + <field name="marker_qty" attrs="{'invisible': [('marker_id', '=', False)]}"/> </group> </group> <group name="mulch"> <group> - <group> - <field - name="mulch_id" - options="{'no_open': True, 'no_create': True}" - /> - </group> - <group + <field + name="mulch_id" + options="{'no_open': True, 'no_create': True}" + /> + <field name="mulch_qty" attrs="{'invisible': [('mulch_id', '=', False)]}"/> + <field name="mulch_unit" class="oe_inline" + attrs="{'invisible': [('mulch_id', '=', False)]}"/> + <field + name="mulch_has_staples" + string="Avec agrafes" attrs="{'invisible': [('mulch_id', '=', False)]}" - > - <field name="mulch_qty" /> - <field name="mulch_unit" class="oe_inline" /> - <field - name="mulch_has_staples" - string="Avec agrafes" - /> - </group> + /> </group> <group name="mulch2" attrs="{'invisible': [('mulch_id', '=', False)]}" > - <group> - <field - name="mulch2_id" - options="{'no_open': True, 'no_create': True}" - /> - </group> - <group + <field + name="mulch2_id" + options="{'no_open': True, 'no_create': True}" + /> + <field name="mulch2_qty" attrs="{'invisible': [('mulch2_id', '=', False)]}"/> + <field name="mulch2_unit" class="oe_inline" + attrs="{'invisible': [('mulch2_id', '=', False)]}"/> + <field + name="mulch2_has_staples" + string="Avec agrafes" attrs="{'invisible': [('mulch2_id', '=', False)]}" - > - <field name="mulch2_qty" /> - <field name="mulch2_unit" class="oe_inline" /> - <field - name="mulch2_has_staples" - string="Avec agrafes" - /> - </group> + /> </group> </group> <group name="high_protection"> <group> - <group> - <field - name="high_protection_id" - options="{'no_open': True, 'no_create': True}" - /> - </group> - <group - attrs="{'invisible': [('high_protection_id', '=', False)]}" - > - <field name="high_protection_qty" /> - </group> + <field + name="high_protection_id" + options="{'no_open': True, 'no_create': True}" + /> + <field name="high_protection_qty" + attrs="{'invisible': [('high_protection_id', '=', False)]}"/> </group> <group name="stake"> - <group> - <field - name="stake_id" - options="{'no_open': True, 'no_create': True}" - /> - </group> - <group - attrs="{'invisible': [('stake_id', '=', False)]}" - > - <field name="stake_qty" /> - </group> + <field + name="stake_id" + options="{'no_open': True, 'no_create': True}" + /> + <field name="stake_qty" attrs="{'invisible': [('stake_id', '=', False)]}"/> </group> <group name="low_protection"> - <group> - <field - name="low_protection_id" - options="{'no_open': True, 'no_create': True}" - /> - </group> - <group - attrs="{'invisible': [('low_protection_id', '=', False)]}" - > - <field name="low_protection_qty" /> - </group> + <field + name="low_protection_id" + options="{'no_open': True, 'no_create': True}" + /> + <field name="low_protection_qty" + attrs="{'invisible': [('low_protection_id', '=', False)]}"/> </group> <group name="bamboo"> - <group - attrs="{'invisible': [('low_protection_id', '=', False)]}" - > - <field name="bamboo_qty" /> - </group> + <field name="bamboo_qty" attrs="{'invisible': [('low_protection_id', '=', False)]}"/> </group> </group> <group string="Composition"> <field name="sequence_type" widget="radio" /> + </group> <field string="Construction en liste" name="plant_list_ids" @@ -239,7 +203,6 @@ <field name="is_local" /> </tree> </field> - </group> <group name="computed_fields" string="Champs calculés"