diff --git a/addons/purchase/models/stock.py b/addons/purchase/models/stock.py index f312fa91c6d..5399c15c0d2 100644 --- a/addons/purchase/models/stock.py +++ b/addons/purchase/models/stock.py @@ -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: diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 1df578b7c40..7b5ee057159 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -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