[FIX] mrp_production_serial_matrix: use qty reserved for selected MO.

User should be able to use the matrix when the MO is reserved and
select the lots that are available plus the ones reserved
specifically for the MO.
This commit is contained in:
Lois Rilo
2021-10-04 15:12:54 +02:00
committed by Ruchir Shukla
parent 13cb852397
commit 61a5b14277
2 changed files with 17 additions and 5 deletions

View File

@@ -71,11 +71,8 @@ class MrpProductionSerialMatrix(models.TransientModel):
if not ll.component_lot_id:
continue
lot_consumption.setdefault(ll.component_lot_id, 0)
available_quantity = self.env["stock.quant"]._get_available_quantity(
ll.component_id,
ll.production_id.location_src_id,
lot_id=ll.component_lot_id,
)
free_qty, reserved_qty = ll._get_available_and_reserved_quantities()
available_quantity = free_qty + reserved_qty
if (
available_quantity - lot_consumption[ll.component_lot_id]
< ll.lot_qty

View File

@@ -36,3 +36,18 @@ class MrpProductionSerialMatrix(models.TransientModel):
]
)
rec.allowed_component_lot_ids = available_quants.mapped("lot_id")
def _get_available_and_reserved_quantities(self):
self.ensure_one()
available_quantity = self.env["stock.quant"]._get_available_quantity(
self.component_id,
self.production_id.location_src_id,
lot_id=self.component_lot_id,
)
move_lines = self.production_id.move_raw_ids.mapped("move_line_ids").filtered(
lambda l: l.product_id == self.component_id
and l.lot_id == self.component_lot_id
and l.state not in ["done", "cancel"]
)
specifically_reserved_quantity = sum(move_lines.mapped("product_uom_qty"))
return available_quantity, specifically_reserved_quantity