[FIX]move: action_confirm now returns ids of move (needed for bom_explode)

bzr revid: csn@openerp.com-20140210145446-djwfreh3f0pdcfet
This commit is contained in:
Cedric Snauwaert 2014-02-10 15:54:46 +01:00
parent 31348b1e4a
commit d1abe6a4cc
4 changed files with 37 additions and 31 deletions

View File

@ -49,6 +49,14 @@ class StockMove(osv.osv):
if move.raw_material_production_id and move.location_dest_id.usage == 'production' and move.raw_material_production_id.product_id.track_production and not move.consumed_for:
raise osv.except_osv(_('Warning!'), _("Because the product %s requires it, you must assign a serial number to your raw material %s to proceed further in your production. Please use the 'Produce' button to do so.") % (move.raw_material_production_id.product_id.name, move.product_id.name))
def _check_phantom_bom(self, cr, uid, move, context=None):
"""check if product associated to move has a phantom bom
return list of ids of mrp.bom for that product """
return self.pool.get('mrp.bom').search(cr, uid, [
('product_id', '=', move.product_id.id),
('bom_id', '=', False),
('type', '=', 'phantom')])
def _action_explode(self, cr, uid, move, context=None):
""" Explodes pickings.
@param move: Stock moves
@ -59,10 +67,7 @@ class StockMove(osv.osv):
procurement_obj = self.pool.get('procurement.order')
product_obj = self.pool.get('product.product')
processed_ids = []
bis = bom_obj.search(cr, uid, [
('product_id', '=', move.product_id.id),
('bom_id', '=', False),
('type', '=', 'phantom')])
bis = self._check_phantom_bom(cr, uid, move, context=context)
if bis:
factor = move.product_qty
bom_point = bom_obj.browse(cr, uid, bis[0], context=context)
@ -85,25 +90,31 @@ class StockMove(osv.osv):
processed_ids.append(mid)
move_obj.unlink(cr, SUPERUSER_ID, [move.id], context=context)
#confirm all new confirm moves
move_obj.action_confirm(cr, uid, processed_ids, context=context)
return processed_ids
#check if new moves needs to be exploded
if processed_ids:
for new_move in self.browse(cr, uid, processed_ids, context=context):
exploded_ids = self._action_explode(cr, uid, new_move, context=context)
if not (len(exploded_ids)==1 and exploded_ids[0]==new_move.id):
#we have some exploded move, delete parent move and add new moves
#to the list of processed ones
processed_ids.remove(move.id)
processed_ids.extend(exploded_ids)
#return list of newly created move or the move id otherwise
return processed_ids or [move.id]
def action_confirm(self, cr, uid, ids, context=None):
move_exploded = []
move_ids = []
for move in self.browse(cr, uid, ids, context=context):
#in order to explode a move, we must have a picking_id on that move!
#if action_explode return a list of new move, it means it has exploded
#and that original move has been deleted, so we should remove that id
#from super call to prevent problem
move_id = move.id
if move.picking_type_id and self._action_explode(cr, uid, move, context=context):
move_exploded.append(move_id)
#if no more id, don't call super
move_unexploded = list(set(ids)-set(move_exploded))
if not len(move_unexploded):
return True
return super(StockMove, self).action_confirm(cr, uid, move_unexploded, context=context)
if move.picking_type_id:
move_ids.extend(self._action_explode(cr, uid, move, context=context))
else:
move_ids.append(move.id)
return super(StockMove, self).action_confirm(cr, uid, move_ids, context=context)
def action_consume(self, cr, uid, ids, product_qty, location_id=False, restrict_lot_id=False, restrict_partner_id=False,
consumed_for=False, context=None):

View File

@ -751,7 +751,7 @@ class purchase_order(osv.osv):
move = stock_move.create(cr, uid, vals, context=context)
todo_moves.append(move)
stock_move.action_confirm(cr, uid, todo_moves)
todo_moves = stock_move.action_confirm(cr, uid, todo_moves)
stock_move.force_assign(cr, uid, todo_moves)
def test_moves_done(self, cr, uid, ids, context=None):

View File

@ -207,8 +207,7 @@ class procurement_order(osv.osv):
move_obj = self.pool.get('stock.move')
move_dict = self._run_move_create(cr, uid, procurement, context=context)
move_id = move_obj.create(cr, uid, move_dict, context=context)
move_obj.action_confirm(cr, uid, [move_id], context=context)
return move_id
return move_obj.action_confirm(cr, uid, [move_id], context=context)
return super(procurement_order, self)._run(cr, uid, procurement, context)
def _check(self, cr, uid, procurement, context=None):

View File

@ -859,9 +859,8 @@ class stock_picking(osv.osv):
todo = []
for move in pick.move_lines:
if move.state == 'draft':
self.pool.get('stock.move').action_confirm(cr, uid, [move.id],
context=context)
todo.append(move.id)
todo.extend(self.pool.get('stock.move').action_confirm(cr, uid, [move.id],
context=context))
elif move.state in ('assigned', 'confirmed'):
todo.append(move.id)
if len(todo):
@ -907,8 +906,7 @@ class stock_picking(osv.osv):
move_obj.write(cr, uid, backorder_move_ids, {'picking_id': backorder_id}, context=context)
self.write(cr, uid, [picking.id], {'date_done': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)}, context=context)
self.action_confirm(cr, uid, [backorder_id], context=context)
return backorder_id
return self.action_confirm(cr, uid, [backorder_id], context=context)
return False
def do_prepare_partial(self, cr, uid, picking_ids, context=None):
@ -1096,7 +1094,7 @@ class stock_picking(osv.osv):
new_move = stock_move_obj.split(cr, uid, move, move.remaining_qty, context=context)
todo_move_ids.append(move.id)
#Assign move as it was assigned before
toassign_move_ids.append(new_move)
toassign_move_ids.extend(new_move)
elif move.state:
#this should never happens
raise
@ -1797,7 +1795,7 @@ class stock_move(osv.osv):
self._create_procurement(cr, uid, move, context=context)
moves = self.browse(cr, uid, ids, context=context)
self._push_apply(cr, uid, moves, context=context)
return True
return ids
def force_assign(self, cr, uid, ids, context=None):
""" Changes the state to assigned.
@ -1901,7 +1899,7 @@ class stock_move(osv.osv):
pack_op_obj = self.pool.get("stock.pack.operation")
todo = [move.id for move in self.browse(cr, uid, ids, context=context) if move.state == "draft"]
if todo:
self.action_confirm(cr, uid, todo, context=context)
ids = self.action_confirm(cr, uid, todo, context=context)
pickings = set()
procurement_ids = []
@ -2054,8 +2052,7 @@ class stock_move(osv.osv):
new_move_prop = self.split(cr, uid, move.move_dest_id, qty, context=context)
self.write(cr, uid, [new_move], {'move_dest_id': new_move_prop}, context=context)
self.action_confirm(cr, uid, [new_move], context=context)
return new_move
return self.action_confirm(cr, uid, [new_move], context=context)
class stock_inventory(osv.osv):
@ -3101,8 +3098,7 @@ class stock_location_path(osv.osv):
move_obj.write(cr, uid, [move.id], {
'move_dest_id': move_id,
})
move_obj.action_confirm(cr, uid, [move_id], context=None)
return move_id
return move_obj.action_confirm(cr, uid, [move_id], context=None)
class stock_move_putaway(osv.osv):
_name = 'stock.move.putaway'