summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Taferner <wtaferner@users.noreply.github.com>2017-10-17 11:50:22 +0200
committerSimon Lejeune <sle@openerp.com>2017-10-18 17:52:19 +0200
commitef592ffa3d1bbeab910cc66fca4028c978d9446e (patch)
treeb97e5e12ce76dbb295e269781fa37c3fd416ca65
parent47b8887ff5fd2904d542da8563dcbfb6bcf92dc3 (diff)
[FIX] stock: make it possible to inherit easier in _merge_moves
-rw-r--r--addons/stock/models/stock_move.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py
index 47f3a99637a..f37554cf583 100644
--- a/addons/stock/models/stock_move.py
+++ b/addons/stock/models/stock_move.py
@@ -514,25 +514,35 @@ class StockMove(models.Model):
'origin': origin,
}
+ @api.model
+ def _prepare_merge_moves_distinct_fields(self):
+ return [
+ 'product_id', 'price_unit', 'product_packaging',
+ 'product_uom', 'restrict_partner_id', 'scrapped', 'origin_returned_move_id'
+ ]
+
+ @api.model
+ def _prepare_merge_move_sort_method(self, move):
+ move.ensure_one()
+ return [
+ move.product_id.id, move.price_unit, move.product_packaging.id, move.product_uom.id,
+ move.restrict_partner_id.id, move.scrapped, move.origin_returned_move_id.id
+ ]
+
def _merge_moves(self):
""" 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.
:return: Recordset of moves passed to this method. If some of the passed moves were merged
into another existing one, return this one and not the (now unlinked) original.
"""
- distinct_fields = ['product_id', 'price_unit', 'product_packaging',
- 'product_uom', 'restrict_partner_id', 'scrapped', 'origin_returned_move_id']
-
- def _keys_sorted(move):
- return move.product_id.id, move.price_unit, move.product_packaging.id, move.product_uom.id,\
- move.restrict_partner_id.id, move.scrapped, move.origin_returned_move_id.id
+ distinct_fields = self._prepare_merge_moves_distinct_fields()
# Move removed after merge
moves_to_unlink = self.env['stock.move']
moves_to_merge = []
for picking in self.mapped('picking_id'):
# First step find move to merge.
- for k, g in groupby(sorted(picking.move_lines, key=_keys_sorted), key=itemgetter(*distinct_fields)):
+ for k, g in groupby(sorted(picking.move_lines, key=self._prepare_merge_move_sort_method), key=itemgetter(*distinct_fields)):
moves = self.env['stock.move'].concat(*g).filtered(lambda m: m.state not in ('done', 'cancel', 'draft'))
# If we have multiple records we will merge then in a single one.
if len(moves) > 1: