[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:
len-odoo
2018-08-06 10:17:25 +02:00
committed by len-odoo
parent 85e8d13768
commit 34d1ecd6f3
2 changed files with 9 additions and 1 deletions
+4
View File
@@ -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:
+5 -1
View File
@@ -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