[FIX] sale_mrp: decrease kit quantity to 0 after so confirmation
Steps to reproduce the bug:
- Create two storable products:
- kit_1 and Comp_1
- Create a bill of materials:
- Product: kit_1
- Type: Kit
- Components: 1 unit of Comp_1
- Create a SO with:
- kit: 1 unit
- Confirm the SO
- A picking with 2 units of “comp_1” will be created
- Edit SO:
- Reduce the qty of kit_1 to 0
Problem:
“Comp_1” qty not updated to 0 on the picking.
When the SOL qty is updated, the pickings should be updated too.
So we get the qty in delivery:
https://github.com/odoo/odoo/blob/e11dfa341baf82fedee753502aef5ef2972f75cb/addons/sale_stock/models/sale_order.py#L553
then the difference between that qty and the new SOL qty is computed.
And procurement based on that difference is created:
https://github.com/odoo/odoo/blob/e11dfa341baf82fedee753502aef5ef2972f75cb/addons/sale_stock/models/sale_order.py#L573-L578
but the `_get_qty_procurement` function returns 0 as result, because
the `_compute_kit_quantities` function is called with the qty set on
the SO (“0”), so the result will be 0 because we need 0 qty to have 0
kit:
https://github.com/odoo/odoo/blob/4ee5df76607c80c94a4aea832dcd2f73ad8e5ee1/addons/sale_mrp/models/sale_order_line.py#L121-L122
opw-3018258
closes odoo/odoo#105078
X-original-commit: 8fcbd91b4416f08693bc806c5f99c6c429ecfe66
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
@@ -113,6 +113,8 @@ class SaleOrderLine(models.Model):
|
||||
# kits that are currently in delivery
|
||||
bom = self.env['mrp.bom']._bom_find(self.product_id, bom_type='phantom')[self.product_id]
|
||||
if bom:
|
||||
if not self.product_uom_qty or (previous_product_uom_qty and not previous_product_uom_qty.get(self.id, 0.0)):
|
||||
return (previous_product_uom_qty and previous_product_uom_qty.get(self.id, 0.0)) or self.qty_delivered
|
||||
moves = self.move_ids.filtered(lambda r: r.state != 'cancel' and not r.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)),
|
||||
|
||||
@@ -2119,3 +2119,41 @@ class TestSaleMrpFlow(ValuationReconciliationTestCommon):
|
||||
self.assertEqual(so.order_line.purchase_price, 60)
|
||||
so.action_confirm()
|
||||
self.assertEqual(so.order_line.purchase_price, 60)
|
||||
|
||||
def test_kit_decrease_sol_qty_to_zero(self):
|
||||
"""
|
||||
Create and confirm a SO with a kit product. Increasing/Decreasing the SOL qty
|
||||
should update the qty on the delivery.
|
||||
"""
|
||||
stock_location = self.company_data['default_warehouse'].lot_stock_id
|
||||
|
||||
grp_uom = self.env.ref('uom.group_uom')
|
||||
self.env.user.write({'groups_id': [(4, grp_uom.id)]})
|
||||
|
||||
# 10 kit_3 = 10 x compo_f + 20 x compo_g
|
||||
self.env['stock.quant']._update_available_quantity(self.component_f, stock_location, 10)
|
||||
self.env['stock.quant']._update_available_quantity(self.component_g, stock_location, 20)
|
||||
|
||||
so_form = Form(self.env['sale.order'])
|
||||
so_form.partner_id = self.partner_a
|
||||
with so_form.order_line.new() as line:
|
||||
line.product_id = self.kit_3
|
||||
line.product_uom_qty = 2
|
||||
line.product_uom = self.uom_ten
|
||||
so = so_form.save()
|
||||
so.action_confirm()
|
||||
|
||||
delivery = so.picking_ids
|
||||
self.assertRecordValues(delivery.move_ids, [
|
||||
{'product_id': self.component_f.id, 'product_uom_qty': 20},
|
||||
{'product_id': self.component_g.id, 'product_uom_qty': 40},
|
||||
])
|
||||
|
||||
# Decrease the qty to 0
|
||||
with Form(so) as so_form:
|
||||
with so_form.order_line.edit(0) as line:
|
||||
line.product_uom_qty = 0
|
||||
self.assertRecordValues(delivery.move_ids, [
|
||||
{'product_id': self.component_f.id, 'product_uom_qty': 0},
|
||||
{'product_id': self.component_g.id, 'product_uom_qty': 0},
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user