NotImplementedError:Frozendict不支持'更新'-Odoo v8 [英] NotImplementedError: 'update' not supported on frozendict - Odoo v8

查看:343
本文介绍了NotImplementedError:Frozendict不支持'更新'-Odoo v8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Odoo v8模块上有以下代码:

I have this code on my Odoo v8 module:

@api.multi
def button_generate_wh_doc(self):
    context = self._context
    partner = self.env['res.partner']
    res = {}
    for inv in self:
        view_id = self.env['ir.ui.view'].search([
            ('name', '=', 'account.invoice.wh.iva.customer')])
        context.update({
            'invoice_id': inv.id,
            'type': inv.type,
            'default_partner_id': partner._find_accounting_partner(
                inv.partner_id).id,
            'default_name': inv.name or inv.number,
            'view_id': view_id,
        })
        res = {
            'name': _('Withholding vat customer'),
            'type': 'ir.actions.act_window',
            'res_model': 'account.wh.iva',
            'view_type': 'form',
            'view_id': False,
            'view_mode': 'form',
            'nodestroy': True,
            'target': 'current',
            'domain': "[('type', '=', '" + inv.type + "')]",
            'context': context
        }
    return res

这是一个按钮动作,但是当我单击它时会抛出:

This is a button action, but when I click it it throws me:

File "/home/user/odoov8/odoo-venezuela/l10n_ve_withholding_iva/model/invoice.py", line 427, in button_generate_wh_doc
'view_id': view_id,
File "/home/user/odoov8/odoo-8.0-20161017/openerp/tools/misc.py", line 1280, in update
raise NotImplementedError("'update' not supported on frozendict")
NotImplementedError: 'update' not supported on frozendict

有人在执行此操作时遇到此类错误吗?

Has anybody encounter this kind of error implementing this?

我认为这与调用上下文的顺序有关,但我不确定.

I think it has to do with the order in which the context is called, but Im not really sure.

推荐答案

要更新上下文,请尝试此操作.

To update context try this.

context = self.env.context.copy()
context.update({'domain':[('something','=','something')]})

现在将其用作上下文变量.

Now use this as your context variable.

更新:

以上解决方案适用于此问题中描述的用例.但是,在Odoo中有许多情况是从环境中获取上下文,并且上述答案并没有真正说明如何以这种方式更新上下文.因此,在这种情况下,您将需要使用此帖子中其他人所描述的with_context()函数.

The above solution is appropriate for the use case described in this question. However there are many circumstances in Odoo where context is taken from the environment and the above described answer does not really explain how to update the context in that fashion. So in those circumstances you will want to use the with_context() function as described by others on this posting.

context = self.env.context.copy()
context.update({'domain':[('something','=','something')]})
self.with_context(context).your_function()

在这种情况下,自我是所讨论的对象,可能会有所不同.您可以在Odoo源代码中找到with_context()的许多示例.

In this circumstance self is the object in question which could vary. You can find many examples of with_context() in the Odoo source code.

这篇关于NotImplementedError:Frozendict不支持'更新'-Odoo v8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆