Unable to get inherited view to work properly

Asked by Jim Norman

OpenERP 5.0.9, Ubuntu Linux 9.10.

I'm attempting to set up views with US address convention (street, city, state_id, zip, country_id) rather than the European style of street zip city country_id state_id. I have created a new module for these changes called en_us. I have most of partner working except for the id="view_partner_property_form" in the account module, which inherits from base.view_partner_form. I have tried multiple solutions, but the following two examples will illustrate the problem:

If I have the following:

        <record id="view_partner_property_form_en_US" model="ir.ui.view">
            <field name="name">res.partner.property.form.inherita</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="account.view_partner_property_form"/>
            <field name="type">form</field>
            <field name="priority">2</field>
            <field name="arch" type="xml">
                    <page string="Accounting" position="replace">
                    <group col="2" colspan="2">
                        <separator string="Customer Accounting Properties" colspan="2"/>
                        <field name="property_account_receivable"/>
                        <field name="property_account_position"/>
                        <field name="property_payment_term"/>
                    </group>
                    <group col="2" colspan="2">
                        <separator string="Supplier Accounting Properties" colspan="2"/>
                        <field name="property_account_payable"/>
                    </group>
                    <group col="2" colspan="2">
                        <separator string="Customer Credit" colspan="2"/>
                        <field name="credit" select="2"/>
                        <field name="credit_limit" select="2"/>
                    </group>
                    <group col="2" colspan="2">
                        <separator string="Supplier Debit" colspan="2"/>
                        <field name="debit" select="2"/>
                    </group>
                    <field colspan="4" context="address=address" name="bank_ids" nolabel="1" select="2">
                        <form string="Bank account">
                            <field name="state" select="2"/>
                            <newline/>
                            <field name="acc_number" select="1"/>
                            <newline/>
                            <field name="bank"/>
                            <newline/>
                            <field name="sequence"/>
                            <field colspan="4" name="name" select="2"/>
                            <separator colspan="4" string="Bank account owner"/>
                            <field colspan="4" name="owner_name"/>
                            <field colspan="4" name="street"/>
                            <newline/>
                            <field name="city"/>
                            <field name="state_id"/>
                            <newline/>
                            <field name="zip"/>
                            <field completion="1" name="country_id"/>
                        </form>
                        <tree string="Bank Details">
                            <field name="state"/>
                            <field name="bank"/>
                            <field name="owner_name"/>
                            <field name="acc_number"/>
                        </tree>
                    </field>
  </page>
             </field>
        </record>

no Account tab appears at all.

If I instead have:

        <record id="view_partner_property_form_en_US" model="ir.ui.view">
            <field name="name">res.partner.property.form.inherita</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="account.view_partner_property_form"/>
            <field name="type">form</field>
            <field name="priority">2</field>
            <field name="arch" type="xml">
                  <notebook>
                    <page string="Accounting" position="replace">
                    <group col="2" colspan="2">
                        <separator string="Customer Accounting Properties" colspan="2"/>
                        <field name="property_account_receivable"/>
                        <field name="property_account_position"/>
                        <field name="property_payment_term"/>
                    </group>
                    <group col="2" colspan="2">
                        <separator string="Supplier Accounting Properties" colspan="2"/>
                        <field name="property_account_payable"/>
                    </group>
                    <group col="2" colspan="2">
                        <separator string="Customer Credit" colspan="2"/>
                        <field name="credit" select="2"/>
                        <field name="credit_limit" select="2"/>
                    </group>
                    <group col="2" colspan="2">
                        <separator string="Supplier Debit" colspan="2"/>
                        <field name="debit" select="2"/>
                    </group>
                    <field colspan="4" context="address=address" name="bank_ids" nolabel="1" select="2">
                        <form string="Bank account">
                            <field name="state" select="2"/>
                            <newline/>
                            <field name="acc_number" select="1"/>
                            <newline/>
                            <field name="bank"/>
                            <newline/>
                            <field name="sequence"/>
                            <field colspan="4" name="name" select="2"/>
                            <separator colspan="4" string="Bank account owner"/>
                            <field colspan="4" name="owner_name"/>
                            <field colspan="4" name="street"/>
                            <newline/>
                            <field name="city"/>
                            <field name="state_id"/>
                            <newline/>
                            <field name="zip"/>
                            <field completion="1" name="country_id"/>
                        </form>
                        <tree string="Bank Details">
                            <field name="state"/>
                            <field name="bank"/>
                            <field name="owner_name"/>
                            <field name="acc_number"/>
                        </tree>
                    </field>
  </page>
                </notebook>
             </field>
        </record>

I get two Accounting tabs - one with the expected address style for banks and one which will not show a view for a new bank.

Any suggestions?

Is this possibly caused by two levels of inheritance?

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Vinay Rana (OpenERP)
Solved:
Last query:
Last reply:
Revision history for this message
Christophe CHAUVET (christophe-chauvet) said :
#1

Hi

You must use <xpath expr... instead of <page string="Accounting" position="replace">

Since i use it, i never had inherit problem

Regards,

Revision history for this message
Jordi Esteve (www.zikzakmedia.com) (jesteve-zikzakmedia) said :
#2

You can see several examples using <xpath expr...> in the magento connector module (magentoerpconnect, it has his own openobject project). For example, inheritance of the product form:

<xpath expr="/form/notebook" position="inside">
<xpath expr="/form/group/group/field[@name='ean13']" position="after">

I suggest you not to change all the Accounting tab in the res.partner form, only to replace or add the specific fields you want to change.

This is an example that adds several fields in product form:

  <record model="ir.ui.view" id="product_product_form_view_magerp">
   <field name="name">product.normal.form_magerp</field>
   <field name="model">product.product</field>
   <field name="inherit_id" ref="product.product_normal_form_view" />
   <field name="type">form</field>
   <field name="arch" type="xml">
    <data>
     <xpath expr="/form/group/group/field[@name='ean13']" position="after">
      <field name="magento_sku" select="2" attrs="{'required':[('magento_exportable','==',True)]}"/>
     </xpath>
     <xpath expr="/form/group/group/field[@name='variants']" position="after">
      <field name="set" select="2" attrs="{'required':[('magento_exportable','==',True)]}"/>
     </xpath>
     <xpath expr="/form/group/group/field[@name='rental']" position="after">
      <field name="magento_exportable" select="2"/>
     </xpath>
    </data>
   </field>
  </record>

Revision history for this message
Jim Norman (jim-jsnorman) said :
#3

This works nicely for inserted fields, but I need to replace one field sequence by another, and the documentation says there may be only one replace in an inherited view. This leads to a proliferation of views. Am i right?

Revision history for this message
Jim Norman (jim-jsnorman) said :
#4

Also, it appears that inheritance only works one level deep. If I try to inherit from an inherited view, I get AttributeError: Couldn't find tag '<xpath expr="//notebook/page//form">' in parent view !

Revision history for this message
Best Vinay Rana (OpenERP) (vra-openerp) said :
#5

Hello Jim,

You can replace only field by another field not the page by page.
This is a new feature you specified in question. Create a blueprints for this issue.

Thanks.

Revision history for this message
Jim Norman (jim-jsnorman) said :
#6

Thanks vra (openerp), that solved my question.

Revision history for this message
Selvam (s.selvam) said :
#7

Hello Jim,

Can i do multi-level inheritance in view ?
A->B->C

B replaces all the content of a one2many field.Now i want a field to the B with C.

Revision history for this message
xrg (xrg) said :
#8

On Saturday 20 November 2010, you wrote:
> Question #107722 on OpenObject Server changed:
> https://answers.launchpad.net/openobject-server/+question/107722
>
> Selvam posted a new comment:
> Hello Jim,
>
> Can i do multi-level inheritance in view ?
> A->B->C
>
> B replaces all the content of a one2many field.Now i want a field to the
> B with C.

Yes, multilevel is perfectly available and tested to work.
But you always need to be careful when designing those views. I can surely
remember a few cases where you had, say, B1 inherit from A, then B2 inherit
from A, too, and B1 conflict with B2. Or even that C would be designed to
inherit from B1, where in fact it would need to inherit from B2, too.

As a general rule, try to discover what other modules try to inherit the view
you want to change, and examine their compatibility with yours. Also, define
the "inherits" attribute to the view you _really_ mean to inherit, not
necessariy the base model view or any arbitrarily chosen view of that model.