Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
9608 มุมมอง

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.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ค. 23
2439
2
พ.ค. 15
6451
1
พ.ย. 24
1660
Change the Position of field in Xpath แก้ไขแล้ว
5
ก.ค. 24
92953
1
ธ.ค. 23
3063