[FIX] stock, stock_account: add move when picking is available

When a picking is available, any added stock move should directly be in
the available state. This is done thanks to a key in context put in the
one2many (stock.move) field on the picking view and an override of
stock.move's default_get. Sadly, an extension of the picking view in
stock_account redefined the context attributes, and the new context did
not have the special key we need. As all the context keys present in
stock_account are present in stock, we remove the extension. And we add
a simple test in stock.
This commit is contained in:
Simon Lejeune
2017-07-24 16:06:57 +02:00
parent afc5c0709a
commit 8822b7cfa4
2 changed files with 46 additions and 12 deletions
+46 -1
View File
@@ -23,7 +23,7 @@ class TestPickShip(TestStockCommon):
'location_dest_id': self.customer_location,
'state': 'waiting',
})
picking_pick = self.env['stock.picking'].create({
'location_id': self.stock_location,
'location_dest_id': self.pack_location,
@@ -701,3 +701,48 @@ class TestSinglePicking(TestStockCommon):
self.assertEqual(len(move1.move_line_ids), 2)
self.assertEqual(move1.move_line_ids[0].lot_id.id, serial1.id)
self.assertEqual(move1.move_line_ids[1].lot_id.id, serial2.id)
def test_add_move_when_picking_is_available_1(self):
""" Check that any move added in a picking once it's assigned is directly considered as
assigned and bypass the reservation.
"""
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,
})
# 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)
# assign
delivery_order.action_confirm()
delivery_order.action_assign()
self.assertEqual(delivery_order.state, 'assigned')
# add a move
move2 = self.MoveObj\
.with_context(default_picking_id=delivery_order.id)\
.create({
'name': self.productA.name,
'product_id': self.productB.id,
'product_uom_qty': 1,
'product_uom': self.productA.uom_id.id,
'picking_id': delivery_order.id,
'location_id': self.pack_location,
'location_dest_id': self.customer_location,
})
self.assertEqual(move2.state, 'assigned')
self.assertEqual(delivery_order.state, 'assigned')
@@ -27,17 +27,6 @@
</field>
</record>
<record id="view_picking_inherit_form2" model="ir.ui.view">
<field name="name">stock.picking.form.inherit</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<field name="move_lines" position="attributes">
<attribute name="context">{'address_in_id': partner_id, 'form_view_ref':'stock.view_move_picking_form', 'tree_view_ref':'stock.view_move_picking_tree', 'default_picking_type_id': picking_type_id, 'default_location_id': location_id, 'default_location_dest_id': location_dest_id}</attribute>
</field>
</field>
</record>
<record id="view_stock_return_picking_form_inherit_stock_account" model="ir.ui.view">
<field name="name">stock.return.picking.stock.account.form</field>
<field name="inherit_id" ref="stock.view_stock_return_picking_form"/>