From 13f0615b8077b8b665a8978ab4db4f2a746355b3 Mon Sep 17 00:00:00 2001 From: amoyaux Date: Fri, 11 Aug 2017 13:04:07 +0200 Subject: [PATCH] [IMP] purchase : Decrease order quantity should not delete picking and moves When deacreasing a quantity on a PO it will decrease the quantity of an associated move. When the move's quantity reach 0, previously the move was unlinked and aslo the picking if all moves inside were unlinked. However the destination move(s) still exist with the quantity that has been removed in the original move. It can confuse the end user which have a move without origin. This commit cancel the move/picking instead of unlink them. Thanks to this the end user still have the link with the original moves and can guess from where their destinations moves come from. It also remove the filter on PO in order to display the canceled picking. --- addons/purchase/models/purchase.py | 8 +------- addons/stock/views/stock_picking_views.xml | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 7ad2a86ae5e..9c8c9b00f57 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -85,7 +85,6 @@ class PurchaseOrder(models.Model): # We keep a limited scope on purpose. Ideally, we should also use move_orig_ids and # do some recursive search, but that could be prohibitive if not done correctly. moves = line.move_ids | line.move_ids.mapped('returned_move_ids') - moves = moves.filtered(lambda r: r.state != 'cancel') pickings |= moves.mapped('picking_id') order.picking_ids = pickings order.picking_count = len(pickings) @@ -666,12 +665,7 @@ class PurchaseOrderLine(models.Model): break else: diff_qty += move.product_qty - move.do_unreserve() - move.state = 'draft' - picking = move.picking_id - move.unlink() - if not picking.move_lines: - picking.unlink() + move.action_cancel() else: raise UserError('You cannot decrease the ordered quantity below the received quantity.\n' 'Create a return first.') diff --git a/addons/stock/views/stock_picking_views.xml b/addons/stock/views/stock_picking_views.xml index 66b287e8cab..ac9c856bdb3 100644 --- a/addons/stock/views/stock_picking_views.xml +++ b/addons/stock/views/stock_picking_views.xml @@ -296,7 +296,7 @@ - +