Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

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

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
treeviewmany2manyodoo8
1 Răspunde
22742 Vizualizări
Imagine profil
Pepiño

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

 

0
Imagine profil
Abandonează
Imagine profil
Denis Baranov
Cel mai bun răspuns

Update

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.one
        @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>


0
Imagine profil
Abandonează
Pepiño
Autor

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

Pepiño
Autor

I have edited my original post to clarify my question.

Denis Baranov

I have added "Update" section in the answer

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Access many2many field from the other side
many2many odoo8
Imagine profil
Imagine profil
1
mar. 15
6384
How can create a new button in the header of the tree view after the "create button or 'import' "? Rezolvat
treeview button odoo8
Imagine profil
Imagine profil
1
sept. 18
13095
How to get url of a tree view with respect to its server and database
treeview url odoo8
Imagine profil
0
oct. 17
4277
How to show many2many_checkboxes in multiple columns? Rezolvat
many2many checkbox odoo8
Imagine profil
Imagine profil
Imagine profil
2
sept. 17
10921
many2many widget editable tree does not save changes?
treeview editable many2many
Imagine profil
0
apr. 17
4072
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now