Odoo Help

Welcome!

This community 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.

2

Tree view of users in tab

By
code_shaman
on 2/20/13, 9:27 AM 1,439 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"/>
                                </tree>
                            </field>
                        </page>
                        <page string="Account Manager">
                            <label string="Account Mananger"/>
                            <field name="user_ids" colspan="4">
                                <tree string="Account manager">
                                    <field name="id"/>
                                </tree>
                            </field>
                        </page>
                    </notebook>                 
                </form>
            </field>

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:

Eg.

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

Daniel Reis

--Daniel Reis--
3436
| 6 7 9
Lisbon, 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.

code_shaman
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
0
Angela
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

code_shaman
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) ?

Angela
on 2/21/13, 4:56 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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