SmithMcPatrick
SmithMcPatrick

Reputation: 619

Error: Element '<field name="x y z">' cannot be located in parent view

I have created a computed field in python code, bom.py (please see below) and added that field in the view bom_view.xml. The field name is "old_default_code" and associated function in python code is _old_default_code(). However, when I try to update (refresh) the module I am getting an error:

"Error details: "Field `old_default_code" does not exist"

What am I doing wrong?

Here is the code snippet from bom.py:

class mrp_bom(osv.osv):
    _inherit = 'mrp.bom'

        def _old_default_code(self, cr, uid, ids, name, arg, context=None):
            return True

    _columns = {'x_roll_material': fields.float('Standard Material Cost', digits=(16, 4), readonly=True),
        'x_bom_time_average': fields.float('Average BOM Lead Time', digits=(16, 4), readonly=True),
        'x_bom_time_last': fields.float('Last BOM Lead Time', digits=(16, 4), readonly=True),
        'old_default_code' : fields.function(_old_default_code, type='char', size=32, method=True, store=False, multi=False) }

and here is the XML code:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <!-- mrp_bom -->
        <record id="adamson_mrp_bom_form_view" model="ir.ui.view">
            <field name="name">adamson.mrp.bom.form.view</field>
            <field name="model">mrp.bom</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="mrp.mrp_bom_form_view" />
            <field name="arch" type="xml">
                <field name="old_default_code" />
                <xpath expr="//notebook/page[@string='Components']/field/tree[@string='Components']/field[@name='sequence']" position="before" >

                     <button class="oe_inline oe_stat_button" type="object" string="Go!" icon="gtk-go-forward" name="action_go" 
                     attrs="{'invisible':[('old_default_code','=', False)]}"  />
                               </xpath>

Upvotes: 1

Views: 3277

Answers (1)

Hardik Patadia
Hardik Patadia

Reputation: 1999

When you inherit a view, that means you can put field in reference to the elements present in the parent view.

The view that you have shown here, in that you tried to put the field old_default_code straight away without any reference to existing field.

For example, when you put new field to a model by inheritance, then in the view you need to refer to field which is there in the parent view and using the option position having the values like 'after', 'before', 'attributes', you can position your newly added field.

Here you are trying to put the field old_default_code straight away, so tries to find that field in the parent view, which is not there and due to that you are facing the error.

Upvotes: 7

Related Questions