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.

2

[SOLVED] How can I change the popup form which a function field generates?

By
Juan Formoso
on 10/22/14, 12:22 PM 938 views

I have created a new model, called res.partner.link.category, whose fields are: active_category, partner_idlink_category_idtypedate and observations.

And in the model res.partner, I added a new field (a function of type many2many pointing to the new model I have created). Here the Python code:

'history': fields.function(_get_history, type='many2many',
                            obj="res.partner.link.category",
                            method=True, string='Categories'),

Then, I want to show it in the res.partner form, as a list of records, so I added this code to the XML of res.partner form:

<group>
    <field name="history" nolabel="1">
        <tree string="Categories">
            <field name="active_category"/>
            <field name="link_category_id"/>
            <field name="type"/>
            <field name="date"/>
            <field name="observations"/>
        </tree>
    </field>
</group>

It works great. Note that I do not show the field partner_id inside the tree, and in fact it is not being shown, so perfect. But, if I click on any record of the tree, a popup form is opened, with all the fields of res.partner.link.category, including partner_id, which I do not want!

So I would like to know how to modify that form (I tried to create the next customized form for res.partner.link.category):

<record id="res_partner_link_category_view" model="ir.ui.view">
    <field name="name">res.partner.link.category.form</field>
    <field name="model">res.partner.link.category</field>   
    <field name="type">form</field>
    <field name="arch" type="xml">
        <group>
            <field name="active_category"/>
            <field name="link_category_id"/>
            <field name="type"/>
        </group>
        <group>
            <field name="date"/>
            <field name="observations"/>
        </group>
    </field>
</record>

This last code is being ignored of course. I did not know where I could declare this form view and I did it in the same XML document where I modified the res.partner form (through inheritance). I do not know if it can be a problem, I guess not.

Anyone can help me, please? Thank you!

EDIT (this is my new declaration of the form, not working yet)

<group string="Activity Summary">
    <field name="history" nolabel="1">
        <form string="Categories" version="7.0">
            <group col="4">
                <field name="link_category_id"/>
                <field name="type"/>
            </group>
            <group col="4">
                <field name="date"/>
                <field name="observations"/>
            </group>
        </form>
        <tree string="Categories">
            <field name="active_category"/>
            <field name="link_category_id"/>
            <field name="type"/>
            <field name="date"/>
            <field name="observations"/>
        </tree>
    </field>
</group>

Hola Juan, You can just add a form inside of the field, as you do with the tree: ...

Pau Ubach
on 10/23/14, 5:13 AM

Hey, I do not know why, but suddenly all the comments were removed when I sent the last one. I had written you that I needed to show a tree with only one record per category (the one with the latest date), so I used a function to return the list with the codes of these records.

Juan Formoso
on 10/23/14, 5:19 AM

OK, now I understand why you use the function field.

Pau Ubach
on 10/23/14, 5:25 AM

I assume you're defining the many2many field for the relation in res.partner.link.category, aren't you?

Pau Ubach
on 10/23/14, 5:26 AM

No, I am not. The field function of type many2many is declared in res.partner.

Juan Formoso
on 10/23/14, 6:07 AM

OK. First of all, you shouldn't edit the res.partner. You should create a new module that inherits from it instead.

Pau Ubach
on 10/23/14, 6:14 AM

Yes, I did so. The name of my module is res_partner_extended, inherits from res.partner and adds that column function of type many2many, pointing to res.partner.link.category, a table created by me from zero.

Juan Formoso
on 10/23/14, 6:17 AM

Great. I'm totally lost. When I had to do for one2many I just checked how was it done in an existing module. I don't know if there's any doing what you need. If you solve it, please post how have you done.

Pau Ubach
on 10/23/14, 6:33 AM

Ok, I'll do that. Thank you so much for your patience.

Juan Formoso
on 10/23/14, 6:37 AM

No problem. I have had people having patience with me, so trying to help the others is the way to repay for it.

Pau Ubach
on 10/23/14, 6:40 AM
0

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 10/24/14, 2:02 AM

I assume you want to show just the tree view for M2M field, but unfortunately you cant prevent it from opening the form view...

Whenever you define a O2M or M2M field in view: when you have embedded its views within the field declaration, then preference are given to those local views, if not then it searchs whether any views exists for that object, if none, then odoo uses a default view by dumping all the fields into form view...
 

So in your code [edited code] though you have locally defined the views, but what you missed was the "mode" property to be set, which tells odoo that the views are defined locally...

Here your code goes something like this:

<field name="history" mode="tree,form" ... >

 

I was waiting for you, deep ;). Actually my last comment in the question was done as a tribute to you.

Pau Ubach
on 10/24/14, 2:10 AM

Oh is it.. :):) thank you

deep
on 10/24/14, 2:14 AM

Thank you deep, and Pau again. Now I know why OpenERP is behaving this way.

Juan Formoso
on 10/24/14, 3:57 AM

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

2 follower(s)

Stats

Asked: 10/22/14, 12:22 PM
Seen: 938 times
Last updated: 3/16/15, 8:10 AM