diff --git a/models/sale_intervention.py b/models/sale_intervention.py index 7c5c564e65300ab44cd670bc50a6d34f0f9a344b..8db4184c0fe5f9ac42f793b491e9b760d4b945af 100644 --- a/models/sale_intervention.py +++ b/models/sale_intervention.py @@ -499,43 +499,38 @@ class SaleIntervention(models.Model): # ------------------------------------------------------ # Onchange / Constraints # ------------------------------------------------------ - @api.onchange( - "plant_qty", "intervention_length", "plant_interval", "mulch_id") + @api.onchange("intervention_length", "plant_interval") + def _onchange_length(self): + if self.intervention_uom_name == "m" and self.plant_interval > 0: + plant_qty = math.ceil(self.intervention_length / self.plant_interval) + 1 + self.plant_qty = plant_qty + self.collarette_qty = plant_qty + + @api.onchange("plant_qty") + def _onchange_plant_qty(self): + if self.intervention_uom_name == "Unité(s)": + self.collarette_qty = self.plant_qty + + @api.onchange("plant_qty", "intervention_length", "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 = ( - math.ceil(self.intervention_length / self.plant_interval) + 1 - ) + self.mulch_qty = self.intervention_length 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", "plant_interval", "mulch2_id") + @api.onchange("plant_qty", "intervention_length", "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 = ( - math.ceil(self.intervention_length / self.plant_interval) + 1 - ) + self.mulch2_qty = self.intervention_length elif self.mulch2_unit == self.env.ref("uom.product_uom_unit"): self.mulch2_qty = self.plant_qty else: self.mulch2_qty = 0.0 - @api.onchange("plant_qty", "intervention_length", "plant_interval") - def _onchange_plant_qty(self): - if self.intervention_uom_name == "m" and self.plant_interval > 0: - self.collarette_qty = ( - math.ceil(self.intervention_length / self.plant_interval) + 1 - ) - elif self.intervention_uom_name == "Unité(s)": - self.collarette_qty = self.plant_qty - else: - self.collarette_qty = 0 - @api.onchange("high_protection_qty") def _onchange_high_protection_qty(self): self.stake_qty = self.high_protection_qty @@ -558,15 +553,13 @@ class SaleIntervention(models.Model): % rec.plant_interval ) - @api.constrains( - "plant_qty", "plants_qty", "intervention_length", "plant_interval") + @api.constrains("plant_qty", "plants_qty") 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( _( @@ -576,23 +569,6 @@ 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", @@ -950,7 +926,6 @@ class SaleIntervention(models.Model): for rec in res: seq = str(rec.project_id.intervention_counter).zfill(3) rec.name = rec.project_id.name + "-" + seq - rec._create_sale_intervention_stock_lines() return res def write(self, values): diff --git a/views/sale_intervention_view.xml b/views/sale_intervention_view.xml index 125d883a1dbe6997429fb896d828d8b8eb44cbb5..c90e8ba3be66be0591ec8271eb3f6266d1211ff4 100644 --- a/views/sale_intervention_view.xml +++ b/views/sale_intervention_view.xml @@ -14,7 +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="partner_id" /> <field name="intervention_type_id" options="{'no_open': True, 'no_create': True}" @@ -92,7 +92,10 @@ name="marker_id" options="{'no_open': True, 'no_create': True}" /> - <field name="marker_qty" attrs="{'invisible': [('marker_id', '=', False)]}"/> + <field + name="marker_qty" + attrs="{'invisible': [('marker_id', '=', False)]}" + /> </group> </group> <group name="mulch"> @@ -101,9 +104,15 @@ 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_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" @@ -118,9 +127,15 @@ 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_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" @@ -134,72 +149,82 @@ name="high_protection_id" options="{'no_open': True, 'no_create': True}" /> - <field name="high_protection_qty" - attrs="{'invisible': [('high_protection_id', '=', False)]}"/> + <field + name="high_protection_qty" + attrs="{'invisible': [('high_protection_id', '=', False)]}" + /> </group> <group name="stake"> <field name="stake_id" options="{'no_open': True, 'no_create': True}" /> - <field name="stake_qty" attrs="{'invisible': [('stake_id', '=', False)]}"/> + <field + name="stake_qty" + attrs="{'invisible': [('stake_id', '=', False)]}" + /> </group> <group name="low_protection"> <field name="low_protection_id" options="{'no_open': True, 'no_create': True}" /> - <field name="low_protection_qty" - attrs="{'invisible': [('low_protection_id', '=', False)]}"/> + <field + name="low_protection_qty" + attrs="{'invisible': [('low_protection_id', '=', False)]}" + /> </group> <group name="bamboo"> - <field name="bamboo_qty" attrs="{'invisible': [('low_protection_id', '=', False)]}"/> + <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" - mode="tree" - context="{'default_intervention_id': active_id, 'default_is_list': True}" - attrs="{'invisible': [('sequence_type', '!=', 'list')]}" - > + string="Construction en liste" + name="plant_list_ids" + mode="tree" + context="{'default_intervention_id': active_id, 'default_is_list': True}" + attrs="{'invisible': [('sequence_type', '!=', 'list')]}" + > <tree editable="inline" string="Construction en liste"> <field name="sequence" widget="handle" /> <field name="intervention_id" invisible="True" /> <field name="is_list" invisible="True" /> <field - name="product_id" - options="{'no_open': True, 'no_create': True}" - /> + name="product_id" + options="{'no_open': True, 'no_create': True}" + /> <field name="qty" /> <field name="is_local" /> </tree> </field> <field - name="plant_sequence_ids" - mode="tree" + name="plant_sequence_ids" + mode="tree" + string="Construction en séquence" + context="{'default_intervention_id': active_id, 'default_is_list': False}" + attrs="{'invisible': [('sequence_type', '!=', 'sequence')]}" + > + <tree + editable="inline" string="Construction en séquence" - context="{'default_intervention_id': active_id, 'default_is_list': False}" - attrs="{'invisible': [('sequence_type', '!=', 'sequence')]}" > - <tree - editable="inline" - string="Construction en séquence" - > <field name="is_list" invisible="True" /> <field name="sequence" widget="handle" /> <field name="intervention_id" invisible="True" /> <field - name="product_id" - options="{'no_open': True, 'no_create': True}" - /> + name="product_id" + options="{'no_open': True, 'no_create': True}" + /> <field - name="product_alternance_id" - options="{'no_open': True, 'no_create': True}" - /> + name="product_alternance_id" + options="{'no_open': True, 'no_create': True}" + /> <field name="is_local" /> </tree> </field> diff --git a/views/sale_order_view.xml b/views/sale_order_view.xml index a889f5892bfabaea452077cf0802721630eda2d6..3d2e9604e79cbc9b5dbcebba7de0ccd67baf35cd 100644 --- a/views/sale_order_view.xml +++ b/views/sale_order_view.xml @@ -10,10 +10,21 @@ <field name="inherit_id" ref="sale.view_order_form" /> <field name="arch" type="xml"> <button name="action_quotation_send" position="after"> - <button name="action_print_pdf" string="Imprimer" type="object" states="draft" class="btn-primary"/> + <button + name="action_print_pdf" + string="Imprimer" + type="object" + states="draft" + class="btn-primary" + /> </button> <button name="action_confirm" position="after"> - <button name="action_print_pdf" string="Imprimer" type="object" states="sent,sale"/> + <button + name="action_print_pdf" + string="Imprimer" + type="object" + states="sent,sale" + /> </button> <label for="pricelist_id" position="attributes"> <attribute name="invisible">1</attribute>