[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.
This commit is contained in:
@@ -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.')
|
||||
|
||||
@@ -296,7 +296,7 @@
|
||||
<field name="product_uom_qty" string="Initial Demand" attrs="{'readonly': [('is_initial_demand_editable', '=', False), ('state', '!=', 'draft')]}"/>
|
||||
<field name="product_uom" attrs="{'readonly': [('state', '!=', 'draft'), ('additional', '=', False)]}" options="{'no_open': True, 'no_create': True}" string="Unit of Measure" groups="product.group_uom"/>
|
||||
<field name="reserved_availability" string="Reserved"/>
|
||||
<field name="quantity_done" string="Done" attrs="{'readonly': [('show_details_visible', '=', True)], 'invisible': ['|', ('state', 'in', ['draft', 'confirmed', 'waiting']), ('show_operations', '=', True)]}"/>
|
||||
<field name="quantity_done" string="Done" attrs="{'readonly': ['|', ('show_details_visible', '=', True), ('state', '=', 'cancel')], 'invisible': ['|', ('state', 'in', ['draft', 'confirmed', 'waiting']), ('show_operations', '=', True)]}"/>
|
||||
<button name="action_show_details" string="Register lots, packs, location" type="object" icon="fa-list" attrs="{'invisible': [('show_details_visible', '=', False)]}"/>
|
||||
</tree>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user