[FIX] stock, purchase: clean moves to merge
Purchase creates an activity when some stock move is deleted. Howver when two moves are merged "behind the scenes", some moves may be deleted. As a result it creates an activity "warning: some move has been deleted" for no good reason. We add a hook to clean moves before the merge. opw 1826791
This commit is contained in:
@@ -60,6 +60,10 @@ class StockMove(models.Model):
|
||||
vals['purchase_line_id'] = self.purchase_line_id.id
|
||||
return vals
|
||||
|
||||
def _clean_merged(self):
|
||||
super(StockMove, self)._clean_merged()
|
||||
self.write({'created_purchase_line_id': False})
|
||||
|
||||
def _action_cancel(self):
|
||||
for move in self:
|
||||
if move.created_purchase_line_id:
|
||||
|
||||
@@ -554,6 +554,10 @@ class StockMove(models.Model):
|
||||
move.product_uom.id, move.restrict_partner_id.id, move.scrapped, move.origin_returned_move_id.id
|
||||
]
|
||||
|
||||
def _clean_merged(self):
|
||||
"""Cleanup hook used when merging moves"""
|
||||
self.write({'propagate': False})
|
||||
|
||||
def _merge_moves(self, merge_into=False):
|
||||
""" This method will, for each move in `self`, go up in their linked picking and try to
|
||||
find in their existing moves a candidate into which we can merge the move.
|
||||
@@ -591,7 +595,7 @@ class StockMove(models.Model):
|
||||
|
||||
if moves_to_unlink:
|
||||
# We are using propagate to False in order to not cancel destination moves merged in moves[0]
|
||||
moves_to_unlink.write({'propagate': False})
|
||||
moves_to_unlink._clean_merged()
|
||||
moves_to_unlink._action_cancel()
|
||||
moves_to_unlink.sudo().unlink()
|
||||
return (self | self.env['stock.move'].concat(*moves_to_merge)) - moves_to_unlink
|
||||
|
||||
Reference in New Issue
Block a user