This question has been flagged
2 Replies
8163 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>

 

Avatar
Discard

Can u show fields?....

Author

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

Best Answer

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>

Avatar
Discard
Author

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!

Best Answer

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

Avatar
Discard
Author

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