Python 未实施错误:';流行音乐';frozendict上不支持
我正在为奥多v9社区改编一个模块 它使用frozendict,但每次我尝试使用某个功能时,它都会抛出:Python 未实施错误:';流行音乐';frozendict上不支持,python,openerp,odoo-9,Python,Openerp,Odoo 9,我正在为奥多v9社区改编一个模块 它使用frozendict,但每次我尝试使用某个功能时,它都会抛出: NotImplementedError: 'pop' not supported on frozendict 代码如下: def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False): i
NotImplementedError: 'pop' not supported on frozendict
代码如下:
def fields_view_get(self, cr, uid, view_id=None, view_type=False,
context=None, toolbar=False, submenu=False):
if context is None:
context = {}
journal_obj = self.pool.get('account.journal')
user_obj = self.pool.get('res.users')
# remove the entry with key 'form_view_ref', otherwise fields_view_get
# crashes
#context=dict(context)
context.pop('form_view_ref', None)
res = super(AccountInvoiceRefund, self).\
fields_view_get(cr, uid,
view_id=view_id,
view_type=view_type,
context=context,
toolbar=toolbar, submenu=submenu)
type = context.get('type', 'out_invoice')
company_id = user_obj.browse(
cr, uid, uid, context=context).company_id.id
journal_type = (type == 'out_invoice') and 'sale_refund' or \
(type == 'out_refund') and 'sale' or \
(type == 'in_invoice') and 'purchase_refund' or \
(type == 'in_refund') and 'purchase'
for field in res['fields']:
if field == 'journal_id':
journal_select = journal_obj._name_search(cr, uid, '',
[('type', '=',
journal_type),
('company_id',
'child_of',
[company_id])],
context=context)
res['fields'][field]['selection'] = journal_select
return res
下面我将此代码添加到行中:
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)
,但仍然得到相同的错误
有什么想法吗
提前谢谢 上下文是不能直接修改的对象。据我所知,这已在版本9上实现
如果要修改代码中的上下文,必须使用Odoo的API提供的方法,请查看第5460行附近的openerp/models.py
上名为的方法的定义。它有足够的文档记录,您可以在源文件中找到许多关于如何使用它的示例。上下文是您无法直接修改的对象。据我所知,这已在版本9上实现
如果要修改代码中的上下文,必须使用Odoo的API提供的方法,请查看第5460行附近的openerp/models.py
上名为的方法的定义。它有足够的文档记录,您可以在源文件中找到许多关于如何使用它的示例。克服这一问题的快速方法是将冻结的字典复制到另一个字典,然后将该字典作为参数传递给该方法,或者如果您使用的是新api,请使用“with_context”方法
以下是一个例子:
ctx = dict(self._context)
self.with_context(ctx).write({'invoice_line': []})
正如您在上面的示例中所看到的,将_上下文复制到ctx,然后使用_上下文传递新修改的上下文。克服这一问题的快速方法是将冻结的字典复制到另一个字典,然后将该字典作为参数传递给方法,或者如果您正在使用新的api,使用“with_context”方法
以下是一个例子:
ctx = dict(self._context)
self.with_context(ctx).write({'invoice_line': []})
正如您在上面的示例中所看到的,将_上下文复制到ctx,然后使用_上下文传递新修改的上下文。Afrozendict
是,嗯,冻结的。您不能pop()
it.lol,但是在这种情况下,什么函数应该是成比例的呢?复制()而不是pop()?pop()
删除键/值对(并返回它删除的值)。你不能用冰激凌copy()
做了一些完全不同的事情。我已将该行更改为get(),但得到相同的错误,仍然引用pop(),不知道为什么,必须继续尝试,看看是否还有其他注释tho,非常感谢!搞定它,哈哈,谢谢你!一个frozendict
是,嗯,冻结的。您不能pop()
it.lol,但是在这种情况下,什么函数应该是成比例的呢?复制()而不是pop()?pop()
删除键/值对(并返回它删除的值)。你不能用冰激凌copy()
做了一些完全不同的事情。我已将该行更改为get(),但得到相同的错误,仍然引用pop(),不知道为什么,必须继续尝试,看看是否还有其他注释tho,非常感谢!搞定它,哈哈,谢谢你!我会查的,非常感谢我会查的,非常感谢