Skip to content

Commit fff6eda

Browse files
committed
[FIX] sale_mrp: sell kit with dropshipped component
When selling a kit with a dropshipped component, the delivered quantity will be incorrect To reproduce the issue: 1. Create 3 consumable products P01, P02, P_kit: - P02: - Add a seller S - Enable the dropship route 2. Create a bill of materials: - Product: P_kit - Type: Kit - Components: - 1 x P01 - 1 x P02 3. Create and confirm a sale order SO with 1 x P_kit 4. Confirm the generated purchase order (with vendor S) 5. Process the two pickings of SO 6. Go back to SO Error: The delivered quantity of P_kit is 0 instead of 1 When computing the delivered quantity, because the `dropship` flag is not set, we don't reach the revelant code: https://github.com/odoo/odoo/blob/3db136f19480b31ca3f60a77c0c7354161bedde0/addons/sale_mrp/models/sale_mrp.py#L37-L44 OPW-2870893 closes odoo#94285 X-original-commit: d05240f Signed-off-by: Arnold Moyaux (arm) <[email protected]> Signed-off-by: Adrien Widart <[email protected]>
1 parent 8b551cd commit fff6eda

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

addons/mrp_subcontracting_dropshipping/tests/test_sale_dropshipping.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,44 @@ def test_cancelled_picking_and_delivered_qty(self):
250250

251251
sale_order.picking_ids.action_cancel()
252252
self.assertEqual(sale_order.order_line.qty_delivered, 0.0)
253+
254+
def test_sale_kit_with_dropshipped_component(self):
255+
"""
256+
The test checks the delivered quantity of a kit when one of the
257+
components is dropshipped
258+
"""
259+
compo01, compo02, kit = self.env['product.product'].create([{
260+
'name': n,
261+
'type': 'consu',
262+
} for n in ['compo01', 'compo02', 'super kit']])
263+
264+
compo02.write({
265+
'route_ids': [(6, 0, [self.dropship_route.id])],
266+
'seller_ids': [(0, 0, {'partner_id': self.supplier.id})],
267+
})
268+
269+
self.env['mrp.bom'].create({
270+
'product_tmpl_id': kit.product_tmpl_id.id,
271+
'product_qty': 1,
272+
'type': 'phantom',
273+
'bom_line_ids': [
274+
(0, 0, {'product_id': compo01.id, 'product_qty': 1}),
275+
(0, 0, {'product_id': compo02.id, 'product_qty': 1}),
276+
],
277+
})
278+
279+
sale_order = self.env['sale.order'].create({
280+
'partner_id': self.customer.id,
281+
'picking_policy': 'direct',
282+
'order_line': [
283+
(0, 0, {'name': kit.name, 'product_id': kit.id, 'product_uom_qty': 1}),
284+
],
285+
})
286+
sale_order.action_confirm()
287+
self.env['purchase.order'].search([], order='id desc', limit=1).button_confirm()
288+
289+
sale_order.picking_ids.move_ids.quantity_done = 1
290+
sale_order.picking_ids[0].button_validate()
291+
sale_order.picking_ids[1].button_validate()
292+
293+
self.assertEqual(sale_order.order_line.qty_delivered, 1.0)

addons/sale_mrp/models/sale.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ def _compute_qty_delivered(self):
7878
for order_line in self:
7979
if order_line.qty_delivered_method == 'stock_move':
8080
boms = order_line.move_ids.filtered(lambda m: m.state != 'cancel').mapped('bom_line_id.bom_id')
81-
dropship = False
82-
if not boms and any(m._is_dropshipped() for m in order_line.move_ids):
81+
dropship = any(m._is_dropshipped() for m in order_line.move_ids)
82+
if not boms and dropship:
8383
boms = boms._bom_find(order_line.product_id, company_id=order_line.company_id.id, bom_type='phantom')[order_line.product_id]
84-
dropship = True
8584
# We fetch the BoMs of type kits linked to the order_line,
8685
# the we keep only the one related to the finished produst.
8786
# This bom shoud be the only one since bom_line_id was written on the moves

0 commit comments

Comments
 (0)