diff --git a/addons/mrp_account/tests/test_valuation_layers.py b/addons/mrp_account/tests/test_valuation_layers.py index c61a7c9f966..097625e99a3 100644 --- a/addons/mrp_account/tests/test_valuation_layers.py +++ b/addons/mrp_account/tests/test_valuation_layers.py @@ -316,3 +316,35 @@ class TestMrpValuationStandard(TestMrpValuationCommon): self.assertEqual(self.product1.quantity_svl, 2) self._make_out_move(self.product1, 1) self.assertEqual(self.product1.value_svl, 15) + + def test_validate_draft_kit(self): + """ + Create a draft receipt, add a kit to its move lines and directly + validate it. From client side, such a behaviour is possible with + the Barcode app. + """ + self.component.product_tmpl_id.categ_id.property_cost_method = 'average' + self.product1.type = 'consu' + self.bom.type = 'phantom' + self.component.standard_price = 1424 + + receipt = self.env['stock.picking'].create({ + 'location_id': self.customer_location.id, + 'location_dest_id': self.stock_location.id, + 'picking_type_id': self.picking_type_in.id, + 'move_line_ids': [(0, 0, { + 'product_id': self.product1.id, + 'qty_done': 1, + 'product_uom_id': self.product1.uom_id.id, + 'location_id': self.customer_location.id, + 'location_dest_id': self.stock_location.id, + })] + }) + receipt.button_validate() + + self.assertEqual(receipt.state, 'done') + self.assertRecordValues(receipt.move_ids, [ + {'product_id': self.component.id, 'quantity_done': 1, 'state': 'done'}, + ]) + self.assertEqual(self.component.qty_available, 1) + self.assertEqual(self.component.value_svl, 1424) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 4a690bfb3d0..4e2fe04f84f 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1761,8 +1761,8 @@ Please change the quantity done or the rounding precision of your unit of measur return extra_move | self def _action_done(self, cancel_backorder=False): - self.filtered(lambda move: move.state == 'draft')._action_confirm() # MRP allows scrapping draft moves - moves = self.exists().filtered(lambda x: x.state not in ('done', 'cancel')) + moves = self.filtered(lambda move: move.state == 'draft')._action_confirm() # MRP allows scrapping draft moves + moves = (self | moves).exists().filtered(lambda x: x.state not in ('done', 'cancel')) moves_ids_todo = OrderedSet() # Cancel moves where necessary ; we should do it before creating the extra moves because diff --git a/addons/stock_account/models/stock_move.py b/addons/stock_account/models/stock_move.py index e6f7725cdca..63b779f17a2 100644 --- a/addons/stock_account/models/stock_move.py +++ b/addons/stock_account/models/stock_move.py @@ -252,6 +252,9 @@ class StockMove(models.Model): res = super(StockMove, self)._action_done(cancel_backorder=cancel_backorder) + # '_action_done' might have deleted some exploded stock moves + valued_moves = {value_type: moves.exists() for value_type, moves in valued_moves.items()} + # '_action_done' might have created an extra move to be valued for move in res - self: for valued_type in self._get_valued_types():