[FIX] stock: edit done move line

When undoing the original move line, make sure to handle the packages
correctly (in the destination location, undo the result package, not the
source one.
This commit is contained in:
Simon Lejeune
2017-09-30 17:12:20 +02:00
parent 191873f8a5
commit 1cded67619
2 changed files with 41 additions and 1 deletions
+1 -1
View File
@@ -250,7 +250,7 @@ class StockMoveLine(models.Model):
# undo the original move line
qty_done_orig = ml.move_id.product_uom._compute_quantity(ml.qty_done, ml.move_id.product_id.uom_id, rounding_method='HALF-UP')
in_date = Quant._update_available_quantity(ml.product_id, ml.location_dest_id, -qty_done_orig, lot_id=ml.lot_id,
package_id=ml.package_id, owner_id=ml.owner_id)[1]
package_id=ml.result_package_id, owner_id=ml.owner_id)[1]
Quant._update_available_quantity(ml.product_id, ml.location_id, qty_done_orig, lot_id=ml.lot_id,
package_id=ml.package_id, owner_id=ml.owner_id, in_date=in_date)
+40
View File
@@ -2202,6 +2202,46 @@ class StockMove(TransactionCase):
move1.move_line_ids.qty_done = 2
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location, lot_id=lot1), 24.0)
def test_edit_done_move_line_13(self):
""" Test that editing a done stock move line linked to a packed and tracked product correctly
and directly adapts the transfer. In this case, we edit the lot to another available one
that we put in the same pack.
"""
lot1 = self.env['stock.production.lot'].create({
'name': 'lot1',
'product_id': self.product1.id,
})
lot2 = self.env['stock.production.lot'].create({
'name': 'lot2',
'product_id': self.product1.id,
})
package1 = self.env['stock.quant.package'].create({'name': 'test_edit_reserved_move_line_5'})
move1 = self.env['stock.move'].create({
'name': 'test_edit_moveline_1',
'location_id': self.supplier_location.id,
'location_dest_id': self.stock_location.id,
'product_id': self.product3.id,
'product_uom': self.uom_unit.id,
'product_uom_qty': 1.0,
})
move1._action_confirm()
move1._action_assign()
move1.move_line_ids.qty_done = 1
move1.move_line_ids.lot_id = lot1.id
move1.move_line_ids.result_package_id = package1.id
move1._action_done()
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location), 1.0)
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location, lot_id=lot1, package_id=package1), 1.0)
move1.move_line_ids.write({'lot_id': lot2.id})
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location), 1.0)
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location, lot_id=lot1), 0.0)
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location, lot_id=lot1, package_id=package1), 0.0)
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location, lot_id=lot2, package_id=package1), 1.0)
def test_immediate_validate_1(self):
""" Create a picking and simulates validate button effect.
Move line quantity should be set to their reservation quantity automatically