[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) <arm@odoo.com>
Signed-off-by: Quentin Wolfs (quwo) <quwo@odoo.com>
This commit is contained in:
clesgow
2022-09-02 15:28:05 +02:00
parent 4e6e3e6261
commit ddfbfddf3c
+2
View File
@@ -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)