[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:
parent
31348b1e4a
commit
d1abe6a4cc
|
@ -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:
|
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))
|
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):
|
def _action_explode(self, cr, uid, move, context=None):
|
||||||
""" Explodes pickings.
|
""" Explodes pickings.
|
||||||
@param move: Stock moves
|
@param move: Stock moves
|
||||||
|
@ -59,10 +67,7 @@ class StockMove(osv.osv):
|
||||||
procurement_obj = self.pool.get('procurement.order')
|
procurement_obj = self.pool.get('procurement.order')
|
||||||
product_obj = self.pool.get('product.product')
|
product_obj = self.pool.get('product.product')
|
||||||
processed_ids = []
|
processed_ids = []
|
||||||
bis = bom_obj.search(cr, uid, [
|
bis = self._check_phantom_bom(cr, uid, move, context=context)
|
||||||
('product_id', '=', move.product_id.id),
|
|
||||||
('bom_id', '=', False),
|
|
||||||
('type', '=', 'phantom')])
|
|
||||||
if bis:
|
if bis:
|
||||||
factor = move.product_qty
|
factor = move.product_qty
|
||||||
bom_point = bom_obj.browse(cr, uid, bis[0], context=context)
|
bom_point = bom_obj.browse(cr, uid, bis[0], context=context)
|
||||||
|
@ -85,25 +90,31 @@ class StockMove(osv.osv):
|
||||||
processed_ids.append(mid)
|
processed_ids.append(mid)
|
||||||
|
|
||||||
move_obj.unlink(cr, SUPERUSER_ID, [move.id], context=context)
|
move_obj.unlink(cr, SUPERUSER_ID, [move.id], context=context)
|
||||||
#confirm all new confirm moves
|
#check if new moves needs to be exploded
|
||||||
move_obj.action_confirm(cr, uid, processed_ids, context=context)
|
if processed_ids:
|
||||||
return 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):
|
def action_confirm(self, cr, uid, ids, context=None):
|
||||||
move_exploded = []
|
move_ids = []
|
||||||
for move in self.browse(cr, uid, ids, context=context):
|
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!
|
#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
|
#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
|
#and that original move has been deleted, so we should remove that id
|
||||||
#from super call to prevent problem
|
#from super call to prevent problem
|
||||||
move_id = move.id
|
if move.picking_type_id:
|
||||||
if move.picking_type_id and self._action_explode(cr, uid, move, context=context):
|
move_ids.extend(self._action_explode(cr, uid, move, context=context))
|
||||||
move_exploded.append(move_id)
|
else:
|
||||||
#if no more id, don't call super
|
move_ids.append(move.id)
|
||||||
move_unexploded = list(set(ids)-set(move_exploded))
|
|
||||||
if not len(move_unexploded):
|
return super(StockMove, self).action_confirm(cr, uid, move_ids, context=context)
|
||||||
return True
|
|
||||||
return super(StockMove, self).action_confirm(cr, uid, move_unexploded, context=context)
|
|
||||||
|
|
||||||
def action_consume(self, cr, uid, ids, product_qty, location_id=False, restrict_lot_id=False, restrict_partner_id=False,
|
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):
|
consumed_for=False, context=None):
|
||||||
|
|
|
@ -751,7 +751,7 @@ class purchase_order(osv.osv):
|
||||||
move = stock_move.create(cr, uid, vals, context=context)
|
move = stock_move.create(cr, uid, vals, context=context)
|
||||||
todo_moves.append(move)
|
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)
|
stock_move.force_assign(cr, uid, todo_moves)
|
||||||
|
|
||||||
def test_moves_done(self, cr, uid, ids, context=None):
|
def test_moves_done(self, cr, uid, ids, context=None):
|
||||||
|
|
|
@ -207,8 +207,7 @@ class procurement_order(osv.osv):
|
||||||
move_obj = self.pool.get('stock.move')
|
move_obj = self.pool.get('stock.move')
|
||||||
move_dict = self._run_move_create(cr, uid, procurement, context=context)
|
move_dict = self._run_move_create(cr, uid, procurement, context=context)
|
||||||
move_id = move_obj.create(cr, uid, move_dict, 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_obj.action_confirm(cr, uid, [move_id], context=context)
|
||||||
return move_id
|
|
||||||
return super(procurement_order, self)._run(cr, uid, procurement, context)
|
return super(procurement_order, self)._run(cr, uid, procurement, context)
|
||||||
|
|
||||||
def _check(self, cr, uid, procurement, context=None):
|
def _check(self, cr, uid, procurement, context=None):
|
||||||
|
|
|
@ -859,9 +859,8 @@ class stock_picking(osv.osv):
|
||||||
todo = []
|
todo = []
|
||||||
for move in pick.move_lines:
|
for move in pick.move_lines:
|
||||||
if move.state == 'draft':
|
if move.state == 'draft':
|
||||||
self.pool.get('stock.move').action_confirm(cr, uid, [move.id],
|
todo.extend(self.pool.get('stock.move').action_confirm(cr, uid, [move.id],
|
||||||
context=context)
|
context=context))
|
||||||
todo.append(move.id)
|
|
||||||
elif move.state in ('assigned', 'confirmed'):
|
elif move.state in ('assigned', 'confirmed'):
|
||||||
todo.append(move.id)
|
todo.append(move.id)
|
||||||
if len(todo):
|
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)
|
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.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 self.action_confirm(cr, uid, [backorder_id], context=context)
|
||||||
return backorder_id
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def do_prepare_partial(self, cr, uid, picking_ids, context=None):
|
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)
|
new_move = stock_move_obj.split(cr, uid, move, move.remaining_qty, context=context)
|
||||||
todo_move_ids.append(move.id)
|
todo_move_ids.append(move.id)
|
||||||
#Assign move as it was assigned before
|
#Assign move as it was assigned before
|
||||||
toassign_move_ids.append(new_move)
|
toassign_move_ids.extend(new_move)
|
||||||
elif move.state:
|
elif move.state:
|
||||||
#this should never happens
|
#this should never happens
|
||||||
raise
|
raise
|
||||||
|
@ -1797,7 +1795,7 @@ class stock_move(osv.osv):
|
||||||
self._create_procurement(cr, uid, move, context=context)
|
self._create_procurement(cr, uid, move, context=context)
|
||||||
moves = self.browse(cr, uid, ids, context=context)
|
moves = self.browse(cr, uid, ids, context=context)
|
||||||
self._push_apply(cr, uid, moves, context=context)
|
self._push_apply(cr, uid, moves, context=context)
|
||||||
return True
|
return ids
|
||||||
|
|
||||||
def force_assign(self, cr, uid, ids, context=None):
|
def force_assign(self, cr, uid, ids, context=None):
|
||||||
""" Changes the state to assigned.
|
""" Changes the state to assigned.
|
||||||
|
@ -1901,7 +1899,7 @@ class stock_move(osv.osv):
|
||||||
pack_op_obj = self.pool.get("stock.pack.operation")
|
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"]
|
todo = [move.id for move in self.browse(cr, uid, ids, context=context) if move.state == "draft"]
|
||||||
if todo:
|
if todo:
|
||||||
self.action_confirm(cr, uid, todo, context=context)
|
ids = self.action_confirm(cr, uid, todo, context=context)
|
||||||
|
|
||||||
pickings = set()
|
pickings = set()
|
||||||
procurement_ids = []
|
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)
|
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.write(cr, uid, [new_move], {'move_dest_id': new_move_prop}, context=context)
|
||||||
|
|
||||||
self.action_confirm(cr, uid, [new_move], context=context)
|
return self.action_confirm(cr, uid, [new_move], context=context)
|
||||||
return new_move
|
|
||||||
|
|
||||||
|
|
||||||
class stock_inventory(osv.osv):
|
class stock_inventory(osv.osv):
|
||||||
|
@ -3101,8 +3098,7 @@ class stock_location_path(osv.osv):
|
||||||
move_obj.write(cr, uid, [move.id], {
|
move_obj.write(cr, uid, [move.id], {
|
||||||
'move_dest_id': move_id,
|
'move_dest_id': move_id,
|
||||||
})
|
})
|
||||||
move_obj.action_confirm(cr, uid, [move_id], context=None)
|
return move_obj.action_confirm(cr, uid, [move_id], context=None)
|
||||||
return move_id
|
|
||||||
|
|
||||||
class stock_move_putaway(osv.osv):
|
class stock_move_putaway(osv.osv):
|
||||||
_name = 'stock.move.putaway'
|
_name = 'stock.move.putaway'
|
||||||
|
|
Loading…
Reference in New Issue