Skip to content

Commit 2777dfc

Browse files
mama-odoosvs-odoo
authored andcommitted
[FIX] stock: wrong result_package_id
When forcefully unreserving then reserving products coming from a same package for multiple pickings, the source package is wrongly propagated as destination package on the multiple pickings. To reproduce: - `-i sale_stock,sale_management` - Create a storable product (I) with 30 qty on hand - Create and confirm an internal transfer to put the product I in an pack (P) - Create and confirm two SO : - Sell 10 I - Sell 20 I - Check the 2 SO delivery pickings (D): - Each are reserved from pack P - They don't have any 'Destination Package' [Expected] - From the picking list view, by selecting the 2 pickings D : - 'Unreserve' them both - 'Check Availability'them both - Check the pickings D: - Each are reserved from pack P - Each have 'Destination Package' P [Faulty] opw-4272573 closes odoo#193745 Signed-off-by: Steve Van Essche <svs@odoo.com>
1 parent c4ed49a commit 2777dfc

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

addons/stock/models/stock_picking.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,9 +1034,9 @@ def _check_entire_pack(self):
10341034
'move_line_ids': [(6, 0, move_lines_to_pack.ids)],
10351035
'company_id': pickings.company_id.id,
10361036
})
1037-
# Propagate the result package in the next move for disposable packages only.
1038-
if package.package_use == 'disposable':
1039-
move_lines_to_pack.write({'result_package_id': package.id})
1037+
# Propagate the result package in the next move for disposable packages only.
1038+
if package.package_use == 'disposable':
1039+
move_lines_to_pack.write({'result_package_id': package.id})
10401040
else:
10411041
move_lines_in_package_level = move_lines_to_pack.filtered(lambda ml: ml.move_id.package_level_id)
10421042
move_lines_without_package_level = move_lines_to_pack - move_lines_in_package_level

addons/stock/tests/test_packing.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,3 +1939,51 @@ def test_reusable_package_propagation(self):
19391939
self.assertEqual(len(pack_lines), 2, 'Should have only 2 stock move line')
19401940
self.assertFalse(pack_lines[0].result_package_id, 'Should not have the reusable package')
19411941
self.assertEqual(pack_lines[1].result_package_id, disposable_package, 'Should have only the disposable package')
1942+
1943+
def test_conditional_package_propagation(self):
1944+
"""If a picking completely moves the products of a package, you want to pass it as result_package_id.
1945+
On the other hand, if the quantity of the same pack is split between several pickings, you want to leave the result_package_id empty.
1946+
"""
1947+
# Storable product : 30 qty in a package.
1948+
package = self.env['stock.quant.package'].create({'name': 'packtest'})
1949+
self.env['stock.quant']._update_available_quantity(self.productA, self.stock_location, 30.0, package_id=package)
1950+
1951+
# 1 delivery picking, 30 product, action_assign => On move line, package_id == result_package_id
1952+
full_delivery = self.env['stock.picking'].create({
1953+
'picking_type_id': self.warehouse.out_type_id.id,
1954+
'location_id': self.stock_location.id,
1955+
'location_dest_id': self.customer_location.id,
1956+
'move_ids': [Command.create({
1957+
'name': 'move full',
1958+
'product_id': self.productA.id,
1959+
'product_uom_qty': 30.0,
1960+
'product_uom': self.productA.uom_id.id,
1961+
'location_id': self.stock_location.id,
1962+
'location_dest_id': self.customer_location.id,
1963+
})]
1964+
})
1965+
full_delivery.action_confirm()
1966+
full_delivery.action_assign()
1967+
self.assertEqual(full_delivery.move_line_ids.package_id, package, "The package should be used as source.")
1968+
self.assertEqual(full_delivery.move_line_ids.result_package_id, package, "If all the products in a package are to be moved, we must move the entire package.")
1969+
full_delivery.action_cancel() # Cancel delivery to unreserve the package/quantity.
1970+
1971+
# Create 2 delivery picking : 10 & 20 of product each.
1972+
partial_deliveries = self.env['stock.picking'].create([{
1973+
'picking_type_id': self.warehouse.out_type_id.id,
1974+
'location_id': self.stock_location.id,
1975+
'location_dest_id': self.customer_location.id,
1976+
'move_ids': [Command.create({
1977+
'name': 'move partial',
1978+
'product_id': self.productA.id,
1979+
'product_uom_qty': qty,
1980+
'product_uom': self.productA.uom_id.id,
1981+
'location_id': self.stock_location.id,
1982+
'location_dest_id': self.customer_location.id,
1983+
})]
1984+
} for qty in [10, 20]])
1985+
partial_deliveries.action_confirm()
1986+
partial_deliveries.action_assign()
1987+
# action_assign => On move lines, result_package_id is not set.
1988+
self.assertEqual(partial_deliveries.move_line_ids.package_id, package, "The package should be used as source.")
1989+
self.assertFalse(partial_deliveries.move_line_ids.result_package_id, "If the contents of a single pack are reserved by multiple picks, the entire pack can't reproduce on each pick.")

0 commit comments

Comments
 (0)