diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py index 94a0913ca29..ff59fcd5118 100644 --- a/addons/mrp/stock.py +++ b/addons/mrp/stock.py @@ -100,7 +100,7 @@ class StockMove(osv.osv): procurement_obj.signal_button_wait_done(cr, uid, procurement_ids) return processed_ids - def action_consume(self, cr, uid, ids, product_qty, location_id=False, restrict_lot_id = False, context=None): + def action_consume(self, cr, uid, ids, product_qty, location_id=False, restrict_lot_id = False, restrict_partner_id = False, context=None): """ Consumed product with specific quatity from specific source location. @param product_qty: Consumed product quantity @param location_id: Source location @@ -110,7 +110,8 @@ class StockMove(osv.osv): production_obj = self.pool.get('mrp.production') for move in self.browse(cr, uid, ids, context=context): self.action_confirm(cr, uid, [move.id], context=context) - new_moves = super(StockMove, self).action_consume(cr, uid, [move.id], product_qty, location_id, restrict_lot_id = restrict_lot_id, context=context) + new_moves = super(StockMove, self).action_consume(cr, uid, [move.id], product_qty, location_id, restrict_lot_id = restrict_lot_id, + restrict_partner_id = restrict_partner_id, context=context) production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])]) for prod in production_obj.browse(cr, uid, production_ids, context=context): if prod.state == 'confirmed': @@ -124,7 +125,7 @@ class StockMove(osv.osv): res.append(new_move) return res - def action_scrap(self, cr, uid, ids, product_qty, location_id, context=None): + def action_scrap(self, cr, uid, ids, product_qty, location_id, restrict_lot_id = False, restrict_partner_id = False, context=None): """ Move the scrap/damaged product into scrap location @param product_qty: Scraped product quantity @param location_id: Scrap location @@ -133,7 +134,9 @@ class StockMove(osv.osv): res = [] production_obj = self.pool.get('mrp.production') for move in self.browse(cr, uid, ids, context=context): - new_moves = super(StockMove, self).action_scrap(cr, uid, [move.id], product_qty, location_id, context=context) + new_moves = super(StockMove, self).action_scrap(cr, uid, [move.id], product_qty, location_id, + restrict_lot_id = restrict_lot_id, + restrict_partner_id = restrict_partner_id, context=context) #If we are not scrapping our whole move, tracking and lot references must not be removed production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])]) for prod_id in production_ids: diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 91feb16bca5..351c78a40c1 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -818,11 +818,11 @@ class stock_picking(osv.osv): return True def cancel_assign(self, cr, uid, ids, context=None): - """ Cancels picking and moves. + """ Cancels picking for the moves that are in the assigned state @return: True """ for pick in self.browse(cr, uid, ids, context=context): - move_ids = [x.id for x in pick.move_lines] + move_ids = [x.id for x in pick.move_lines if x not in ['done', 'cancel']] self.pool.get('stock.move').cancel_assign(cr, uid, move_ids, context=context) return True @@ -1821,7 +1821,7 @@ class stock_move(osv.osv): if qty > 0: self.check_tracking(cr, uid, move, move.restrict_lot_id.id, context=context) quants = quant_obj.quants_get_prefered_domain(cr, uid, move.location_id, move.product_id, qty, domain=main_domain, prefered_domain=prefered_domain, fallback_domain=fallback_domain, restrict_lot_id=move.restrict_lot_id.id, restrict_partner_id=move.restrict_partner_id.id, context=context) - quant_obj.quants_move(cr, uid, quants, move, context=context) + quant_obj.quants_move(cr, uid, quants, move, lot_id = move.restrict_lot_id.id, owner_id = move.restrict_partner_id.id, context=context) #unreserve the quants and make them available for other operations/moves quant_obj.quants_unreserve(cr, uid, move, context=context) @@ -1852,7 +1852,7 @@ class stock_move(osv.osv): raise osv.except_osv(_('User Error!'), _('You can only delete draft moves.')) return super(stock_move, self).unlink(cr, uid, ids, context=context) - def action_scrap(self, cr, uid, ids, quantity, location_id, restrict_lot_id=False, context=None): + def action_scrap(self, cr, uid, ids, quantity, location_id, restrict_lot_id=False, restrict_partner_id=False, context=None): """ Move the scrap/damaged product into scrap location @param cr: the database cursor @param uid: the user id @@ -1884,6 +1884,7 @@ class stock_move(osv.osv): 'scrapped': True, 'location_dest_id': location_id, 'restrict_lot_id': restrict_lot_id, + 'restrict_partner_id': restrict_partner_id, } new_move = self.copy(cr, uid, move.id, default_val) @@ -1898,7 +1899,7 @@ class stock_move(osv.osv): self.action_done(cr, uid, res, context=context) return res - def action_consume(self, cr, uid, ids, quantity, location_id=False, restrict_lot_id=False, context=None): + def action_consume(self, cr, uid, ids, quantity, location_id=False, restrict_lot_id=False, restrict_partner_id=False, context=None): """ Consumed product with specific quantity from specific source location. This correspond to a split of the move (or write if the quantity to consume is >= than the quantity of the move) followed by an action_done @param ids: ids of stock move object to be consumed @param quantity : specify consume quantity (given in move UoM) @@ -1921,16 +1922,18 @@ class stock_move(osv.osv): ctx = context.copy() if location_id: ctx['source_location_id'] = location_id - res.append(self.split(cr, uid, move, move_qty - quantity_rest, restrict_lot_id=restrict_lot_id, context=ctx)) + res.append(self.split(cr, uid, move, move_qty - quantity_rest, restrict_lot_id=restrict_lot_id, + restrict_partner_id = restrict_partner_id, context=ctx)) else: res.append(move.id) if location_id: - self.write(cr, uid, [move.id], {'location_id': location_id, 'restrict_lot_id': restrict_lot_id}, context=context) + self.write(cr, uid, [move.id], {'location_id': location_id, 'restrict_lot_id': restrict_lot_id, + 'restrict_partner_id': restrict_partner_id}, context=context) self.action_done(cr, uid, res, context=context) return res - def split(self, cr, uid, move, qty, restrict_lot_id=False, context=None): + 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 :param qty: float. quantity to split (given in product UoM) @@ -1956,6 +1959,7 @@ class stock_move(osv.osv): 'move_dest_id': False, 'reserved_quant_ids': [], 'restrict_lot_id': restrict_lot_id, + 'restrict_partner_id': restrict_partner_id } if context.get('source_location_id'): defaults['location_id'] = context['source_location_id'] diff --git a/addons/stock/wizard/stock_move_view.xml b/addons/stock/wizard/stock_move_view.xml index f8121a89ee9..0a567be651e 100644 --- a/addons/stock/wizard/stock_move_view.xml +++ b/addons/stock/wizard/stock_move_view.xml @@ -15,7 +15,8 @@ - +