[FIX] mrp: prevent MO creation with the same component as product to produce
Steps to reproduce the bug:
- Create a storable product “P1”
- Add a BOM
- Try to add the product P1 as a component > save > validation error is triggered
> it's not possible to add the same component as the product to produce > correct behavior
- Create a manufacturing order:
- Select the product “P1” as product to produce
- Add the product “P1” as component
- save
Problem:
no validation error is triggered, It's possible to create a MO in which the final product is included in the component > wrong behavior
opw-2796750
closes odoo/odoo#87262
X-original-commit: f38727ee4e7b6596a9da5f3285c7622da0ac6772
Signed-off-by: Arnold Moyaux <arm@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
This commit is contained in:
@@ -749,6 +749,13 @@ class MrpProduction(models.Model):
|
||||
if sum(order.move_byproduct_ids.mapped('cost_share')) > 100:
|
||||
raise ValidationError(_("The total cost share for a manufacturing order's by-products cannot exceed 100."))
|
||||
|
||||
@api.constrains('product_id', 'move_raw_ids')
|
||||
def _check_production_lines(self):
|
||||
for production in self:
|
||||
for move in production.move_raw_ids:
|
||||
if production.product_id == move.product_id:
|
||||
raise ValidationError(_("The component %s should not be the same as the product to produce.") % production.product_id.display_name)
|
||||
|
||||
def write(self, vals):
|
||||
if 'workorder_ids' in self:
|
||||
production_to_replan = self.filtered(lambda p: p.is_planned)
|
||||
|
||||
Reference in New Issue
Block a user