Skip to content

Commit

Permalink
[FIX] sale_stock: update SO line with import
Browse files Browse the repository at this point in the history
Creates a sale order, then validates the delivery.
Modify the sale order lines qty via import.
We expect a new delivery instead we have a UserError

The purpose of the userError is to avoid editing
reserved quantity directly in the picking. But in
SO/PO case it's handle by the system and quantities
are correctly reserved so the UserError should not
happens.

A better fix exists in saas-16.2 where the create
method of stock.move.line is now responsible for
reservation

opw-3336131

closes odoo#129795

X-original-commit: a53614e
Signed-off-by: Tiffany Chang <tic@odoo.com>
  • Loading branch information
amoyaux authored and ticodoo committed Aug 4, 2023
1 parent 2c1279e commit 87f62c9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion addons/sale_stock/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,10 @@ def _action_launch_stock_rule(self, previous_product_uom_qty=False):
line.order_id.partner_shipping_id.property_stock_customer,
line.product_id.display_name, line.order_id.name, line.order_id.company_id, values))
if procurements:
self.env['procurement.group'].run(procurements)
procurement_group = self.env['procurement.group']
if self.env.context.get('import_file'):
procurement_group = procurement_group.with_context(import_file=False)
procurement_group.run(procurements)

# This next block is currently needed only because the scheduler trigger is done by picking confirmation rather than stock.move confirmation
orders = self.mapped('order_id')
Expand Down
26 changes: 26 additions & 0 deletions addons/sale_stock/tests/test_sale_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,32 @@ def test_18_deliver_more_and_multi_uom(self):
self.assertEqual(so.order_line[1].qty_delivered, 1)
self.assertEqual(so.order_line[1].product_uom.id, uom_km_id)

def test_19_deliver_update_so_line_qty(self):
"""
Creates a sale order, then validates the delivery
modifying the sale order lines qty via import and ensures
a new delivery is created.
"""
self.product_a.type = 'product'
self.env['stock.quant']._update_available_quantity(
self.product_a, self.company_data['default_warehouse'].lot_stock_id, 10)

# Create sale order
sale_order = self._get_new_sale_order()
sale_order.action_confirm()

# Validate delivery
picking = sale_order.picking_ids
picking.move_ids.write({'quantity_done': 10})
picking.button_validate()

# Update the line and check a new delivery is created
with Form(sale_order.with_context(import_file=True)) as so_form:
with so_form.order_line.edit(0) as line:
line.product_uom_qty = 777

self.assertEqual(len(sale_order.picking_ids), 2)

def test_multiple_returns(self):
# Creates a sale order for 10 products.
sale_order = self._get_new_sale_order()
Expand Down

0 comments on commit 87f62c9

Please sign in to comment.