如何在不继承默认树的情况下为res.partner创建新的树视图?

时间:2014-04-14 09:35:06

标签: openerp openerp-7 openerp-8

我需要为res.partner创建一个备用树视图。

这是我的代码

<record id="custom_res_partner_tree_view" model="ir.ui.view">
    <field name="name">CUSTOM</field>
    <field name="model">res.partner</field>
    <field eval="1" name="priority"/>
    <field name="arch" type="xml">
        <tree string="Contacts">
            <field string="1" name="custom_field1"/>
            <field string="2" name="custom_field2"/>
            <field string="3" name="name"/>
            <field string="4" name="street"/>
            <field string="5" name="phone"/>
            <field string="6" name="email"/>
        </tree>
    </field>
</record>

.......

<record model="ir.actions.act_window.view" id="custom_res_partner_tree_view_action">
    <field eval="2" name="sequence"/>
    <field name="view_mode">tree</field>
    <field name="view_id" ref="custom_res_partner_tree_view"/>
    <field name="act_window_id" ref="custom_res_partner_action"/>
</record>

上面的代码可以工作,但它的行为就像它继承了原始树视图一样。它显示了我没有指定的列。如何制作一棵全新的树?


其他详情:

custom_res_partner.py

from osv import osv,fields

class custom_res_partner(osv.osv):

    def _account_default(self, cr ,uid, context=None):
    obj= self.pool.get('account.account')
    ids = obj.search(cr, uid, [])

    if(len(ids)>0):
        return ids[0]
    else:
        return None

    _name           = "res.partner"
    _inherit        = "res.partner"
    _columns        = {
    }

    _defaults = {
        'property_account_receivable'       : _account_default,
        'property_account_payable'          : _account_default,
    }

    _sql_constraints = [
    ]

    def init(self, cr):
    pass   

custom_res_partner()

custom_res_partner_view.xml

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>
        <record id="custom_res_partner_tree_view" model="ir.ui.view">
            <field name="name">Customer</field>
            <field name="model">res.partner</field>
            <field eval="10" name="priority"/>
            <field name="arch" type="xml">
                <tree string="Contacts">
                    <field string="KTP" name="ktp"/>
                    <field string="NPWP" name="npwp"/>
                    <field string="Name" name="name"/>
                    <field string="Address" name="street"/>
                    <field string="Telephone" name="phone"/>
                    <field string="Email" name="email"/>
                </tree>
            </field>
        </record>

        <record id="custom_res_partner_kanban_view" model="ir.ui.view">
            <field name="name">res.partner.kanban.custom</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.res_partner_kanban_view" />
            <field name="arch" type="xml">
                <xpath expr="/kanban/field[@name='color']" position="after">
                    <field name="npwp" />
                </xpath>
            </field>
        </record>

        <record id="custom_res_partner_form_view" model="ir.ui.view">
            <field name="name">res.partner.form</field>
            <field name="model">res.partner</field>
            <field eval="1" name="priority" />
            <field name="arch" type="xml">
                <form string="Customer" version="7.0">
                    <header></header>
                    <sheet>
                        <field name="image" widget='image' class="oe_left oe_avatar" options='{"preview_image": "image_medium", "size": [90, 90]}'/>
                        <div class="oe_title">
                            <div class="oe_edit_only">
                            <label for="name" string="Name"/>
                            </div>
                            <h1>
                            <field name="name" default_focus="1" placeholder="Nama" />
                            </h1>
                            <div class="oe_edit_only">
                            <label for="ktp" string="KTP"/>
                            </div>
                            <h1>
                            <field name="ktp" placeholder="KTP" />
                            </h1>
                            <div class="oe_edit_only">
                            <label for="npwp" string="NPWP"/>
                            </div>
                            <h1>
                            <field name="npwp" placeholder="NPWP" />
                            </h1>
                        </div>
                        <group>
                            <group>             
                                <label for="street" string="Address"/>
                                <div>
                                    <field name="street" placeholder="Address 1"/>
                                    <field name="street2" placeholder="Address 2"/>
                                    <div class="address_format">
                                        <field name="city" placeholder="City" style="width: 40%%"/>
                                        <field name="state_id" class="oe_no_button" placeholder="State" style="width: 37%%" options='{"no_open": True}' on_change="onchange_state(state_id)"/>
                                        <field name="zip" placeholder="Zip" style="width: 20%%"/>
                                    </div>
                                    <field name="country_id" placeholder="Country" class="oe_no_button" options='{"no_open": True}'/>
                                </div>
                            </group>
                            <group>
                                <field name="phone" placeholder="misal +62224281110"/>
                                <field name="mobile"/>
                                <field name="fax"/>
                                <field name="email" widget="email"/>
                            </group>
                        </group>
                    </sheet>
                    <div class="oe_chatter"></div>
                </form>
            </field>
        </record>

        <record id="custom_res_partner_action" model="ir.actions.act_window">
            <field name="name">Customer</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">res.partner</field>
            <field name="view_type">form</field>
            <field name="view_mode">kanban,tree,form</field>
            <field name="context">{"search_default_customer":1}</field>
            <field name="help" type="html">
            <p class="oe_view_nocontent_create">
              bla bla bla
            </p>
            </field>
        </record>

        <record model="ir.actions.act_window.view" id="custom_res_partner_kanban_view_action">
            <field eval="1" name="sequence"/>
            <field name="view_mode">kanban</field>
            <field name="view_id" ref="custom_res_partner_kanban_view"/>
            <field name="act_window_id" ref="custom_res_partner_action"/>
        </record>

        <record model="ir.actions.act_window.view" id="custom_res_partner_tree_view_action">
            <field eval="2" name="sequence"/>
            <field name="view_mode">tree</field>
            <field name="view_id" ref="custom_res_partner_tree_view"/>
            <field name="act_window_id" ref="custom_res_partner_action"/>
        </record>

        <record model="ir.actions.act_window.view" id="custom_res_partner_form_view_action">
            <field eval="3" name="sequence"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="custom_res_partner_form_view"/>
            <field name="act_window_id" ref="custom_res_partner_action"/>
        </record>

        <menuitem id="menu_partner_form" parent="base.menu_sales" action="custom_res_partner_action" sequence="1"/>
    </data>
</openerp>

1 个答案:

答案 0 :(得分:0)

原因是因为<field name="name">CUSTOM</field>。巧合的是,我将此处的内容更改为CUSTOM,而在原始代码中,它仍然是Customer。它以某种方式表明我继承了原始视图。我不知道inherit_id的目的是什么。但在我更改了name之后,它运行正常。