Odoo Help


Odoo 8 - Many2Many field in a tree view, how to show it in two o more columns?

Eduardo BP
on 5/17/15, 4:05 PM 5,447 views

Hi Odoo developers,

I would want to show a many2many field from a module in its tree view but splitted in columns. Here is my example.

I have a TodoTask model with a field named tag_ids (a task may have multiple tags).

class TodoTask(models.Model):
_inherit = 'todo.task'
# Relational fields
stage_id = fields.Many2one('todo.task.stage', 'Stage')
tag_ids = fields.Many2many(
'todo.task.tag', # related= (model name)
'todo_task_tag_rel', # relation= (table name)
'task_id', # column1= ("this" field)
'tag_id', # column2= ("other" field)
# Relational field attributes:

The Tag model:

class Tag(models.Model):
_name = 'todo.task.tag'
name = fields.Char('Name', size=40, translate=True)
# Many2many inverse relation
task_ids = fields.Many2many('todo.task', string='Tasks')
# Hierarchic relations:
_parent_store = True
_parent_name = 'parent_id' # the default
parent_id = fields.Many2one(
'todo.task.tag', 'Parent Tag', ondelete='restrict')
parent_left = fields.Integer('Parent Left', index=True)
parent_right = fields.Integer('Parent Right', index=True)
child_ids = fields.One2many('todo.task.tag', 'parent_id', 'Child Tags')

The tree view associated to TodoTask model:

<record id="todo_app.view_tree_todo_task" model="ir.ui.view">
<field name="name">To-do Task Tree</field>
<field name="model">todo.task</field>
<field name="arch" type="xml">
<tree colors="gray:is_done==True"
<field name="is_done" invisible="True"/>
<field name="stage_state" invisible="True"/>
<field name="name"/>
<field name="tag_ids"/>

The most important part of the above view is field name="tag_ids".
tag_ids is a Many2Many field in TodoTask model (todo.task) related to Tag model (todo.task.tag).

The problem is that this tree view shows only one column for tag_ids (see column Tags in the next image).


I would like to show the Many2Many field (tag_ids) from TodoTask model in more than one column in the tree view associated to TodoTask model: one column for tag name, another column for another field from Tag model, ...

nameCourse | start_date Course | tag name | tag parent name |
course 1         2015-5-15                 tag1          tag2
course 1         2015-5-15                 tag3          tag2



IT Libertas

--IT Libertas--
| 4 3 7
Saint Petersburg, Russian Federation
--IT Libertas--

Visit us: itlibertas.com

IT Libertas is a team of developers and automation experts to help you to unlock Odoo ERP system's potential. We have been communicating with end users to whom the software became a main business tool since 2012. As a result, we are proud of dozens of successful implementations.

IT Libertas guarantees deadlines predictability and transparent pricing. We rely upon the best international practices and invest in local markets' study. That is why the company's services are in demand of European, Asian, American and African entrepreneurs.

We are open for cooperation and keep searching for new solutions to the end that IT Libertas clients go ahead of the curve, deal with less routine and generate more profit.

IT Libertas
On 5/19/15, 3:16 PM


I got your point. It is impossible to do it by standard instrument, you will have to change the widget (a lot of work by modifying javascript). Basically, there can't be table inside table in xml Odoo at the moment.

The only solution which I can see:

1) To modify display_name field (name_get in OpenERP 7), in order it will show all necessary data. For example:

        @api.depends('name', 'ref ')
        def _get_display_name(self):
            self.display_name = name + ref
display_name = fields.Char(string='Name', compute='_get_display_name',) name = fields.Char(string='Name') ref = fields.Char(string='Ref')

2) To use widget many2many_tags inside column of tags.

You also may try to add intermediary class, which will consists of: 1. class_x fields (inherits from this class), 2. tag as M2O field, 3. tag fields as related fields. Then you will have a tree with all the columns.

Initial answer

If I understood you in a right way, you would like to add columns from todo.task.tag model. If so, everything you need is to add tree inside tag_ids. E.g.: 

<field name="tag_ids"> <tree> <field name='name '/> <field name='parent_id '/> </tree> </field>

Your solution doesn't work in a tree view, only in a form view. I want to show different columns in a tree view for a many2many field. model Course(models.Model): name = fields.Char(string='Name Course') max_seats = fields.Integer() start_date = fields.DateTime() tag_ids = fields.Many2many('todo.task.tag') model Tag(models.Model): _name="todo.task.tag" name = fields.Char() quality = fields.Integer() In the Course's form view, I want to show two columns for the tag_ids field: name and quality: -------------------------------------------------------------------------------------------------- Name Course | max_seats | start_date | name (tag_ids) | quality (tag_ids) | -------------------------------------------------------------------------------------------------- course 1 25 2015-5-5 tag1 25 course 2 70 2015-5-6 tag2 35

Eduardo BP
on 5/19/15, 10:52 PM

I have edited my original post to clarify my question.

Eduardo BP
on 5/19/15, 11:10 PM

I have added "Update" section in the answer

IT Libertas
on 5/20/15, 5:39 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.


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)


Asked: 5/17/15, 4:05 PM
Seen: 5447 times
Last updated: 5/20/15, 9:37 AM