Odoo Help

1

Invalid XML when trying to inherit

By
Abdullah Sofan
on 9/27/13, 5:29 AM 4,458 views

I'm very new to Openerp so please bare with me if my mistake is too obvious :-)

I'm trying to create a new model called clients.client inheriting from res.partner

this is the code of clients.py:

from openerp.osv import osv, fields

class clients_client(osv.osv):
    _inherit = 'res.partner'
    _name = 'clients.client'
    _columns = {
        'id_type': fields.char('ID Type', size=30),
    }
clients_client()

This is the view code of clients_view.xml:

<?xml version="1.0"?>
<openerp>
<data>

    <record model="ir.ui.view" id="view_clients_client_form">
        <field name="name">clients.client.form</field>
        <field name="model">clients.client</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">
            <form string="clients.client" version="7.0">
                <field name="id_type" select="1"/>
            </form>
        </field>
    </record>
    <record model="ir.ui.view" id="view_clients_client_tree">
        <field name="name">clients.client.tree</field>
        <field name="model">clients.client</field>
        <field name="inherit_id" ref="base.view_partner_tree"/>
        <field name="arch" type="xml">
            <tree string="clients.client">
                <field name="id_type"/>

            </tree>
        </field>
    </record>
    <record model="ir.actions.act_window" id="action_clients_client">
        <field name="name">Clients</field>
        <field name="res_model">clients.client</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>
    <menuitem name="Clients/Clients/Clients" id="menu_clients_client" action="action_clients_client"/>


</data>
</openerp>

This is the Error I get:

ValidateError

Error occurred while validating the field(s) arch: Invalid XML for View Architecture!

Can someone help?

0
Ali Ravani
On 9/27/13, 6:25 AM

Hello.

  1. If you are inheriting existing object then u have to use that object name i.e "res.partner"

>

   <field name="model">clients.client</field> 
    with  
   <field name="model">res.partner</field> 

  <field name="res_model">clients.client</field> 
   with
  <field name="res_model">res.partner</field

>

I tried that but that did not fix the error. Is there anything else in the code I need to change to match the change of object name?

Abdullah Sofan
on 9/27/13, 6:37 AM
0
Vikram
On 9/28/13, 2:53 AM

Please do the change of existing view file with following line:

<field name="model">res.partner</field>

Overall record should be:

<record model="ir.ui.view" id="view_clients_client_form"> <field name="name">clients.client.form</field> <field name="model">res.partner</field> <field name="inherit_id" ref="base.view_partner_form"/> <field name="arch" type="xml"> <xpath expr="//field[@name='active']" position="after"> <field name="id_type"/> </xpath> </field> </record>

Whenever you want to inherit existing class (res.partner), You have to specified in model. I hope you get some idea on this,

Thanks,

Vikram.

0
Abdullah Sofan
On 9/27/13, 4:07 PM

OK, after looking at some other sites I made a little change and the code partially works, but the problem now is that the form displays differently than expected. The form view shows all the views of the parent view as well as the new field, but the order and look is not as expected. Can someone help?

the clients.py code is the same as above (no change):

from openerp.osv import osv, fields

class clients_client(osv.osv):
    _inherit = 'res.partner'
    _name = 'clients.client'
    _columns = {
        'id_type': fields.char('ID Type', size=30),
    }
clients_client()

the clients_view.xml looks like this after modification:

<?xml version="1.0"?>
<openerp>
<data>

    <record model="ir.ui.view" id="view_clients_client_form">
        <field name="name">clients.client.form</field>
        <field name="model">clients.client</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">
        <xpath expr="//field[@name='active']" position="after">
                    <field name="id_type"/>
                </xpath>
        </field>
    </record>

    <record model="ir.actions.act_window" id="action_clients_client">
        <field name="name">Clients</field>
        <field name="res_model">clients.client</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>
    <menuitem name="Clients/Clients/Clients" id="menu_clients_client" action="action_clients_client"/>


</data>
</openerp>

However, as I said before, the form looks different form the way it looks in other modules. Please see the picture:

sama4g.com/res.partner.view.jpg

Can someone help me get the form to look the same?

What is in the depends tag of your __openerp__.py file ?

Bista Solutions US, Ray Carnes
on 9/27/13, 5:59 PM

the is __openerp_.py file contents:

{ "name" : "clients", "version" : "0.1", "author" : "Tiny", "website" : "http://openerp.com", "category" : "Unknown", "description": """ """, "depends" : ['base'], "init_xml" : [ ], "demo_xml" : [ ], "update_xml" : ['clients_view.xml', 'security/ir.model.access.csv'], "installable": True }

Abdullah Sofan
on 9/27/13, 6:01 PM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 9/27/13, 5:29 AM
Seen: 4458 times
Last updated: 3/16/15, 8:10 AM