Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Creating new view from a old view

By
Lawrence
on 2/20/13, 12:23 PM 3,625 views

I have to create a view from the view "view_partner_tree"(base.res_partner) without touching the original. In the view that I create, I have to add some function field (not stored). I managed to create a new module displaying the view "view_partner_tree" on a different page. Would really kind of any of you to maybe guide me a bit through it or to give me a link that might help. (I have read anything google could find me with (inheritance, view)

_description = 'Aged Partner Balance'   
def _get_not_due(self, cr, uid, ids, name, arg, context):
    res = {}
    return res

_name = 'aged.partner.balance'
_columns = {
    'not_due': fields.function(_get_not_due, type='char', string="Not Due")       
    }   


    <record id="view_partner_tree" model="ir.ui.view">
        <field name="name">res.partner.tree</field>
        <field name="model">res.partner</field>
        <field eval="8" name="priority"/>
        <field name="arch" type="xml">
            <tree string="Contacts">
                <field name="name"/>
                <field name="function" invisible="1"/>
                <field name="phone"/>
                <field name="email"/>
                <field name="user_id" invisible="1" />
                <field name="is_company" invisible="1"/>
                <field name="country" invisible="1"/>
                <field name="country_id" invisible="1"/>
                <field name="parent_id" invisible="1"/>
            </tree>
        </field>
    </record>
   <record id="view_res_partner_filter" model="ir.ui.view">
        <field name="name">res.partner.select</field>
        <field name="model">res.partner</field>
        <field name="arch" type="xml">
            <search string="Search Partner">
               <field name="name"
                   filter_domain="['|','|',('name','ilike',self),('parent_id','ilike',self),('ref','=',self)]"/>
               <filter help="My Partners" icon="terp-personal+" domain="[('user_id','=',uid)]"/>
               <separator/>
               <filter string="Persons" name="type_person" icon="terp-personal" domain="[('is_company','=',0)]"/>
               <filter string="Companies" name="type_company" icon="terp-partner" domain="[('is_company','=',1)]"/>
               <separator/>
               <filter string="Customers" name="customer" icon="terp-personal" domain="[('customer','=',1)]" help="Customer Partners"/>
               <separator/>
               <filter string="Suppliers" name="supplier" icon="terp-personal" domain="[('supplier','=',1)]" help="Supplier Partners"/>
               <field name="category_id" string="Tag" filter_domain="[('category_id','ilike', self)]"/>
               <field name="user_id"/>
               <field name="parent_id" filter_domain="[('parent_id','child_of',[self])]"/>
               <group expand="0" string="Group By...">
                   <filter string="Salesperson" icon="terp-personal" domain="[]" context="{'group_by' : 'user_id'}" />
                   <filter string="Company" context="{'group_by': 'parent_id'}"/>
               </group>
           </search>
        </field>
    </record>


    <record id="action_partner_form" model="ir.actions.act_window">
        <field name="name">Aged Partner Balance</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">tree</field>
        <field name="context">{"search_default_customer":1}</field>
        <field name="search_view_id" ref="view_res_partner_filter"/>
    </record>

    <record id="action_partner_tree_view1" model="ir.actions.act_window.view">
        <field name="sequence" eval="1"/>
        <field name="view_mode">tree</field>
        <field name="view_id" ref="view_partner_tree2"/>
        <field name="act_window_id" ref="action_partner_form"/>
    </record>


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

</openerp>

What do you want to say about "different pages" : in a new menu or a new tab in form view?

Bonnet Denis
on 2/21/13, 5:23 AM

in a new menu

Lawrence
on 2/21/13, 9:15 AM
1

Bonnet Denis

--Bonnet Denis--
925
| 5 6 8
Vannes, France
--Bonnet Denis--

Engeneer at MGS Consulting Ouest at Vannes, FRANCE

Bonnet Denis
On 2/20/13, 12:40 PM

This is an example I make to a perso module:

<record id="view_task_form2_inherit" model="ir.ui.view">
    <field name="name">project.task.form.inherit</field>
    <field name="model">project.task</field>
    <field name="inherit_id" ref="project.view_task_form2"/>
    <field name="arch" type="xml">
        <field name="work_ids" groups="project.group_tasks_work_on_tasks" position="replace">
            <field name="work_ids" groups="project.group_tasks_work_on_tasks">
                <tree string="Task Work" editable="top">
                    <field name="id" invisible='1'/>
                    <field name="name" on_change="onchange_name(name,id)"/>
                    <field name="date" on_change="onchange_date(date,id)"/>
                    <field name="hours" widget="float_time" sum="Spent Hours" on_change="onchange_hours(hours,id)"/>
                    <field name="user_id" on_change="onchange_user_id(user_id,id)"/>
                </tree>
            </field>
        </field>
    </field>
</record>

Here the documentation about inheritance in Views in V6.1(Work with v7.0 too)

When you create a new menu, you associate this to a act_window and this act_window have to be associate to your custom view. If you need some more explication I can give it.

I have done something similar aswell. But now I want to create a new module that would looks like the page "Customers" but with like 7 more functions fields. (I read that doc a while ago, but thanks).

Lawrence
on 2/20/13, 12:50 PM

Inherit from "Customers" view, add some function fields and call your new view In your module.

Bonnet Denis
on 2/21/13, 5:18 AM

I thought that doing so would just add the new fields in the old "customers" view and wouldnt create a different view. I think I have a idea tho. Im going to try this right away. Anything i should put in the .py?

Lawrence
on 2/21/13, 9:18 AM

When I do that I get a error which says that it can't find the function field that i added in the model : "res.partner", but when i put mine "aged.partner.balance" it says that it cant render the view with this model

Lawrence
on 2/21/13, 9:38 AM

Can't find field 'not_due' in the following view parts composing the view of object model 'res.partner': Can't render view aged_partner_balance.view_partner_tree for model: aged.partner.balance

Lawrence
on 2/21/13, 9:39 AM
Bonnet Denis
on 2/21/13, 11:58 AM

yes :S do you want me to show you my .py and xml?

Lawrence
on 2/21/13, 12:05 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/20/13, 12:23 PM
Seen: 3625 times
Last updated: 3/16/15, 8:10 AM