[FIX] stock: move: initial demand should be 0 on create

When creating a new line in a picking, the initial demand should be 0.
When editing a move line and changning the product, the initial demand
should not be reset to 1.

The rationale is that when creating a picking by hand, most users do
want to skip the reservationm and, by forcing the initial demand at 1,
we force the user to enter to encode two times what he's doing.
This commit is contained in:
amoyaux
2017-07-19 17:28:40 +02:00
committed by Simon Lejeune
parent 96eeb5c186
commit d6ed41f9d7
2 changed files with 19 additions and 3 deletions
+1 -3
View File
@@ -52,7 +52,7 @@ class StockMove(models.Model):
product_uom_qty = fields.Float(
'Initial Demand',
digits=dp.get_precision('Product Unit of Measure'),
default=1.0, required=True, states={'done': [('readonly', True)]},
default=0.0, required=True, states={'done': [('readonly', True)]},
help="This is the quantity of products from an inventory "
"point of view. For moves in the state 'done', this is the "
"quantity of products that were actually moved. For other "
@@ -498,8 +498,6 @@ class StockMove(models.Model):
product = self.product_id.with_context(lang=self.partner_id.lang or self.env.user.lang)
self.name = product.partner_ref
self.product_uom = product.uom_id.id
if self.product_uom_qty:
self.product_uom_qty = 1.0
return {'domain': {'product_uom': [('category_id', '=', product.uom_id.category_id.id)]}}
@api.onchange('date')
+18
View File
@@ -2202,3 +2202,21 @@ class StockMove(TransactionCase):
(move1 + move2).write({'quantity_done': 1})
self.assertEqual(move1.quantity_done, 1)
self.assertEqual(move2.quantity_done, 1)
def test_initial_demand_1(self):
""" Check that the initial demand is set to 0 when creating a move by hand, and
that changing the product on the move do not reset the initial demand.
"""
move1 = self.env['stock.move'].create({
'name': 'test_in_1',
'location_id': self.supplier_location.id,
'location_dest_id': self.stock_location.id,
'product_id': self.product1.id,
'product_uom': self.uom_unit.id,
})
self.assertEqual(move1.state, 'draft')
self.assertEqual(move1.product_uom_qty, 0)
move1.product_uom_qty = 100
move1.product_id = self.product2
move1.onchange_product_id()
self.assertEqual(move1.product_uom_qty, 100)