İçereği Atla
Menü
Bu soru işaretlendi
3 Cevaplar
9590 Görünümler

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
Vazgeç
En İyi Yanıt

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
Vazgeç
Üretici

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?

Üretici En İyi Yanıt

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
Vazgeç

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

Üretici

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 }

En İyi Yanıt

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
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
May 23
2394
2
May 15
6440
1
Kas 24
1632
5
Tem 24
92891
1
Ara 23
3044