Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Why is my iteration not working in fields_view_get?

By
Matthew Watkins
on 2/27/16, 9:56 PM 394 views

This code is expecting a singleton somewhere in cat_temps and I can't figure out why the iteration isn't working.

@api.model

def fields_view_get(self, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):

    self.env['ae.asset'].action_get_all_current_resv()

    res = super(ae_asset, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)

    all_recs = self.env['ir.model.fields'].search([('model_id', '=', 'ae.asset'), ('state', '=', 'manual')])    

    eview = etree.XML(res['arch'])

    insert_point = eview.xpath("//group[@name='attributes']")# Find the point in XML file to insert new code # Convert XML to string

    if len(insert_point):

        for rec in all_recs:

            cat_temps = ("["+','.join(['%d']*len(rec.ae_cat_temp_ids))% tuple(rec.ae_cat_temp_ids)+"]")

            res['fields'].update({'%s'%(rec.name):{'string':'%s'%(rec.field_description), 'type':'%s'%(rec.ttype)}})

            new_line = etree.Element('field', {

            'name':'%s'%(rec.name),

             })

             insert_point.append(new_line) # Append the new_line

             for node in (eview.xpath("//field[@name='%s']"%(rec.name))):

                    node.set('attrs', "{'invisible':[('cat_temp_id', 'not in', %s)]}"%(cat_temps))

                    setup_modifiers(node, res['fields']['%s'%(rec.name)])

        res['arch'] = etree.tostring(eview) # Convert back to XML

        return res


Traceback:

Traceback (most recent call last):

  File "/opt/odoo/openerp/http.py", line 537, in _handle_exception

    return super(JsonRequest, self)._handle_exception(exception)

  File "/opt/odoo/openerp/http.py", line 574, in dispatch

    result = self._call_function(**self.params)

  File "/opt/odoo/openerp/http.py", line 310, in _call_function

    return checked_call(self.db, *args, **kwargs)

  File "/opt/odoo/openerp/service/model.py", line 118, in wrapper

    return f(dbname, *args, **kwargs)

  File "/opt/odoo/openerp/http.py", line 307, in checked_call

    return self.endpoint(*a, **kw)

  File "/opt/odoo/openerp/http.py", line 803, in __call__

    return self.method(*args, **kw)

  File "/opt/odoo/openerp/http.py", line 403, in response_wrap

    response = f(*args, **kw)

  File "/opt/odoo/addons/web/controllers/main.py", line 944, in call_kw

    return self._call_kw(model, method, args, kwargs)

  File "/opt/odoo/addons/web/controllers/main.py", line 936, in _call_kw

    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)

  File "/opt/odoo/openerp/api.py", line 268, in wrapper

    return old_api(self, *args, **kwargs)

  File "/opt/odoo/openerp/api.py", line 372, in old_api

    result = method(recs, *args, **kwargs)

  File "/opt/odoo/addons/asset_extension/asset_extension.py", line 177, in fields_view_get

    cat_temps = ("["+','.join(['%d']*len(rec.ae_cat_temp_ids))% list(rec.ae_cat_temp_ids)+"]")

  File "/opt/odoo/openerp/fields.py", line 831, in __get__

    self.determine_value(record)

  File "/opt/odoo/openerp/fields.py", line 924, in determine_value

    record._prefetch_field(self)

  File "/opt/odoo/openerp/api.py", line 266, in wrapper

    return new_api(self, *args, **kwargs)

  File "/opt/odoo/openerp/models.py", line 3243, in _prefetch_field

    result = records.read(list(fnames), load='_classic_write')

  File "/opt/odoo/openerp/api.py", line 266, in wrapper

    return new_api(self, *args, **kwargs)

  File "/opt/odoo/openerp/models.py", line 3180, in read

    self._read_from_database(stored, inherited)

  File "/opt/odoo/openerp/api.py", line 266, in wrapper

    return new_api(self, *args, **kwargs)

  File "/opt/odoo/openerp/models.py", line 3367, in _read_from_database

    res2 = self._columns[f].get(cr, self._model, ids, f, user, context=context, values=result)

  File "/opt/odoo/openerp/osv/fields.py", line 781, in get

    result[int(record[inverse])].append(record.id)

  File "/opt/odoo/openerp/models.py", line 5611, in __int__

    return self.id

  File "/opt/odoo/openerp/fields.py", line 1884, in __get__

    return record.ensure_one()._ids[0]

  File "/opt/odoo/openerp/models.py", line 5307, in ensure_one

    raise except_orm("ValueError", "Expected singleton: %s" % self)

except_orm: ('ValueError', 'Expected singleton: ir.model.fields(6271, 6272)')

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/27/16, 9:56 PM
Seen: 394 times
Last updated: 2/27/16, 10:21 PM