From cb4070d392c2f621c6bc99d1bf53f8abf6c390ed Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 14 Feb 2014 11:14:20 +0100 Subject: [PATCH 1/4] [IMP] In action_confirm, take into account split moves bzr revid: jco@openerp.com-20140214101420-64k7rmw1s7r58xff --- addons/stock/stock.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 5e409242f50..9082bab9a2f 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1776,8 +1776,15 @@ class stock_move(osv.osv): for move in self.browse(cr, uid, ids, context=context): state = 'confirmed' for m in move.move_orig_ids: - if m.state not in ('done', 'cancel'): + if move.move_orig_ids: state = 'waiting' + elif move.split_from: + move2 = move.split_from + while move2 and state != 'waiting': + if move2.move_orig_ids: + state = 'waiting' + move2 = move2.split_from + states[state].append(move.id) self._picking_assign(cr, uid, move, context=context) From 9dfcc007b0ed3bcd84b21946f2598c7aa12a7579 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 14 Feb 2014 11:18:47 +0100 Subject: [PATCH 2/4] [IMP] In action_assign, take into account split moves and consider mto as mto. Can be forced afterwards bzr revid: jco@openerp.com-20140214101847-jj20512nl0mey1w9 --- addons/stock/stock.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 9082bab9a2f..326ca787d98 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1842,6 +1842,16 @@ class stock_move(osv.osv): fallback_domain = prev_quant_ids and [('id', 'not in', prev_quant_ids)] or [] #we always keep the quants already assigned and try to find the remaining quantity on quants not assigned only main_domain = [('reservation_id', '=', False), ('qty', '>', 0)] + #Check for original moves + move_orig_ids = [] + result = False + move2 = move + while move2: + move_orig_ids += [x.id for x in move2.move_orig_ids] + move2 = move2.split_from + if move_orig_ids: + main_domain += [('history_ids', 'in', move_orig_ids)] + #if the move is returned from another, restrict the choice of quants to the ones that follow the returned move if move.origin_returned_move_id: main_domain += [('history_ids', 'in', move.origin_returned_move_id.id)] From 6cf485fc5c6d79dace9bacdb4fd03aaf7ff0afa6 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 14 Feb 2014 11:24:26 +0100 Subject: [PATCH 3/4] [IMP] Do not take into account package check for negative quants and no make to stock for split by default bzr revid: jco@openerp.com-20140214102426-o0njdd3fnme9f54p --- addons/stock/stock.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 326ca787d98..bcb3261675f 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1903,7 +1903,7 @@ class stock_move(osv.osv): pack_obj = self.pool.get("stock.quant.package") packs = set() for move in self.browse(cr, uid, ids, context=context): - packs |= set([q.package_id.id for q in move.quant_ids if q.package_id]) + packs |= set([q.package_id.id for q in move.quant_ids if q.package_id and q.qty > 0]) return pack_obj._check_location_constraint(cr, uid, list(packs), context=context) def action_done(self, cr, uid, ids, context=None): @@ -2065,7 +2065,6 @@ class stock_move(osv.osv): 'product_uom_qty': uom_qty, 'product_uos_qty': uos_qty, 'state': move.state, - 'procure_method': 'make_to_stock', 'move_dest_id': False, 'reserved_quant_ids': [], 'restrict_lot_id': restrict_lot_id, @@ -3259,7 +3258,7 @@ class stock_package(osv.osv): quant_ids = self.get_content(cr, uid, [parent.id], context=context) quants = quant_obj.browse(cr, uid, quant_ids, context=context) location_id = quants and quants[0].location_id.id or False - if not all([quant.location_id.id == location_id for quant in quants]): + if not all([quant.location_id.id == location_id for quant in quants if quant.qty > 0]): raise osv.except_osv(_('Error'), _('Everything inside a package should be in the same location')) return True From ef372a6bd0a447849d3c80963c85f15c5b4a6ff3 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Tue, 18 Feb 2014 10:31:49 +0100 Subject: [PATCH 4/4] [FIX] stock: fixes + comments made during code review bzr revid: qdp-launchpad@openerp.com-20140218093149-pg751zobmpied10f --- addons/stock/stock.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index bcb3261675f..36ad25da981 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1775,15 +1775,16 @@ class stock_move(osv.osv): } for move in self.browse(cr, uid, ids, context=context): state = 'confirmed' - for m in move.move_orig_ids: - if move.move_orig_ids: - state = 'waiting' - elif move.split_from: - move2 = move.split_from - while move2 and state != 'waiting': - if move2.move_orig_ids: - state = 'waiting' - move2 = move2.split_from + #if the move is preceeded, then it's waiting (if preceeding move is done, then action_assign has been called already and its state is already available) + if move.move_orig_ids: + state = 'waiting' + #if the move is split and some of the ancestor was preceeded, then it's waiting as well + elif move.split_from: + move2 = move.split_from + while move2 and state != 'waiting': + if move2.move_orig_ids: + state = 'waiting' + move2 = move2.split_from states[state].append(move.id) self._picking_assign(cr, uid, move, context=context) @@ -1842,11 +1843,12 @@ class stock_move(osv.osv): fallback_domain = prev_quant_ids and [('id', 'not in', prev_quant_ids)] or [] #we always keep the quants already assigned and try to find the remaining quantity on quants not assigned only main_domain = [('reservation_id', '=', False), ('qty', '>', 0)] - #Check for original moves + + #if the move is preceeded, restrict the choice of quants in the ones moved previously in original move move_orig_ids = [] - result = False move2 = move while move2: + #loop on the split_from to find the ancestor of split moves move_orig_ids += [x.id for x in move2.move_orig_ids] move2 = move2.split_from if move_orig_ids: @@ -2042,7 +2044,6 @@ class stock_move(osv.osv): self.action_done(cr, uid, res, context=context) return res - def split(self, cr, uid, move, qty, restrict_lot_id=False, restrict_partner_id=False, context=None): """ Splits qty from move move into a new move :param move: browse record @@ -2065,6 +2066,7 @@ class stock_move(osv.osv): 'product_uom_qty': uom_qty, 'product_uos_qty': uos_qty, 'state': move.state, + 'procure_method': 'make_to_stock', 'move_dest_id': False, 'reserved_quant_ids': [], 'restrict_lot_id': restrict_lot_id,