Odoo Help


Tree view of users in tab

on 2/20/13, 9:27 AM 1,943 views

I'm building a module where the user will have a window view where he can choose start, stop date. Two tabs with tree views where he can add analytic account and in the other users.

I don't get a tree-view in my tab. I only get a field where I can choose one user.

I have the columns set like this:

_columns = {
            'start_date': fields.date('Start Date', required=True),
            'stop_date': fields.date('Stop Date', required=True),
            'analytic_accounts': fields.one2many('account.analytic.account', 'id', 'Project'),
            'user_ids': fields.one2many('res.users', 'id', 'Account managers')

And in my view looks like this:

<field name="arch" type="xml">
                <form string="Project followup report">
                    <field name="start_date"/>
                    <field name="stop_date"/>
                    <notebook tabpos="up" colspan="4">
                        <page string="Projects" name="projectsTab">
                            <label string="Project"/>
                            <field name="analytic_accounts">
                                <tree string="Projects" editable="top">
                                    <field name="name"/>
                                    <field name="state"/>
                        <page string="Account Manager">
                            <label string="Account Mananger"/>
                            <field name="user_ids" colspan="4">
                                <tree string="Account manager">
                                    <field name="id"/>

I'm on a 6.0.3 installation.

I'm might have the wrong approach on this one. The thing I want to do is to have a list(tree) where I can add and remove users. Then add a button that calculate something depending on the users in the list.

Solution many2many was the way to go. The relationtable names could be anything:


'analyticAccounts': fields.many2many('account.analytic.account', 'analytic_account_rel', 'analytic_account_id', 'Projects'),

Daniel Reis

--Daniel Reis--
| 7 8 9
Linda-a-Velha, Portugal
--Daniel Reis--

Author of the "Odoo Development Essentials" book.

Applications Manager at Securitas Portugal

Github: https://github.com/dreispt

Twitter; @reis_pt

Daniel Reis
On 2/20/13, 9:49 AM

many2one is a one-value foreign key.

one2manycould handle that, but it requires you to add a foreign key (many2one) on the related table.

You probably should use many2many fields. Please note that the documentation is outdated - some filed arguments now are automatically handled and not required anymore.

fields.many2many('other.object.name', 'Field Name')

In this case:

'analytic_accounts': fields.many2many('account.analytic.account', 'Projects'),

The ORM handles the creation of the database table (*_rel) to hold this information.

How do I use a many2many on a (osv.osv_memory) object? I don't have any releationship table for this, or am I missing something.

on 2/20/13, 9:51 AM

I improved my answer to explain this. osv_memory objects should behave just like normal objects. They are also stored in the database nor, the difference is that their data gets cleaned up regularly by a scheduled job.

Daniel Reis
on 2/21/13, 5:08 AM
On 2/20/13, 9:39 AM

Not sure about my answer here, I'd have to test, but is it possible the many2one is inverted, and indeed, within your object there is only one object to define? This could explain why the GUI suggests a "select one element" widget rather than a tree...

I had turned the relation backwards. I now get the tree. But it's empty and I cannot add existing users to the tree

on 2/20/13, 9:48 AM

Any chance it is simply read only? Normally that should work, have you taken a look at other examples (for example "invoice lines" on the "invoice" object) ?

on 2/21/13, 4:56 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

0 follower(s)


Asked: 2/20/13, 9:27 AM
Seen: 1943 times
Last updated: 3/16/15, 8:10 AM