Skip to Content
Menu
This question has been flagged
1 Reply
7406 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>

Avatar
Discard

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

Author

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.

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

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

Author

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

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

Author

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.

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.

Author

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

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

Best Answer

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" ... >

 

Avatar
Discard

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

Oh is it.. :):) thank you

Author

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