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)