[FIX] purchase_stock: use correct picking when updating purchase qty

Before the fix, the picking used to create the new stock moves resulting
from changes in the purchased quantity is simply taking the first
available picking of the Purchase. This causes problems when you handle
Purchase Orders with multiple open pickings, as the correct picking to
use when the quantity is updated is not always taken.

After the fix we give priority to evaluate open pickings already related
to the line we are updating. We fallback to the same behaviour as before
is none is available.

closes odoo/odoo#161721

X-original-commit: b3335566a878fd2df29ff02023033acd3cabef70
Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
This commit is contained in:
JordiMForgeFlow
2024-04-22 08:27:06 +00:00
parent dbc760b68c
commit c35df66c8f
@@ -172,8 +172,13 @@ class PurchaseOrderLine(models.Model):
note=_('The quantities on your purchase order indicate less than billed. You should ask for a refund.'))
# If the user increased quantity of existing line or created a new line
pickings = line.order_id.picking_ids.filtered(lambda x: x.state not in ('done', 'cancel') and x.location_dest_id.usage in ('internal', 'transit', 'customer'))
picking = pickings and pickings[0] or False
# Give priority to the pickings related to the line
line_pickings = line.move_ids.picking_id.filtered(lambda p: p.state not in ('done', 'cancel') and p.location_dest_id.usage in ('internal', 'transit', 'customer'))
if line_pickings:
picking = line_pickings[0]
else:
pickings = line.order_id.picking_ids.filtered(lambda x: x.state not in ('done', 'cancel') and x.location_dest_id.usage in ('internal', 'transit', 'customer'))
picking = pickings and pickings[0] or False
if not picking:
if not line.product_qty > line.qty_received:
continue