NotImplementedError:frozendi不支持“pop”

2024-05-19 09:46:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为Odoo v9社区修改一个模块

它使用frozendict,但每次我尝试使用某个功能时,它都会抛出:

NotImplementedError: 'pop' not supported on frozendict

代码如下:

^{pr2}$

this之后,我将以下代码添加到行:

if context is None:
    context = {}
    journal_obj = self.pool.get('account.journal')
    user_obj = self.pool.get('res.users')
    context=dict(context)
    context.pop('form_view_ref', None)
    res = super(AccountInvoiceRefund, self).\

而不是:

if context is None:
    context = {}
    journal_obj = self.pool.get('account.journal')
    user_obj = self.pool.get('res.users')
    context.pop('form_view_ref', None)
    res = super(AccountInvoiceRefund, self).\

如您所见,我添加了context=dict(context),但仍然得到相同的错误。在

有什么想法吗?在

提前谢谢!在


Tags: 代码selfnoneobjgetifiscontext
2条回答

解决这个问题的一个快速方法是将冻结的字典复制到另一个字典中,然后将该字典作为参数传递给该方法,或者如果您使用的是新api,则使用“with_context”方法。在

下面是一个例子:

ctx = dict(self._context)
self.with_context(ctx).write({'invoice_line': []})

正如您在上面的示例中看到的那样,\u上下文被复制到ctx,然后使用with_context传递新的修改后的上下文。在

上下文是不能直接修改的frozendict对象。据我所知,这已经在版本9上实现了

如果要修改代码中的上下文,必须使用Odoo的API提供的方法,请查看第5460行中名为with_context的方法的定义。你可以找到它的源文件和它是如何使用足够多的文件。在

相关问题 更多 >

    热门问题