跳至内容
菜单
此问题已终结
3 回复
9622 查看

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?

形象
丢弃
最佳答案

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?

编写者 最佳答案

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 ?

编写者

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 }

最佳答案

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.

形象
丢弃
相关帖文 回复 查看 活动
1
5月 23
2441
2
5月 15
6461
1
11月 24
1675
5
7月 24
92980
1
12月 23
3072