From d6ed41f9d74361f259c8555a0f6aa552ede08846 Mon Sep 17 00:00:00 2001 From: amoyaux Date: Tue, 18 Jul 2017 10:21:44 +0200 Subject: [PATCH] [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. --- addons/stock/models/stock_move.py | 4 +--- addons/stock/tests/test_move.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index df7cc8aec52..077e8147917 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -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') diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index 3e072b692b4..04406847d7e 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -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)