2016-10-28 4 views
2

私はOdoo v8のモジュールでこのコードを持っている:NotImplementedError:frozendictでサポートされていない「更新」 - OdooのV8

@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 

これはボタンアクションですが、私はそれをクリックしたとき、それは私をスロー:

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 

このようなエラーが発生している人はいますか?

私はそれがコンテキストが呼ばれる順序と関係があると思いますが、実際はわかりません。

答えて

4

コンテキストを更新するには、これを試してください。

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

これをコンテキスト変数として使用します。

+1

あなたの答えは技術的には正しいですが、@ shodowsjediの答えのように、最初のオプションとしてwith_context()を使うべきです。 – CZoellner

5

あなたが好きなようにコンテキストをコピーして使用することができますが、forezedictをコピーすると、新しい辞書が現在のコンテキストを壊すことになります。with_contextメソッドを使用するようにアドバイスします。

self.with_context(key=value,key=value) 

これにより、現在の環境コンテキストが更新され、自動的に前に進みます。

+0

odooコントローラのrequest.env.contextを更新するには? –

関連する問題