From 0bc29de024823dc4bc37e661a85743b07f68415f Mon Sep 17 00:00:00 2001 From: Hiral Bhavsar Date: Wed, 6 Sep 2017 11:36:10 +0530 Subject: [PATCH] [IMP] stock: group tracked products in stock.move.line When the picking type doesn't have use_create_lots or use_existing_lots the products should end up in one stock.move.line. The user will then be able to validate the picking without specifying serial/lot numbers. --- addons/stock/models/stock_move.py | 2 +- addons/stock/tests/test_move.py | 44 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 3ee63610245..da4e32320ce 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -717,7 +717,7 @@ class StockMove(models.Model): if move.location_id.usage in ('supplier', 'inventory', 'production', 'customer')\ or move.product_id.type == 'consu': # create the move line(s) but do not impact quants - if move.product_id.tracking == 'serial': + if move.product_id.tracking == 'serial' and (move.picking_type_id.use_create_lots or move.picking_type_id.use_existing_lots): for i in range(0, int(move.product_qty)): self.env['stock.move.line'].create(move._prepare_move_line_vals(quantity=1)) else: diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index 2fc3d884045..ff95a03ddc6 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -2291,6 +2291,50 @@ class StockMove(TransactionCase): self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) self.assertEqual(len(self.env['stock.quant']._gather(self.product1, self.stock_location)), 0.0) + def _create_picking_test_immediate_validate_5(self, picking_type_id, product_id): + picking = self.env['stock.picking'].create({ + 'location_id': self.supplier_location.id, + 'location_dest_id': self.stock_location.id, + 'picking_type_id': picking_type_id.id, + }) + self.env['stock.move'].create({ + 'name': 'move1', + 'location_id': self.supplier_location.id, + 'location_dest_id': self.stock_location.id, + 'picking_id': picking.id, + 'picking_type_id': picking_type_id.id, + 'product_id': product_id.id, + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 5.0, + }) + + picking.action_confirm() + + for line in picking.move_line_ids: + line.qty_done = line.product_uom_qty + + return picking + + def test_immediate_validate_5(self): + """ Create a picking and simulates validate button effect. + Test that tracked products can be received without specifying a serial + number when the picking type is configured that way. + """ + picking_type_id = self.env.ref('stock.picking_type_in') + product_id = self.product2 + self.assertTrue(picking_type_id.use_create_lots or picking_type_id.use_existing_lots) + self.assertEqual(product_id.tracking, 'serial') + + picking = self._create_picking_test_immediate_validate_5(picking_type_id, product_id) + # should raise because no serial numbers were specified + self.assertRaises(UserError, picking.do_new_transfer) + + picking_type_id.use_create_lots = False + picking_type_id.use_existing_lots = False + picking = self._create_picking_test_immediate_validate_5(picking_type_id, product_id) + picking.do_new_transfer() + self.assertEqual(picking.state, 'done') + def test_set_quantity_done_1(self): move1 = self.env['stock.move'].create({ 'name': 'test_set_quantity_done_1',