mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
mrp_p_auto_validate: fix auto_validate flag
Relying on onchange makes this value set only if the BOM is set manually on the Form view, what isn't the case when MO are created by running procurements.
This commit is contained in:
committed by
Sébastien Alix
parent
76be60d17b
commit
bf7e47056a
@@ -13,7 +13,9 @@ class MrpProduction(models.Model):
|
||||
|
||||
auto_validate = fields.Boolean(
|
||||
string="Auto Validate",
|
||||
default=False,
|
||||
compute="_compute_auto_validate",
|
||||
store=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
|
||||
@api.constrains("bom_id", "auto_validate", "product_qty")
|
||||
@@ -39,11 +41,16 @@ class MrpProduction(models.Model):
|
||||
).format(qty=mo.bom_id.product_qty)
|
||||
)
|
||||
|
||||
@api.onchange("bom_id")
|
||||
def _onchange_bom_id(self):
|
||||
res = super()._onchange_bom_id()
|
||||
self.auto_validate = self.bom_id.mo_auto_validation
|
||||
return res
|
||||
@api.depends("bom_id.mo_auto_validation", "state")
|
||||
def _compute_auto_validate(self):
|
||||
for prod in self:
|
||||
if prod.state != "draft":
|
||||
# Avoid recomputing the value once the MO is confirmed.
|
||||
# e.g. if the value changes on the BOM but the MO was already confirmed,
|
||||
# or if the user forces another value while the MO is in draft,
|
||||
# we don't want to change the value after confirmation.
|
||||
continue
|
||||
prod.auto_validate = prod.bom_id.mo_auto_validation
|
||||
|
||||
def _auto_validate_after_picking(self):
|
||||
self.ensure_one()
|
||||
|
||||
Reference in New Issue
Block a user