|
|
for request in self:
if request.product_id.type != "service":
qty_cancelled = sum(
request.mapped("purchase_request_allocation_ids.stock_move_id")
.filtered(lambda sm: sm.state == "cancel")
.mapped("product_qty")
)
else:
qty_cancelled = sum(
request.mapped("purchase_request_allocation_ids.purchase_line_id")
.filtered(lambda sm: sm.state == "cancel")
.mapped("product_qty")
)
# done this way as i cannot track what was received before
# cancelled the purchase order
qty_cancelled -= request.qty_done
if request.product_uom_id:
request.qty_cancelled = (
max(
0,
request.product_id.uom_id._compute_quantity(
qty_cancelled, request.product_uom_id
),
)
if request.purchase_request_allocation_ids
else 0
)
else:
request.qty_cancelled = qty_cancelled
|
|