NotImplementedError: 'pop' not supported on frozendict
NotImplementedError: 'pop' not supported on frozendict
我正在为 Odoo 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):
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
在 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)
,但仍然出现相同的错误。
对此有什么想法吗?
提前致谢!
上下文是您无法直接修改的 frozendict 对象。据我所知,这已在版本 9 上实现,
如果您想修改代码中的上下文,您必须使用 Odoo 的 API 提供的方法,请查看 openerp/models.py
上名为 with_context
的方法的定义大约第 5460 行。它有充分的文档记录,您可以在源文件中找到许多关于如何使用它的示例。
一个快速解决这个问题的方法是将冻结的字典复制到另一个字典,然后将该字典作为参数传递给方法,或者如果您使用的是新的 api,请使用 'with_context'方法。
这是一个例子:
ctx = dict(self._context)
self.with_context(ctx).write({'invoice_line': []})
正如您在上面的示例中看到的,_context 被复制到 ctx,然后 with_context 用于传递新修改的上下文。
我正在为 Odoo 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):
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
在 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)
,但仍然出现相同的错误。
对此有什么想法吗?
提前致谢!
上下文是您无法直接修改的 frozendict 对象。据我所知,这已在版本 9 上实现,
如果您想修改代码中的上下文,您必须使用 Odoo 的 API 提供的方法,请查看 openerp/models.py
上名为 with_context
的方法的定义大约第 5460 行。它有充分的文档记录,您可以在源文件中找到许多关于如何使用它的示例。
一个快速解决这个问题的方法是将冻结的字典复制到另一个字典,然后将该字典作为参数传递给方法,或者如果您使用的是新的 api,请使用 'with_context'方法。
这是一个例子:
ctx = dict(self._context)
self.with_context(ctx).write({'invoice_line': []})
正如您在上面的示例中看到的,_context 被复制到 ctx,然后 with_context 用于传递新修改的上下文。