Odoo Help


Store many2one model records in model with one2many field - how?

on 4/25/13, 6:42 AM 3,040 views

If I have two models, f.e. : 'my.model.items' and 'my.model' where 'my.model.items' has many2one field to 'my.model' and 'my.model' has one2many field to 'my.model.items'

How could I implement ability to select from existing 'my.model.items' records in 'my.model'?

Re-Edit: Having models as described above, in 'my.model' form I only have functionality to create records in 'my.model.items'. I would like to have functionality in 'my.model' form to select multiple existing records from 'my.model.items', and create a record containing this selection in 'my.model'.

What you need? Explain please.

Francesco OpenCode
on 4/25/13, 6:48 AM

Please see edit section at the end of question.

on 4/25/13, 6:53 AM

Francesco OpenCode

--Francesco OpenCode--
Francesco OpenCode
| 5 7 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 4/25/13, 6:55 AM

It's impossible in OpenERP. You can only create, select and delete one record every time in one2many view. Only in tree view you can select all the row you want.

Perhaps i did not make my point clear. Please see re-edit in question. I want not to be able to select, but to create a record from selection.

on 4/25/13, 7:00 AM
Nehemias Herrera
On 12/8/14, 2:08 PM

I want to get the same result as Antanas, I have models A and B:

class A (models.Model):
    _name = 'example.a'

    name = fields.Char(string="Model A")

    b_id = fields.Many2one('example.b', string='Model B')

class B (models.Model):

   _name = 'example.b'

   name = fields.Char(string="Model B")

    a_ids = fields.One2many('example.a', 'b_id', string="Models A")

I want to add an item in a_ids from the existing records of A, not create new ones, how can this be achieved ? thanks in advance

Nehemias, your question is a bit different from Antanas. In your case you just need to set the value of b_id field in Class A to the ID of the Class B you want to link. Or, if done via Class B you can write with the following value: {'a_ids': [(4, ID_of_class_a_to_link)]}

on 12/9/14, 6:31 AM

Another way to achieve it via UI trick is to set the widget="many2many_list" in tue a_ids field in your view.

on 12/9/14, 6:33 AM


| 5 3 6
Jakarta, Indonesia
On 12/9/14, 6:34 AM

Antanas, I know this is an old question, but if you still need it, what you can do is create a wizard to select the my.model.items to include and then create my.model from the wizard based on the selection.

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 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: 4/25/13, 6:42 AM
Seen: 3040 times
Last updated: 3/16/15, 8:10 AM