Merge PR #684 into 14.0

Signed-off-by LoisRForgeFlow
This commit is contained in:
OCA-git-bot
2021-10-05 09:34:14 +00:00
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