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)
string='Tags',
# Relational field attributes:
auto_join=False,
context="{}",
domain="[]",
ondelete='cascade',
)
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"
font="italic:stage_state!='open'"
delete="false">
<field name="is_done" invisible="True"/>
<field name="stage_state" invisible="True"/>
<field name="name"/>
<field name="tag_ids"/>
</tree>
</field>
</record>
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).
http://i.imgur.com/G44hQh4.png
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