diff --git a/addons/mrp_subcontracting_dropshipping/tests/test_sale_dropshipping.py b/addons/mrp_subcontracting_dropshipping/tests/test_sale_dropshipping.py index d4062ddd437..dcdf1e7b1c3 100644 --- a/addons/mrp_subcontracting_dropshipping/tests/test_sale_dropshipping.py +++ b/addons/mrp_subcontracting_dropshipping/tests/test_sale_dropshipping.py @@ -250,3 +250,44 @@ class TestSaleDropshippingFlows(TestMrpSubcontractingCommon): sale_order.picking_ids.action_cancel() self.assertEqual(sale_order.order_line.qty_delivered, 0.0) + + def test_sale_kit_with_dropshipped_component(self): + """ + The test checks the delivered quantity of a kit when one of the + components is dropshipped + """ + compo01, compo02, kit = self.env['product.product'].create([{ + 'name': n, + 'type': 'consu', + } for n in ['compo01', 'compo02', 'super kit']]) + + compo02.write({ + 'route_ids': [(6, 0, [self.dropship_route.id])], + 'seller_ids': [(0, 0, {'partner_id': self.supplier.id})], + }) + + self.env['mrp.bom'].create({ + 'product_tmpl_id': kit.product_tmpl_id.id, + 'product_qty': 1, + 'type': 'phantom', + 'bom_line_ids': [ + (0, 0, {'product_id': compo01.id, 'product_qty': 1}), + (0, 0, {'product_id': compo02.id, 'product_qty': 1}), + ], + }) + + sale_order = self.env['sale.order'].create({ + 'partner_id': self.customer.id, + 'picking_policy': 'direct', + 'order_line': [ + (0, 0, {'name': kit.name, 'product_id': kit.id, 'product_uom_qty': 1}), + ], + }) + sale_order.action_confirm() + self.env['purchase.order'].search([], order='id desc', limit=1).button_confirm() + + sale_order.picking_ids.move_ids.quantity_done = 1 + sale_order.picking_ids[0].button_validate() + sale_order.picking_ids[1].button_validate() + + self.assertEqual(sale_order.order_line.qty_delivered, 1.0) diff --git a/addons/sale_mrp/models/sale_order_line.py b/addons/sale_mrp/models/sale_order_line.py index dad7b7e4a83..9a1b499798c 100644 --- a/addons/sale_mrp/models/sale_order_line.py +++ b/addons/sale_mrp/models/sale_order_line.py @@ -35,10 +35,9 @@ class SaleOrderLine(models.Model): for order_line in self: if order_line.qty_delivered_method == 'stock_move': boms = order_line.move_ids.filtered(lambda m: m.state != 'cancel').mapped('bom_line_id.bom_id') - dropship = False - if not boms and any(m._is_dropshipped() for m in order_line.move_ids): + dropship = any(m._is_dropshipped() for m in order_line.move_ids) + if not boms and dropship: boms = boms._bom_find(order_line.product_id, company_id=order_line.company_id.id, bom_type='phantom')[order_line.product_id] - 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 should be the only one since bom_line_id was written on the moves