Search code examples
odooodoo-8odoo-9

Update context in old api


This is the original method but I want to call it with super and ad my context to it, but it's old API and I'm kinda confused here.

After move_scrap write method should be called, but nothing happens and write is not called

and with_context of course not working

class stock_move_scrap(osv.osv_memory):
    _name = "stock.move.scrap"
    _description = "Scrap Products"


  def move_scrap(self, cr, uid, ids, context=None):
    """ To move scrapped products
    @param self: The object pointer.
    @param cr: A database cursor
    @param uid: ID of the user currently logged in
    @param ids: the ID or list of IDs if we want more than one
    @param context: A standard dictionary
    @return:
    """
    if context is None:
        context = {}
    move_obj = self.pool.get('stock.move')
    move_ids = context['active_ids']
    for data in self.browse(cr, uid, ids):
        move_obj.action_scrap(cr, uid, move_ids,
                         data.product_qty, data.location_id.id, restrict_lot_id=data.restrict_lot_id.id,
                         context=context)
    if context.get('active_id'):
        move = self.pool.get('stock.move').browse(cr, uid, context['active_id'], context=context)
        if move.picking_id:
            return {
                'view_type': 'form',
                'view_mode': 'form',
                'res_model': 'stock.picking',
                'type': 'ir.actions.act_window',
                'res_id': move.picking_id.id,
                'context': context
            }
    return {'type': 'ir.actions.act_window_close'}

i did try something like this

 def move_scrap(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        ctx = context.copy()
        ctx['allow_scrap'] = True
        super(stock_move_scrap,self).move_scrap(cr, uid, [], context=ctx)

Solution

  • Your issue is that you are removing the ids from the super call by replacing the expected ids arg with []. Change you last line from:

    super(stock_move_scrap,self).move_scrap(cr, uid, [], context=ctx)
    

    to:

    super(stock_move_scrap,self).move_scrap(cr, uid, ids, context=ctx)