From 0ab71f124797912b3df39e748552741df430e4fc Mon Sep 17 00:00:00 2001 From: len-odoo Date: Tue, 7 Aug 2018 10:26:50 +0200 Subject: [PATCH] [FIX] stock, sale_stock: copy the to_refund field when splitting a move The to_refund attribute is set to copy=False. However when splitting a move to create a backorder, a new move is created as a copy with the remaining work to do. This attribute is needed so that the backorder refund is consistently applied. Essentially a backport of commit: https://github.com/odoo/odoo/commit/c5ffca151160f9d99bec036330def108e4e91e0b opw 1865324 --- addons/sale_stock/models/stock.py | 5 +++++ addons/stock/models/stock_move.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/addons/sale_stock/models/stock.py b/addons/sale_stock/models/stock.py index 054b070b152..c9514a22084 100644 --- a/addons/sale_stock/models/stock.py +++ b/addons/sale_stock/models/stock.py @@ -40,6 +40,11 @@ class StockMove(models.Model): subtype_id=self.env.ref('mail.mt_note').id) return result + def _prepare_move_split_vals(self, defaults): + defaults = super(StockMove, self)._prepare_move_split_vals(defaults) + defaults['to_refund_so'] = self.to_refund_so + return defaults + class StockPicking(models.Model): _inherit = 'stock.picking' diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 352392ccb7d..c170d2cc5fa 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -938,6 +938,10 @@ class StockMove(models.Model): new_move_prop = self.move_dest_id.split(qty) new_move.write({'move_dest_id': new_move_prop}) + def _prepare_move_split_vals(self, defaults): + # hook to add values in default vals in other modules + return defaults + @api.multi def split(self, qty, restrict_lot_id=False, restrict_partner_id=False): """ Splits qty from move move into a new move @@ -967,6 +971,9 @@ class StockMove(models.Model): 'move_dest_id': self.move_dest_id.id, 'origin_returned_move_id': self.origin_returned_move_id.id, } + + defaults = self._prepare_move_split_vals(defaults) + if restrict_partner_id: defaults['restrict_partner_id'] = restrict_partner_id