[FIX] stock: _action_done

Rev[1] fixed a bug where the order inside of the recordset could trigger
side effects by merging move when creating the extra moves. However,
after the patch, `moves_todo` contained moves that should be backordered
(with no quantity done). This commit fixes this oversight.

[1] b95cabef0b
Fixes #22440
This commit is contained in:
Simon Lejeune
2018-01-23 14:42:56 +01:00
parent 340d70338f
commit dec50fc19b
2 changed files with 49 additions and 9 deletions
+4 -9
View File
@@ -1009,17 +1009,12 @@ class StockMove(models.Model):
move._action_cancel()
# Create extra moves where necessary
for move in moves.filtered(lambda m: m.state != 'cancel'):
# Here, the `quantity_done` was already rounded to the product UOM by the `do_produce` wizard. However,
# it is possible that the user changed the value before posting the inventory by a value that should be
# rounded according to the move's UOM. In this specific case, we chose to round up the value, because it
# is what is expected by the user (if i consumed/produced a little more, the whole UOM unit should be
# consumed/produced and the moves are split correctly).
# FIXME: move rounding to move line
# rounding = move.product_uom.rounding
# move.quantity_done = float_round(move.quantity_done, precision_rounding=rounding, rounding_method ='UP')
for move in moves:
if move.state == 'cancel' or move.quantity_done <= 0:
continue
moves_todo |= move
moves_todo |= move._create_extra_move()
# Split moves where necessary and move quants
for move in moves_todo:
rounding = move.product_uom.rounding
+45
View File
@@ -743,6 +743,51 @@ class TestSinglePicking(TestStockCommon):
backorder = self.env['stock.picking'].search([('backorder_id', '=', delivery_order.id)])
self.assertEqual(backorder.state, 'confirmed')
def test_backorder_3(self):
""" Check the good behavior of creating a backorder for an available move on a picking with
two available moves.
"""
delivery_order = self.env['stock.picking'].create({
'location_id': self.pack_location,
'location_dest_id': self.customer_location,
'partner_id': self.partner_delta_id,
'picking_type_id': self.picking_type_out,
})
self.MoveObj.create({
'name': self.productA.name,
'product_id': self.productA.id,
'product_uom_qty': 2,
'product_uom': self.productA.uom_id.id,
'picking_id': delivery_order.id,
'location_id': self.pack_location,
'location_dest_id': self.customer_location,
})
self.MoveObj.create({
'name': self.productA.name,
'product_id': self.productB.id,
'product_uom_qty': 2,
'product_uom': self.productB.uom_id.id,
'picking_id': delivery_order.id,
'location_id': self.pack_location,
'location_dest_id': self.customer_location,
})
# make some stock
pack_location = self.env['stock.location'].browse(self.pack_location)
self.env['stock.quant']._update_available_quantity(self.productA, pack_location, 2)
self.env['stock.quant']._update_available_quantity(self.productA, pack_location, 2)
# assign to partially available
delivery_order.action_confirm()
delivery_order.action_assign()
self.assertEqual(delivery_order.state, 'assigned')
delivery_order.move_lines[0].move_line_ids[0].qty_done = 2
delivery_order.do_transfer()
backorder = self.env['stock.picking'].search([('backorder_id', '=', delivery_order.id)])
self.assertEqual(backorder.state, 'confirmed')
def test_extra_move_1(self):
""" Check the good behavior of creating an extra move in a delivery order. This usecase
simulates the delivery of 2 item while the initial stock move had to move 1 and there's