Odoo Help

0

New model many2many selection

By
Aitor Bouzas
on 1/20/15, 4:02 AM 2,092 views

Hi everyone,

I've added a new model with my custom module, and now I want to add a many2many relation field into res.company, but as I click "add" in this relation field it shows up a tree view with just one field from the new model (instead of the three componing the model...). Is there anyway to edit this popup view?

My model has just 3 fields: Postal Code (integer), City (text), Additional Description (text) and I want to show them all when you are selecting multiple values for the many2many field...

This is my actual xml view for res.company:

            <field name="arch" type="xml">
                <field name="company_registry" position="after">
                    <field name="zips_asignados" widget="many2many">
                        <tree>
                            <field name="zip"/>
                            <field name="name"/>
                        </tree>
                    </field>
                    <field name="invoicing_company" />
                </field>
            </field>

But this only shows zip and name into the res.company view, as I click "add" only "name" is showing in the new popup window...

Thanks in advice

SOLUTION:

Make a tree view for new model:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="zips_tree_view" model="ir.ui.view">
            <field name="name">zips_tree_view</field>
            <field name="model">zips</field>
            <field name="arch" type="xml">
                <tree string="Zips">
                    <field name="zip"/>
                    <field name="name"/>
                </tree>
            </field>
        </record>
    </data>
</openerp>

And reference it in the res.company view:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="view_company_form" model="ir.ui.view">
            <field name="name">res.company.form.inherit</field>
            <field name="model">res.company</field>
            <field name="inherit_id" ref="base.view_company_form" />
            <field name="arch" type="xml">
                <field name="company_registry" position="after">
                    <field name="zips_asignados" context="{'tree_view_ref':'zips_tree_view'}" />
                    <field name="invoicing_company" />
                </field>
            </field>
        </record>
    </data>
</openerp>

 

Can u show fields?....

Umashankar Subramani
on 1/20/15, 4:39 AM

If you mean if I can show the fields in the "add" button, then the answer is YES :)

Aitor Bouzas
on 1/20/15, 4:58 AM
4
Hardikgiri Goswami
On 1/20/15, 4:33 AM

Hello Aitor,

You need to add tree view for your new model.

<record model="ir.ui.view" id="[unique id]">
            <field name="name">name for the view</field>
            <field name="model">new.model.name</field>
            <field name="arch" type="xml">
                <tree string="">
                  <field name="name" />

                  <field name="zip" />

                  <field name="description" />
                </tree>
            </field>
        </record>

Hands down, I just needed to add a tree view like this, and make a reference to it in the res.company view. I'm editing the post to show it. Thanks!

Aitor Bouzas
on 1/20/15, 4:48 AM
1

Try the following:

            <field name="arch" type="xml">
                <field name="company_registry" position="after">
                    <field name="zips_asignados" widget="many2many">
                        <tree>
                            <field name="zip"/>
                            <field name="name"/>
                        </tree>
                       <form>
                             <field name="additional_desc"/>
                             <field name="postal_code"/>
                             <field name="city"/>
                      </form>

                    </field>
                    <field name="invoicing_company" />
                </field>
            </field>

Here we have added the form view to be shown when you will click on "Add" button. It is same way as we defined 'tree' view.

Hope this helps !!.

Thanks for the anwser, but this didn't seem to work...

Aitor Bouzas
on 1/20/15, 4:47 AM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 1/20/15, 4:02 AM
Seen: 2092 times
Last updated: 3/16/15, 8:10 AM