代码之家  ›  专栏  ›  技术社区  ›  Chaban33

更新旧api中的上下文

  •  0
  • Chaban33  · 技术社区  · 7 年前

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

    之后 move_scrap write 未调用

    当然,在这种情况下,这是行不通的

    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)
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   aekis.dev    7 年前

    您的问题是,将预期的ids arg替换为[],从而从超级调用中删除ids。

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

    收件人:

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