Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
3 Besvarelser
9623 Visninger

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?

Avatar
Kassér
Bedste svar

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

>

Avatar
Kassér
Forfatter

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?

Forfatter Bedste svar

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?

Avatar
Kassér

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

Forfatter

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 }

Bedste svar

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.

Avatar
Kassér
Related Posts Besvarelser Visninger Aktivitet
1
maj 23
2445
2
maj 15
6462
1
nov. 24
1675
5
jul. 24
92984
1
dec. 23
3073