mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
When defining a single BOM for a product template having multiple product variants, we can have different components where the lot number must be propagated for different product variants. Therefore we need to allow to mark multiple BOM line with propagate_lot_number, and to avoid complicating the check function on the BOM lines, we ensure at the manufacturing order confirmation that only a single component is set to propagate its lot number.
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
# Copyright 2022 Camptocamp SA
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
|
|
|
from odoo import _, api, fields, models
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
class MrpBomLine(models.Model):
|
|
_inherit = "mrp.bom.line"
|
|
|
|
propagate_lot_number = fields.Boolean(
|
|
default=False,
|
|
)
|
|
display_propagate_lot_number = fields.Boolean(
|
|
compute="_compute_display_propagate_lot_number"
|
|
)
|
|
|
|
@api.depends(
|
|
"bom_id.display_lot_number_propagation",
|
|
"bom_id.lot_number_propagation",
|
|
)
|
|
def _compute_display_propagate_lot_number(self):
|
|
for line in self:
|
|
line.display_propagate_lot_number = (
|
|
line.bom_id.display_lot_number_propagation
|
|
and line.bom_id.lot_number_propagation
|
|
)
|
|
|
|
@api.constrains("propagate_lot_number")
|
|
def _check_propagate_lot_number(self):
|
|
"""
|
|
This function should check:
|
|
|
|
- if the bom has lot_number_propagation marked, there is one and
|
|
only one line of this bom with propagate_lot_number marked.
|
|
- the bom line being marked with lot_number_propagation is of the same
|
|
tracking type as the finished product
|
|
"""
|
|
for line in self:
|
|
if not line.bom_id.lot_number_propagation:
|
|
continue
|
|
if line.propagate_lot_number and line.product_id.tracking != "serial":
|
|
raise ValidationError(
|
|
_(
|
|
"Only components tracked by serial number can propagate "
|
|
"its lot/serial number to the finished product."
|
|
)
|
|
)
|