更新旧 api 中的上下文

Update context in old api

这是原始方法,但我想用 super 调用它并将我的上下文添加到它,但它是旧的 API,我在这里有点困惑。

move_scrap 之后应该调用 write 方法,但是没有任何反应并且没有调用 write

和with_context当然不行

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'}

我确实尝试过这样的事情

 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)

您的问题是您通过将预期的 ID arg 替换为 [] 从 super 调用中删除了 ID。 更改你的最后一行:

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

至:

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