diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 53693db61f8..a179b75bf8d 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -2349,6 +2349,7 @@ class stock_move(osv.osv): main_domain = {} todo_moves = [] operations = set() + ancestors_list = {} for move in self.browse(cr, uid, ids, context=context): if move.state not in ('confirmed', 'waiting', 'assigned'): continue @@ -2368,6 +2369,7 @@ class stock_move(osv.osv): #if the move is preceeded, restrict the choice of quants in the ones moved previously in original move ancestors = self.find_move_ancestors(cr, uid, move, context=context) + ancestors_list[move.id] = True if ancestors else False if move.state == 'waiting' and not ancestors: #if the waiting move hasn't yet any ancestor (PO/MO not confirmed yet), don't find any quant available in stock main_domain[move.id] += [('id', '=', False)] @@ -2392,6 +2394,10 @@ class stock_move(osv.osv): if qty: quants = quant_obj.quants_get_prefered_domain(cr, uid, ops.location_id, move.product_id, qty, domain=domain, prefered_domain_list=[], restrict_lot_id=move.restrict_lot_id.id, restrict_partner_id=move.restrict_partner_id.id, context=context) quant_obj.quants_reserve(cr, uid, quants, move, record, context=context) + + # Sort moves to reserve first the ones with ancestors, in case the same product is listed in + # different stock moves. + todo_moves.sort(key=lambda x: -1 if ancestors_list.get(x.id) else 0) for move in todo_moves: #then if the move isn't totally assigned, try to find quants without any specific domain if move.state != 'assigned': diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index a651c7d8bfa..cf57bd86d4f 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -854,7 +854,8 @@ var result_domain = []; // Normalize only if the first domain is the array ["|"] or ["!"] var need_normalization = ( - domains.length > 0 + domains + && domains.length > 0 && domains[0].length === 1 && (domains[0][0] === "|" || domains[0][0] === "!") ); diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index 9ad980e011a..ac26d3121f9 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -976,7 +976,9 @@ instance.web.ListView.List = instance.web.Class.extend( /** @lends instance.web. $row = self.$current.children( '[data-id=' + record.get('id') + ']'); } - $row.replaceWith(self.render_record(record)); + if ($row.length) { + $row.replaceWith(self.render_record(record)); + } }, 'add': function (ev, records, record, index) { var $new_row = $(self.render_record(record));