Skip to content

Commit

Permalink
[FIX] stock_pack_operation_auto_fill: Avoid auto fill qty_done when a…
Browse files Browse the repository at this point in the history
…n extra_move has been created
  • Loading branch information
sergio-teruel committed Jul 2, 2019
1 parent 48ac521 commit 9d520a4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
18 changes: 16 additions & 2 deletions stock_pack_operation_auto_fill/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@
class StockMove(models.Model):
_inherit = 'stock.move'

def _create_extra_move(self):
"""
When user set on stock move line done a quantity greater than initial
demand Odoo creates an extra stock move with the difference and it is
posible to create an extra stock move line with qty_done = 0 which will
be deleted in _action_done method.
This method set a context variable to prevent set qty_done for these
cases.
"""
my_self = self
if self.picking_id.auto_fill_operation:
my_self = self.with_context(skip_auto_fill_operation=True)
return super(StockMove, my_self)._create_extra_move()

def _prepare_move_line_vals(self, quantity=None, reserved_quant=None):
"""Auto-assign as done the quantity proposed for the lots"""
self.ensure_one()
res = super(StockMove, self)._prepare_move_line_vals(
quantity, reserved_quant,
)
if not self.picking_id.auto_fill_operation:
if (self.env.context.get('skip_auto_fill_operation') or
not self.picking_id.auto_fill_operation):
return res
elif (self.picking_id.picking_type_id.avoid_lot_assignment and
res.get('lot_id')):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,38 @@ def test_action_auto_transfer_avoid_assign_lots(self):
# The expected result is only opertions with product_id set and
self.assertFalse(product_8_op.qty_done)
self.assertTrue(product_9_op.qty_done)

def test_receipt_more_qty_than_demand(self):
# Active auto fill operations although they have assigned lots
self.picking_type_in.write({
'auto_fill_operation': True,
'avoid_lot_assignment': False,
})
picking_in = self.picking_model.create({
'partner_id': self.supplier.id,
'picking_type_id': self.picking_type_in.id,
'location_id': self.supplier_location.id,
'location_dest_id': self.warehouse.wh_input_stock_loc_id.id,
'move_lines': [(0, 0, {
'name': self.product_8.display_name,
'product_id': self.product_8.id,
'product_uom_qty': 10.0,
'product_uom': self.product_8.uom_id.id,
'partner_id': self.supplier.id,
'location_id': self.supplier_location.id,
'location_dest_id': self.warehouse.wh_input_stock_loc_id.id,
})]
})
lot = self.env['stock.production.lot'].create({
'product_id': self.product_8.id,
'name': 'test-lot-0001',
})
# Receipt more than initial demand and assign a lot to force create an
# extra stock move line which must be deleted.
picking_in.move_line_ids.write({
'lot_id': lot.id,
'qty_done': 50.0,
})
picking_in.action_done()
# The move should only have a one stock move line.
self.assertEqual(len(picking_in.move_line_ids), 1)

0 comments on commit 9d520a4

Please sign in to comment.