Skip to content
Extraits de code Groupes Projets
Valider 1de1fe79 rédigé par Juliana's avatar Juliana
Parcourir les fichiers

[ADD]Add onchange qty

parent 5782ebea
Branches
Étiquettes
Aucune requête de fusion associée trouvée
......@@ -83,9 +83,7 @@ class SaleIntervention(models.Model):
# FOURNITURES
is_collarette = fields.Boolean("Collerettes")
# TODO : add a default_quantity field on product_template and take
# the following from there ?
collarette_qty = fields.Integer("Nombre de collerettes", default=1)
collarette_qty = fields.Integer("Nombre de collerettes")
# Mulch Fields
mulch_id = fields.Many2one(
......@@ -148,7 +146,7 @@ class SaleIntervention(models.Model):
],
ondelete="restrict",
)
stake_qty = fields.Float("Qté Piquets", default=1)
stake_qty = fields.Float("Qté Piquets")
# Low protection
low_protection_id = fields.Many2one(
......@@ -169,7 +167,7 @@ class SaleIntervention(models.Model):
(avec protections entrées au dessus)",
)
bamboo_qty = fields.Integer("Qté bambous", default=2)
bamboo_qty = fields.Integer("Qté bambous")
# Markers (Jalons)
marker_id = fields.Many2one(
......@@ -425,6 +423,49 @@ class SaleIntervention(models.Model):
# ------------------------------------------------------
# Onchange / Constraints
# ------------------------------------------------------
@api.onchange('plant_qty', 'intervention_length', 'mulch_id')
def _onchange_mulch_id(self):
if self.mulch_unit == self.env.ref("uom.product_uom_meter"):
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', 'mulch2_id')
def _onchange_mulch2_id(self):
if self.mulch2_unit == self.env.ref("uom.product_uom_meter"):
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')
def _onchange_plant_qty(self):
self.collarette_qty = self.plant_qty
@api.onchange("high_protection_id")
def _onchange_high_protection_id(self):
if not self.high_protection_id:
self.high_protection_qty = 0.0
@api.onchange("high_protection_qty", "stake_id")
def _onchange_high_protection_qty(self):
if self.stake_id:
self.stake_qty = self.high_protection_qty
else:
self.stake_qty = 0.0
@api.onchange("low_protection_id")
def _onchange_low_protection_id(self):
if not self.low_protection_id:
self.low_protection_qty = 0.0
@api.onchange("low_protection_qty")
def _onchange_low_protection_qty(self):
self.bamboo_qty = self.low_protection_qty * 2
@api.constrains("plant_interval")
def _check_plant_interval(self):
for rec in self:
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter