Odoo Help


How do I change the columns displayed in a many2many tree view?

AJ Schrafel Paper Corp
on 4/20/13, 7:50 PM 14,846 views

I have a custom module with a tree view that display a many2many field. Everything works fine, i would just like to display different fields in the tree view.

This is the pertinant part of the code

    <tree string="Partner Contacts">
        <field name="partner_id" domain="[('customer','=',True),('opt_out','=',False)]"/>

Using the above XML code, the tree view displays the columns Name, Phone, Email.

How can I modify it so that the columns display are Name, City, State?



AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
| 4 5 8
Bronx, United States
--AJ Schrafel Paper Corp--

Exploring OpenERP for business

AJ Schrafel Paper Corp
On 4/23/13, 4:08 PM

I fixed it by doing the following:

<field name="partner_id" widget="many2many">
      <field name="name"/>
      <field name="city"/>
      <field name="state"/>

Still works in Odoo 10

Jérôme Thériault
on 4/27/17, 10:20 AM
On 4/23/13, 12:10 PM

You may define a custom tree view with the fields you want to show and explicitly use it for your many2many field


<field name="order_line" colspan="4" nolabel="1" context="{'form_view_ref' : 'module.view_id', 'tree_view_ref' : model.view_id'}"/>

where 'tree_view_ref' points to your custom tree view

On 4/21/13, 2:58 AM

Please check this sample. The model has a many2one field. This many2one is Calib_id. This is a connection with a two table. csyscmeascalibrate >> csyscmeascalibraterow. You can use this way to see what you want, and filter the data if is it necessary.


        <record model="ir.ui.view" id="csysc_measuringtoolcalibration_form_view">   
        <field name="name">csysc_measuringtoolcalibration.form</field>
        <field name="model">csyscmeascalibrate</field>
        <field name="type">form</field>       
        <field name="arch" type="xml">
        <form string="Measuring Equipment Calibration Plan">
                <group colspan="4" col="6">                                 
                <field name="name"/>     
                <field name="Title"/>
                <field name="ISO_form_number"/>
                <field name="type"/>    
                                <notebook colspan="4">
                                    <page string="Controlled Calibration points">
                                     <field colspan="4" name="Calib_lines" nolabel="1" widget="one2many_list" mode="tree"/>                                                                                                 



class csyscmeascalibraterow(osv.osv):
_name = "csyscmeascalibraterow"
_description = "calibration data sheet"
_columns = {    
    'name'  : fields.char('Calibration point:',size=40, required = True, help='The name of the calibration point, like jig width or ring diameter...etc'),
    'Calib_id':fields.many2one('csyscmeascalibrate','Parent Calibration', select=False, ondelete='cascade'),
    'NomValue' : fields.float('Nominal Value:',size=40, required = False, help='Nominal measuring value: like 12.00'),
    "Max_deviation" : fields.char('Max deviation:',size=40, required = False, help='Maximum deviation from nominal measuring value: like 12.00'),

class csyscmeascalibrate(osv.osv):
_name = "csyscmeascalibrate"
_description = "calibration data sheet"
_columns = {
    'name'  : fields.char('Calibration Name:',size=40, required = True, help='The name of the calibration like Calipper 0-150...etc'),
    'Title'     : fields.char('Calibration title:',size=40, required = True, help='Title of the calibration point, like measuring series with jig...'),     
    'ISO_form_number' : fields.char('Iso Form Number:',size=40, required = False, help='The ISO system form number'),
    'type': fields.many2one('csyscmtooltypes','Equipment type',required = True),
    'Calibration_child_row_id': fields.many2one('csyscmeascalibrate','csyscmeascalibrate'),
    'Calib_lines': fields.one2many('csyscmeascalibraterow', 'Calib_id', 'Calibration Plan id'),  

thank you for your comment, but how does this change the columns automatically displayed when a many2many field is displayed?

AJ Schrafel Paper Corp
on 4/21/13, 4:54 PM

As I think this is depend the relation. Please put it your code, and the situation will be clear, what you want...

on 4/22/13, 1:59 AM

klacus, your example does not customize the fields you want to show within the nested tree view

on 4/23/13, 12:06 PM

Yes because this is show all of the fields from csyscmeascalibraterow. If you want to show a special view, you must declare it in xml, and after that you need to call according by tree name. (As I know :-) )

on 4/23/13, 2:07 PM

"i would just like to display different fields in the tree view.", that's the key part

on 4/23/13, 3:08 PM

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.


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

0 follower(s)


Asked: 4/20/13, 7:50 PM
Seen: 14846 times
Last updated: 3/16/15, 8:10 AM