[MERGE] sale,purchase: better context passing during picking creation, courtesy of Akretion
Existing overriding modules also updated to use the new API bzr revid: odo@openerp.com-20111221153924-0a6nbc7r83tlu1jl
This commit is contained in:
commit
0d5bddc89f
|
@ -36,14 +36,12 @@ class sale_order(osv.osv):
|
|||
result['value']['carrier_id'] = dtype
|
||||
return result
|
||||
|
||||
def action_ship_create(self, cr, uid, ids, *args):
|
||||
result = super(sale_order, self).action_ship_create(cr, uid, ids, *args)
|
||||
for order in self.browse(cr, uid, ids, context={}):
|
||||
pids = [ x.id for x in order.picking_ids]
|
||||
self.pool.get('stock.picking').write(cr, uid, pids, {
|
||||
'carrier_id':order.carrier_id.id,
|
||||
})
|
||||
def _prepare_order_picking(self, cr, uid, order, context=None):
|
||||
result = super(sale_order, self)._prepare_order_picking(cr, uid, order, context=context)
|
||||
result.update(carrier_id=order.carrier_id.id)
|
||||
return result
|
||||
|
||||
|
||||
sale_order()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -57,9 +57,9 @@ product_product()
|
|||
class sale_order(osv.osv):
|
||||
_inherit ='sale.order'
|
||||
|
||||
def _prepare_order_line_procurement(self, cr, uid, order, line, move_id, date_planned, *args):
|
||||
def _prepare_order_line_procurement(self, cr, uid, order, line, move_id, date_planned, context=None):
|
||||
proc_data = super(sale_order, self)._prepare_order_line_procurement(cr,
|
||||
uid, order, line, move_id, date_planned, *args)
|
||||
uid, order, line, move_id, date_planned, context=context)
|
||||
proc_data['sale_line_id'] = line.id
|
||||
return proc_data
|
||||
|
||||
|
|
|
@ -426,7 +426,7 @@ class purchase_order(osv.osv):
|
|||
self.log(cr, uid, id, message)
|
||||
return True
|
||||
|
||||
def _prepare_order_picking(self, cr, uid, order, *args):
|
||||
def _prepare_order_picking(self, cr, uid, order, context=None):
|
||||
return {
|
||||
'name': self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.in'),
|
||||
'origin': order.name + ((order.origin and (':' + order.origin)) or ''),
|
||||
|
@ -439,7 +439,7 @@ class purchase_order(osv.osv):
|
|||
'move_lines' : [],
|
||||
}
|
||||
|
||||
def _prepare_order_line_move(self, cr, uid, order, order_line, picking_id, *args):
|
||||
def _prepare_order_line_move(self, cr, uid, order, order_line, picking_id, context=None):
|
||||
return {
|
||||
'name': order.name + ': ' + (order_line.name or ''),
|
||||
'product_id': order_line.product_id.id,
|
||||
|
@ -460,7 +460,7 @@ class purchase_order(osv.osv):
|
|||
'price_unit': order_line.price_unit
|
||||
}
|
||||
|
||||
def _create_pickings(self, cr, uid, order, order_lines, picking_id=False, *args):
|
||||
def _create_pickings(self, cr, uid, order, order_lines, picking_id=False, context=None):
|
||||
"""Creates pickings and appropriate stock moves for given order lines, then
|
||||
confirms the moves, makes them available, and confirms the picking.
|
||||
|
||||
|
@ -480,7 +480,7 @@ class purchase_order(osv.osv):
|
|||
:return: list of IDs of pickings used/created for the given order lines (usually just one)
|
||||
"""
|
||||
if not picking_id:
|
||||
picking_id = self.pool.get('stock.picking').create(cr, uid, self._prepare_order_picking(cr, uid, order, *args))
|
||||
picking_id = self.pool.get('stock.picking').create(cr, uid, self._prepare_order_picking(cr, uid, order, context=context))
|
||||
todo_moves = []
|
||||
stock_move = self.pool.get('stock.move')
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
|
@ -488,7 +488,7 @@ class purchase_order(osv.osv):
|
|||
if not order_line.product_id:
|
||||
continue
|
||||
if order_line.product_id.type in ('product', 'consu'):
|
||||
move = stock_move.create(cr, uid, self._prepare_order_line_move(cr, uid, order, order_line, picking_id, *args))
|
||||
move = stock_move.create(cr, uid, self._prepare_order_line_move(cr, uid, order, order_line, picking_id, context=context))
|
||||
if order_line.move_dest_id:
|
||||
order_line.move_dest_id.write({'location_id': order.location_id.id})
|
||||
todo_moves.append(move)
|
||||
|
@ -497,10 +497,10 @@ class purchase_order(osv.osv):
|
|||
wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr)
|
||||
return [picking_id]
|
||||
|
||||
def action_picking_create(self,cr, uid, ids, *args):
|
||||
def action_picking_create(self,cr, uid, ids, context=None):
|
||||
picking_ids = []
|
||||
for order in self.browse(cr, uid, ids):
|
||||
picking_ids.extend(self._create_pickings(cr, uid, order, order.order_line, None, *args))
|
||||
picking_ids.extend(self._create_pickings(cr, uid, order, order.order_line, None, context=context))
|
||||
|
||||
# Must return one unique picking ID: the one to connect in the subflow of the purchase order.
|
||||
# In case of multiple (split) pickings, we should return the ID of the critical one, i.e. the
|
||||
|
|
|
@ -685,7 +685,7 @@ class sale_order(osv.osv):
|
|||
return False
|
||||
return canceled
|
||||
|
||||
def _prepare_order_line_procurement(self, cr, uid, order, line, move_id, date_planned, *args):
|
||||
def _prepare_order_line_procurement(self, cr, uid, order, line, move_id, date_planned, context=None):
|
||||
return {
|
||||
'name': line.name,
|
||||
'origin': order.name,
|
||||
|
@ -706,7 +706,7 @@ class sale_order(osv.osv):
|
|||
'company_id': order.company_id.id,
|
||||
}
|
||||
|
||||
def _prepare_order_line_move(self, cr, uid, order, line, picking_id, date_planned, *args):
|
||||
def _prepare_order_line_move(self, cr, uid, order, line, picking_id, date_planned, context=None):
|
||||
location_id = order.shop_id.warehouse_id.lot_stock_id.id
|
||||
output_id = order.shop_id.warehouse_id.lot_output_id.id
|
||||
return {
|
||||
|
@ -733,7 +733,7 @@ class sale_order(osv.osv):
|
|||
'price_unit': line.product_id.standard_price or 0.0
|
||||
}
|
||||
|
||||
def _prepare_order_picking(self, cr, uid, order, *args):
|
||||
def _prepare_order_picking(self, cr, uid, order, context=None):
|
||||
pick_name = self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.out')
|
||||
return {
|
||||
'name': pick_name,
|
||||
|
@ -771,12 +771,12 @@ class sale_order(osv.osv):
|
|||
self.pool.get('procurement.order').write(cr, uid, [proc_id], {'product_qty': mov.product_qty, 'product_uos_qty': mov.product_uos_qty})
|
||||
return True
|
||||
|
||||
def _get_date_planned(self, cr, uid, order, line, start_date, *args):
|
||||
def _get_date_planned(self, cr, uid, order, line, start_date, context=None):
|
||||
date_planned = datetime.strptime(start_date, DEFAULT_SERVER_DATE_FORMAT) + relativedelta(days=line.delay or 0.0)
|
||||
date_planned = (date_planned - timedelta(days=order.company_id.security_lead)).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
return date_planned
|
||||
|
||||
def _create_pickings_and_procurements(self, cr, uid, order, order_lines, picking_id=False, *args):
|
||||
def _create_pickings_and_procurements(self, cr, uid, order, order_lines, picking_id=False, context=None):
|
||||
"""Create the required procurements to supply sale order lines, also connecting
|
||||
the procurements to appropriate stock moves in order to bring the goods to the
|
||||
sale order's requested location.
|
||||
|
@ -804,18 +804,18 @@ class sale_order(osv.osv):
|
|||
if line.state == 'done':
|
||||
continue
|
||||
|
||||
date_planned = self._get_date_planned(cr, uid, order, line, order.date_order, *args)
|
||||
date_planned = self._get_date_planned(cr, uid, order, line, order.date_order, context=context)
|
||||
|
||||
if line.product_id:
|
||||
if line.product_id.product_tmpl_id.type in ('product', 'consu'):
|
||||
if not picking_id:
|
||||
picking_id = picking_obj.create(cr, uid, self._prepare_order_picking(cr, uid, order, *args))
|
||||
move_id = move_obj.create(cr, uid, self._prepare_order_line_move(cr, uid, order, line, picking_id, date_planned, *args))
|
||||
picking_id = picking_obj.create(cr, uid, self._prepare_order_picking(cr, uid, order, context=context))
|
||||
move_id = move_obj.create(cr, uid, self._prepare_order_line_move(cr, uid, order, line, picking_id, date_planned, context=context))
|
||||
else:
|
||||
# a service has no stock move
|
||||
move_id = False
|
||||
|
||||
proc_id = procurement_obj.create(cr, uid, self._prepare_order_line_procurement(cr, uid, order, line, move_id, date_planned, *args))
|
||||
proc_id = procurement_obj.create(cr, uid, self._prepare_order_line_procurement(cr, uid, order, line, move_id, date_planned, context=context))
|
||||
proc_ids.append(proc_id)
|
||||
line.write({'procurement_id': proc_id})
|
||||
self.ship_recreate(cr, uid, order, line, move_id, proc_id)
|
||||
|
@ -840,9 +840,9 @@ class sale_order(osv.osv):
|
|||
order.write(val)
|
||||
return True
|
||||
|
||||
def action_ship_create(self, cr, uid, ids, *args):
|
||||
for order in self.browse(cr, uid, ids, context={}):
|
||||
self._create_pickings_and_procurements(cr, uid, order, order.order_line, None, *args)
|
||||
def action_ship_create(self, cr, uid, ids, context=None):
|
||||
for order in self.browse(cr, uid, ids, context=context):
|
||||
self._create_pickings_and_procurements(cr, uid, order, order.order_line, None, context=context)
|
||||
return True
|
||||
|
||||
def action_ship_end(self, cr, uid, ids, context=None):
|
||||
|
|
|
@ -66,14 +66,10 @@ class sale(osv.osv):
|
|||
_columns = {
|
||||
'invoice_type_id': fields.many2one('sale_journal.invoice.type', 'Invoice Type')
|
||||
}
|
||||
def action_ship_create(self, cr, uid, ids, *args):
|
||||
result = super(sale, self).action_ship_create(cr, uid, ids, *args)
|
||||
obj_stock_pick = self.pool.get('stock.picking')
|
||||
for order in self.browse(cr, uid, ids, context={}):
|
||||
pids = [ x.id for x in order.picking_ids]
|
||||
self.pool.get('stock.picking').write(cr, uid, pids, {
|
||||
'invoice_type_id': order.invoice_type_id and order.invoice_type_id.id or False,
|
||||
})
|
||||
|
||||
def _prepare_order_picking(self, cr, uid, order, context=None):
|
||||
result = super(sale,self)._prepare_order_picking(cr, uid, order, context=context)
|
||||
result.update(invoice_type_id=order.invoice_type_id and order.invoice_type_id.id or False)
|
||||
return result
|
||||
|
||||
def onchange_partner_id(self, cr, uid, ids, part):
|
||||
|
|
Loading…
Reference in New Issue