diff --git a/addons/sale_mrp/models/sale.py b/addons/sale_mrp/models/sale.py index a5da78cc4a5..927037b9548 100644 --- a/addons/sale_mrp/models/sale.py +++ b/addons/sale_mrp/models/sale.py @@ -56,6 +56,10 @@ class SaleOrderLine(models.Model): for order_line in self: if order_line.qty_delivered_method == 'stock_move': boms = order_line.move_ids.mapped('bom_line_id.bom_id') + dropship = False + if not boms and any([m._is_dropshipped() for m in order_line.move_ids]): + boms = boms._bom_find(product=order_line.product_id, company_id=order_line.company_id.id, bom_type='phantom') + dropship = True # We fetch the BoMs of type kits linked to the order_line, # the we keep only the one related to the finished produst. # This bom shoud be the only one since bom_line_id was written on the moves @@ -63,6 +67,18 @@ class SaleOrderLine(models.Model): (b.product_id == order_line.product_id or (b.product_tmpl_id == order_line.product_id.product_tmpl_id and not b.product_id))) if relevant_bom: + # In case of dropship, we use a 'all or nothing' policy since 'bom_line_id' was + # not written on a move coming from a PO. + # FIXME: if the components of a kit have different suppliers, multiple PO + # are generated. If one PO is confirmed and all the others are in draft, receiving + # the products for this PO will set the qty_delivered. We might need to check the + # state of all PO as well... but sale_mrp doesn't depend on purchase. + if dropship: + if order_line.move_ids and all([m.state == 'done' for m in order_line.move_ids]): + order_line.qty_delivered = order_line.product_uom_qty + else: + order_line.qty_delivered = 0.0 + continue moves = order_line.move_ids.filtered(lambda m: m.state == 'done' and not m.scrapped) filters = { 'incoming_moves': lambda m: m.location_dest_id.usage == 'customer' and (not m.origin_returned_move_id or (m.origin_returned_move_id and m.to_refund)),