简体   繁体   中英

NotImplementedError: 'pop' not supported on frozendict

I'm adapting a module for Odoo v9 community

It uses frozendict, but everytime I try to use a feature, it throws:

NotImplementedError: 'pop' not supported on frozendict

The code is as follows:

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

Following this I've added this code to the line:

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).\

Instead of:

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).\

As You can see I've added context=dict(context) , but still get the same error.

Any ideas about this?

Thanks in advance!

Contexts are frozendict objects that you cannot directly modify. This has been implemented on version 9 from what I am aware,

If you want to modify the context in your code you have to use methods provided by Odoo's API, take a look at the definition of the method named with_context on openerp/models.py around line 5460. It is sufficiently documented and you can find many examples on the source files as to how it is used.

A quick way to get over this would be to copy the frozen dictionary to another dictionary and then pass that dictionary to the method either as an argument or if you are using the new api, use the 'with_context' method.

Here is an example:

ctx = dict(self._context)
self.with_context(ctx).write({'invoice_line': []})

As you can see in the above example the _context is copied to ctx and then with_context is used to pass the new modified context.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM