我正在为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)
,但仍会收到同样的错误。
有关于此的任何想法吗?
提前致谢!
答案 0 :(得分:1)
快速解决这个问题的方法是将冻结的字典复制到另一个字典,然后将该字典作为参数传递给方法,或者如果您使用新的api,请使用' with_context&#39 ;方法
以下是一个例子:
ctx = dict(self._context)
self.with_context(ctx).write({'invoice_line': []})
正如您在上面的示例中所看到的,_context被复制到ctx,然后with_context用于传递新修改的上下文。