I need to make an alternate tree view for res.partner.
This is my code
<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>
The code above works, but it behaves like it inherits the original tree view. It shows the columns which I don't specify. How do I make a completely new tree?
Additional details:
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>
Turns out the cause was because of this <field name="name">CUSTOM</field>
. Coincidentally I changed content here to CUSTOM
while in my original code it was still Customer
. It somehow indicates that I inherited the original view. I don't know what's the purpose of the inherit_id
then. But after I changed the name
it works fine.