0

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>
William Wino
  • 3,599
  • 7
  • 38
  • 61
  • there should be no problem with a complete new tree view. but form views could be special, because the inherited model could have a lots of required fields, which you have to include in your view. i don't see any problems with your code, but there is missing so much. python code and xml menu and so on. can you provide us this info? – CZoellner Apr 14 '14 at 10:51
  • What do you mean the form views could be special? I've already made a "special" form view. And it works just fine, but not this tree view. I even use the same method. – William Wino Apr 15 '14 at 01:51
  • i meant that normal tree views (not editable) are kind of readonly, because if you click an entry, the form view opens up... so there is no problem if you make a tree view without required fields. a form view without them, would be bad, because you probably can't save anything with it. – CZoellner Apr 15 '14 at 06:14
  • . . . Sorry, I don't get what you mean...What do I do? So I got a working completely different form from the same model. How do I get a working completely different tree from the same model? – William Wino Apr 15 '14 at 06:51
  • not that important... my point: i need more info from you. python code (your model) and all xml code (ir.ui.view, ir.actions.act_window and menuitem), because i don't see mistakes in your code above except that you've used ir.actions.act_window.view, what i've never used before – CZoellner Apr 15 '14 at 06:55
  • There I've added all the source code. The kanban works fine as well, only the tree has the problem. – William Wino Apr 15 '14 at 07:16
  • The `ir.actions.act_window.view` is to prevent the system from using the top priority view. Because I want to specify my own view for this particular model without overriding the original. – William Wino Apr 15 '14 at 07:21
  • thx for the code, but i don't see any mistake :( i never used ir.actions.act_window.view, because i never needed it, but if it's working with kanban and form view the fields sequence/priority can't be the problem. sorry i don't know what's wrong, should be working :-( – CZoellner Apr 15 '14 at 07:49
  • Can you try this on your computer? – William Wino Apr 15 '14 at 08:09
  • i really would, but i'm at work, sorry – CZoellner Apr 15 '14 at 08:10
  • Allright, thanks. Please do try when you have the time to. – William Wino Apr 15 '14 at 09:03

1 Answers1

0

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.

William Wino
  • 3,599
  • 7
  • 38
  • 61