From ddfbfddf3c8639f6e6cfc64bb0125156c13c84ab Mon Sep 17 00:00:00 2001 From: clesgow Date: Wed, 24 Aug 2022 13:34:15 +0000 Subject: [PATCH] [FIX] purchase_stock: Fix receipt auto-batch When using the auto-batch feature for receipt, when creating a purchase, it wouldn't batch pickings that matched the group-by conditions. The issue is that the _create_picking() called when validating a Purchase Order creates the picking, then creates its moves and then validates them. Doing it this way avoids the trigger for the auto-batch feature located in picking's action_confirm(). By calling action_confirm() on the created picking, we force the trigger of the auto-batch, while not confirming the moves a second time since their state isn't 'draft' anymore. opw-2961618 closes odoo/odoo#99466 X-original-commit: 7d091ba995d13fa8f692827b33aad0982c2a65fa Signed-off-by: Arnold Moyaux (arm) Signed-off-by: Quentin Wolfs (quwo) --- addons/purchase_stock/models/purchase.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/purchase_stock/models/purchase.py b/addons/purchase_stock/models/purchase.py index 4f75a40560f..e07d1a220f0 100644 --- a/addons/purchase_stock/models/purchase.py +++ b/addons/purchase_stock/models/purchase.py @@ -236,6 +236,7 @@ class PurchaseOrder(models.Model): if not pickings: res = order._prepare_picking() picking = StockPicking.with_user(SUPERUSER_ID).create(res) + pickings = picking else: picking = pickings[0] moves = order.order_line._create_stock_moves(picking) @@ -245,6 +246,7 @@ class PurchaseOrder(models.Model): seq += 5 move.sequence = seq moves._action_assign() + pickings.action_confirm() picking.message_post_with_view('mail.message_origin_link', values={'self': picking, 'origin': order}, subtype_id=self.env.ref('mail.mt_note').id)