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

Problem with inheritance of a view.

By
Luis Filipe Castanheira
on 5/27/14, 9:52 AM 1,195 views

In order to show some workflow buttons to members of a group and hide them from all others, I am trying to inherit a view of a custom module that I am developing in OpenERP 7.0

In my original view I have the following code:

<?xml version="1.0"?>
<openerp>
    <data>
(...)
        <!-- ### GENERIC REQUEST ### -->
        <record model="ir.ui.view" id="view_generic_request_form">
            <field name="name">generic_request.form</field>
            <field name="model">generic.request</field>
            <!-- ####### F O R M   V I E W  ###### -->        
            <field name="arch" type="xml">
                <form string="generic_request" version="7.0">
                    <header>
     (...)                   
                        <!-- treatment (authorized & approved)-->

                        <button name="wtv" invisible="1" />
                        <button name="close_request" class="oe_highlight oe_view_mode_only" string="Close Request Process" help="This will close the request and end the process here" type="workflow" attrs="{'invisible':['|', ('state', 'not in', ['treatment', 'authorized', 'approved']), ('ami_owner', '=', False)]}"  />
                        <button name="%(action_auth_generic_request)d" class="oe_view_mode_only" string="Ask for authorization wiz" help="" type="action" attrs="{'invisible':['|', '|', ('state', 'not in', ['treatment', 'authorized', 'approved']), ('authorized','=', True), ('ami_owner', '=', False)]}" />
                        <button name="%(action_appr_generic_request)d" class="oe_view_mode_only" string="Ask for approval wiz" help="" type="action"  attrs="{'invisible':['|', '|', '|', ('state', 'not in', ['treatment', 'authorized', 'approved']), ('authorized','=', True), ('approved','=', True), ('ami_owner', '=', False)]}"  />
                        <button name="%(action_reformulate_generic_request)d" class="oe_view_mode_only" string="Send to be reformulated w2" help="Send request back to requester to be reformulated" type="action"  attrs="{'invisible': ['|',('state', 'not in', ['treatment', 'authorized', 'approved']), ('ami_owner', '=', False)]}"/>

                            <!-- give and take buttons -->                    
                            <button name="take_request" string="Take request" help="Take this request to your responsability" attrs="{'invisible': ['|',('ami_owner', '=', True), ('state', 'not in', ['treatment', 'authorized', 'approved']),]}" />
                            <button name="%(action_give_request)d" string="Give request wiz" help="Give this request to someone else's responsability" type="action" attrs="{'invisible': ['|',('ami_owner', '=', False),'|', ('state', 'not in', ['treatment', 'authorized', 'approved']),]}"  />

    (...)             

    
In my inherited view XML I have this:

<?xml version="1.0"?>
<openerp>
    <data>
<!-- ###  SHOW WTV BUTTON ONLY TO HR MEMBERS  ### -->
<record model="ir.ui.view"  id="view_generic_request_form_hr">
    <field name="name">view.generic.request.form.hr</field>
    <field name="model">generic.request</field>
    <field name="inherit_id" ref="processos_uc.view_generic_request_form"/>
    <field name="groups_id" eval="[(6, 0, [ref('processos_uc.group_processos_hr') ])]"/>
    <field name="arch" type="xml">
        <field name="wtv" position="attributes">
            <attribute name="invisible">0</attribute>
        </field>
    </field>
</record>
    </data>
</openerp>

And I get this error:

AttributeError: View definition error for inherited view '' on model 'generic.request': Element '<field name="wtv">' not found in parent view 'processos_uc.view_generic_request_form'

I've seen other examples of inheritance and can't figure out what I'm doing wrong. Can anyone help?

Here is the full (and now correct) trace :

2014-05-27 14:16:52,567 4156 INFO may_9 openerp.modules.loading: module processos_uc: loading inherit_view.xml
2014-05-27 14:16:52,596 4156 ERROR may_9 openerp.addons.base.ir.ir_ui_view: Can't render view  for model: generic.request
Traceback (most recent call last):
  File "/opt/openerp/v7/server/openerp/addons/base/ir/ir_ui_view.py", line 126, in _check_render_view
    fvg = self.pool.get(view.model).fields_view_get(cr, uid, view_id=view.id, view_type=view.type, context=context)
  File "/opt/openerp/v7/server/openerp/osv/orm.py", line 2237, in fields_view_get
    arch=apply_view_inheritance(cr, user, source, sql_res['id']),
  File "/opt/openerp/v7/server/openerp/osv/orm.py", line 2195, in apply_view_inheritance
    source = apply_inheritance_specs(source, view_arch, view_id)
  File "/opt/openerp/v7/server/openerp/osv/orm.py", line 2179, in apply_inheritance_specs
    raise_view_error("Element '%s' not found in parent view '%%(parent_xml_id)s'" % tag, inherit_id)
  File "/opt/openerp/v7/server/openerp/osv/orm.py", line 2072, in raise_view_error
    %  (child_view.xml_id, self._name, error_msg))
AttributeError: View definition error for inherited view '' on model 'generic.request': Element '<field name="wtv">' not found in parent view 'processos_uc.view_generic_request_form'
2014-05-27 14:16:52,598 4156 ERROR may_9 openerp.tools.convert: Parse error in /home/lfc/openerp/v7/addons/processos_uc/inherit_view.xml:5:
<record model="ir.ui.view" id="view_generic_request_form_hr">
    <field name="name">view.generic.request.form.hr</field>
    <field name="model">generic.request</field>
    <field name="inherit_id" ref="processos_uc.view_generic_request_form"/>
    <field name="groups_id" eval="[(6, 0, [ref('processos_uc.group_processos_hr') ])]"/>
    <field name="arch" type="xml">
        <field name="wtv" position="attributes">
            <attribute name="invisible">0</attribute>
        </field>
    </field>
</record>
Traceback (most recent call last):
  File "/opt/openerp/v7/server/openerp/tools/convert.py", line 847, in parse
    self._tags[rec.tag](self.cr, rec, n)
  File "/opt/openerp/v7/server/openerp/tools/convert.py", line 814, in _tag_record
    id = self.pool.get('ir.model.data')._update(cr, self.uid, rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode, context=rec_context )
  File "/opt/openerp/v7/server/openerp/addons/base/ir/ir_model.py", line 964, in _update
    res_id = model_obj.create(cr, uid, values, context=context)
  File "/opt/openerp/v7/server/openerp/addons/base/ir/ir_ui_view.py", line 103, in create
    return super(view, self).create(cr, uid, values, context)
  File "/opt/openerp/v7/server/openerp/osv/orm.py", line 4472, in create
    self._validate(cr, user, [id_new], context)
  File "/opt/openerp/v7/server/openerp/osv/orm.py", line 1546, in _validate
    raise except_orm('ValidateError', '\n'.join(error_msgs))
except_orm: ('ValidateError', u'Error occurred while validating the field(s) arch: Invalid XML for View Architecture!')
2014-05-27 14:16:52,599 4156 ERROR may_9 openerp.netsvc: ValidateError
Error occurred while validating the field(s) arch: Invalid XML for View Architecture!
Traceback (most recent call last):
  File "/opt/openerp/v7/server/openerp/netsvc.py", line 292, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/opt/openerp/v7/server/openerp/service/web_services.py", line 622, in dispatch
    security.check(db,uid,passwd)
  File "/opt/openerp/v7/server/openerp/service/security.py", line 40, in check
    pool = pooler.get_pool(db)
  File "/opt/openerp/v7/server/openerp/pooler.py", line 49, in get_pool
    return get_db_and_pool(db_name, force_demo, status, update_module)[1]
  File "/opt/openerp/v7/server/openerp/pooler.py", line 33, in get_db_and_pool
    registry = RegistryManager.get(db_name, force_demo, status, update_module)
  File "/opt/openerp/v7/server/openerp/modules/registry.py", line 192, in get
    update_module)
  File "/opt/openerp/v7/server/openerp/modules/registry.py", line 218, in new
    openerp.modules.load_modules(registry.db, force_demo, status, update_module)
  File "/opt/openerp/v7/server/openerp/modules/loading.py", line 350, in load_modules
    force, status, report, loaded_modules, update_module)
  File "/opt/openerp/v7/server/openerp/modules/loading.py", line 256, in load_marked_modules
    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
  File "/opt/openerp/v7/server/openerp/modules/loading.py", line 187, in load_module_graph
    load_update_xml(module_name, idref, mode)
  File "/opt/openerp/v7/server/openerp/modules/loading.py", line 74, in <lambda>
    load_update_xml = lambda *args: _load_data(cr, *args, kind='update_xml')
  File "/opt/openerp/v7/server/openerp/modules/loading.py", line 124, in _load_data
    tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
  File "/opt/openerp/v7/server/openerp/tools/convert.py", line 954, in convert_xml_import
    obj.parse(doc.getroot())
  File "/opt/openerp/v7/server/openerp/tools/convert.py", line 847, in parse
    self._tags[rec.tag](self.cr, rec, n)
  File "/opt/openerp/v7/server/openerp/tools/convert.py", line 814, in _tag_record
    id = self.pool.get('ir.model.data')._update(cr, self.uid, rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode, context=rec_context )
  File "/opt/openerp/v7/server/openerp/addons/base/ir/ir_model.py", line 964, in _update
    res_id = model_obj.create(cr, uid, values, context=context)
  File "/opt/openerp/v7/server/openerp/addons/base/ir/ir_ui_view.py", line 103, in create
    return super(view, self).create(cr, uid, values, context)
  File "/opt/openerp/v7/server/openerp/osv/orm.py", line 4472, in create
    self._validate(cr, user, [id_new], context)
  File "/opt/openerp/v7/server/openerp/osv/orm.py", line 1546, in _validate
    raise except_orm('ValidateError', '\n'.join(error_msgs))
except_orm: ('ValidateError', u'Error occurred while validating the field(s) arch: Invalid XML for View Architecture!')
2014-05-27 14:16:52,607 4156 INFO may_9 werkzeug: 193.136.201.121 - - [27/May/2014 14:16:52] "POST /web/dataset/call_button HTTP/1.1" 200 -

 

Question / Error and trace updated (I was trying to simplify and I guess I complicated things a bit)

Luis Filipe Castanheira
on 5/27/14, 10:20 AM

I edited my comment below.

Ludo - Neobis
on 5/27/14, 10:23 AM
1

Ludo - Neobis

--Ludo - Neobis--
2387
| 2 2 5
Hoogvliet, Netherlands
--Ludo - Neobis--

Developer

Ludo - Neobis
On 5/27/14, 10:06 AM

This often happens when developing different versions and switching back and forth between them. The view that is causing the crash (view_generic_request_form_hr) still refers to a field called "close_request". Make sure you are updating/editing the right view.

If you are 100% sure you are updating the right view and it is linked correctly, then look for this field "close_request" on the form you try to inherit. I don't see it in the top view that you posted, but you left out some information on purpose as well.

[EDIT]

Oke, I read your comment. In that case, it is trying to alter a field, while you are trying to alter a button.

So you have:

<field name="close_request position="attributes">

replace that with:

<button name="close_request position="attributes">

Yeah, I did for simplicity sake. I edited the code and those are the buttons I want to Hide (the "wtv" button was added as an example)

Luis Filipe Castanheira
on 5/27/14, 10:17 AM

That was it! Thanks!

Luis Filipe Castanheira
on 5/27/14, 10:35 AM

Glad to hear. If this is resolved now, please mark the answer.

Ludo - Neobis
on 5/27/14, 10:57 AM

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

2 follower(s)

Stats

Asked: 5/27/14, 9:52 AM
Seen: 1195 times
Last updated: 3/16/15, 8:10 AM