Odoo Help


insert new record into one2many field [Closed]

Hannes Smit
on 6/12/13, 9:37 AM 12,913 views

The Question has been closed

Sudhir Arya (ERP Harbor Consulting Services)
on 06/12/2013 09:51:29

I thought it was possible in OE7 to write to an object with a one2many field.

For example: I want to add a student to a course:

    cr, uid, [course_id], {
        'student_ids': (0, 0, {'name': 'John', 'age': 12})

Is this the right way to add a student to a course?

And yes, a course has a 'student_ids': fields.one2many(..) field.

Let's say that there are already 3 student on the course, and now I want to be adding 1 extra.

Take a look at 'https://doc.openerp.com/6.0/developer/2_5_Objects_Fields_Methods/methods/#osv.osv.osv.write' for the (0, 0, {}) notation.


Sudhir Arya (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 




Sudhir Arya
ERP Harbor Consulting Services
Sudhir Arya (ERP Harbor Consulting Services)
On 6/12/13, 9:41 AM

Try this:

course_osv.write(cr, uid, [course_id], {
    'student_ids': [(0, 0, {'name': 'John', 'age': 12})]

For a one2many field, a lits of tuples is expected.

Here is the list of tuple that are accepted, with the corresponding semantics:

(0, 0,  { values }) #link to a new record that needs to be created with the given values dictionary
(1, ID, { values }) #update the linked record with id = ID (write *values* on it)
(2, ID) #remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)


[(0, 0, {'field_name':field_value_record1, ...}), (0, 0, {'field_name':field_value_record2, ...})]
Hannes Smit
On 6/12/13, 9:49 AM

Ah, I found the syntax error I made. Have a look at the following code:

    cr, uid, [course_id], {
        'student_ids': [(0, 0, {'name': 'John', 'age': 12}])

yes, you didn't add tuple inside list.

Sudhir Arya (ERP Harbor Consulting Services)
on 6/12/13, 9:50 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: 6/12/13, 9:37 AM
Seen: 12913 times
Last updated: 5/12/16, 8:32 AM