[IMP] stock: reserved quantity put in pack
-Purpose of this task is speed up the put in pack process. -after this commit, on the Picking when clicking 'Put In Pack' button if there are no quantity set as done all the reserved quantity put in the pack. Task- 1966999 closes odoo/odoo#35280 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
@@ -1113,13 +1113,19 @@ class Picking(models.Model):
|
||||
float_compare(ml.qty_done, 0.0, precision_rounding=ml.product_uom_id.rounding) > 0
|
||||
and not ml.result_package_id
|
||||
)
|
||||
if not move_line_ids:
|
||||
move_line_ids = self.move_line_ids.filtered(lambda ml: float_compare(ml.product_uom_qty, 0.0,
|
||||
precision_rounding=ml.product_uom_id.rounding) > 0 and float_compare(ml.qty_done, 0.0,
|
||||
precision_rounding=ml.product_uom_id.rounding) == 0)
|
||||
for line in move_line_ids:
|
||||
line.qty_done = line.product_uom_qty
|
||||
if move_line_ids:
|
||||
res = self._pre_put_in_pack_hook(move_line_ids)
|
||||
if not res:
|
||||
res = self._put_in_pack(move_line_ids)
|
||||
return res
|
||||
else:
|
||||
raise UserError(_('You must first set the quantity you will put in the pack.'))
|
||||
raise UserError(_('All the products currently reserved in the picking are already in a pack. Please add products to the picking to create a new pack.'))
|
||||
|
||||
def button_scrap(self):
|
||||
self.ensure_one()
|
||||
|
||||
@@ -4199,3 +4199,97 @@ class StockMove(SavepointCase):
|
||||
picking.button_validate()
|
||||
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0)
|
||||
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.customer_location), 2)
|
||||
|
||||
def test_put_in_pack_2(self):
|
||||
"""Check that reserving moves without done quantity
|
||||
adding in same package.
|
||||
"""
|
||||
product1 = self.env['product.product'].create({
|
||||
'name': 'Product B',
|
||||
'type': 'product',
|
||||
'categ_id': self.env.ref('product.product_category_all').id,
|
||||
})
|
||||
self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1)
|
||||
self.env['stock.quant']._update_available_quantity(product1, self.stock_location, 2)
|
||||
picking = self.env['stock.picking'].create({
|
||||
'location_id': self.stock_location.id,
|
||||
'location_dest_id': self.customer_location.id,
|
||||
'picking_type_id': self.env.ref('stock.picking_type_out').id,
|
||||
})
|
||||
move1 = self.env['stock.move'].create({
|
||||
'name': 'test_transit_1',
|
||||
'location_id': self.stock_location.id,
|
||||
'location_dest_id': self.customer_location.id,
|
||||
'product_id': self.product.id,
|
||||
'product_uom': self.uom_unit.id,
|
||||
'product_uom_qty': 1.0,
|
||||
'picking_id': picking.id,
|
||||
})
|
||||
move2 = self.env['stock.move'].create({
|
||||
'name': 'test_transit_2',
|
||||
'location_id': self.stock_location.id,
|
||||
'location_dest_id': self.customer_location.id,
|
||||
'product_id': product1.id,
|
||||
'product_uom': self.uom_unit.id,
|
||||
'product_uom_qty': 2.0,
|
||||
'picking_id': picking.id,
|
||||
})
|
||||
picking.action_confirm()
|
||||
picking.action_assign()
|
||||
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0)
|
||||
self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, self.stock_location), 0)
|
||||
picking.put_in_pack()
|
||||
self.assertEqual(len(picking.move_line_ids), 2)
|
||||
self.assertEqual(picking.move_line_ids[0].qty_done, 1, "Stock move line should have 1 quantity as a done quantity.")
|
||||
self.assertEqual(picking.move_line_ids[1].qty_done, 2, "Stock move line should have 2 quantity as a done quantity.")
|
||||
line1_result_package = picking.move_line_ids[0].result_package_id
|
||||
line2_result_package = picking.move_line_ids[1].result_package_id
|
||||
self.assertEqual(line1_result_package, line2_result_package, "Product and Product1 should be in a same package.")
|
||||
|
||||
def test_put_in_pack_3(self):
|
||||
"""Check that one reserving move without done quantity and
|
||||
another reserving move with done quantity adding in different
|
||||
package.
|
||||
"""
|
||||
product1 = self.env['product.product'].create({
|
||||
'name': 'Product B',
|
||||
'type': 'product',
|
||||
'categ_id': self.env.ref('product.product_category_all').id,
|
||||
})
|
||||
self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1)
|
||||
self.env['stock.quant']._update_available_quantity(product1, self.stock_location, 2)
|
||||
picking = self.env['stock.picking'].create({
|
||||
'location_id': self.stock_location.id,
|
||||
'location_dest_id': self.customer_location.id,
|
||||
'picking_type_id': self.env.ref('stock.picking_type_out').id,
|
||||
})
|
||||
move1 = self.env['stock.move'].create({
|
||||
'name': 'test_transit_1',
|
||||
'location_id': self.stock_location.id,
|
||||
'location_dest_id': self.customer_location.id,
|
||||
'product_id': self.product.id,
|
||||
'product_uom': self.uom_unit.id,
|
||||
'product_uom_qty': 1.0,
|
||||
'picking_id': picking.id,
|
||||
})
|
||||
move2 = self.env['stock.move'].create({
|
||||
'name': 'test_transit_2',
|
||||
'location_id': self.stock_location.id,
|
||||
'location_dest_id': self.customer_location.id,
|
||||
'product_id': product1.id,
|
||||
'product_uom': self.uom_unit.id,
|
||||
'product_uom_qty': 2.0,
|
||||
'picking_id': picking.id,
|
||||
})
|
||||
picking.action_confirm()
|
||||
picking.action_assign()
|
||||
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0)
|
||||
self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, self.stock_location), 0)
|
||||
move1.quantity_done = 1
|
||||
picking.put_in_pack()
|
||||
move2.quantity_done = 2
|
||||
picking.put_in_pack()
|
||||
self.assertEqual(len(picking.move_line_ids), 2)
|
||||
line1_result_package = picking.move_line_ids[0].result_package_id
|
||||
line2_result_package = picking.move_line_ids[1].result_package_id
|
||||
self.assertNotEqual(line1_result_package, line2_result_package, "Product and Product1 should be in a different package.")
|
||||
|
||||
Reference in New Issue
Block a user