Odoo Help


Understanding many2many field and API create method

on 5/25/16, 8:58 AM 1,314 views

I want to programaically add pos_order with lines and everything. I have came very far, but now I'm stuck on this issue. How would I pass tax information to pos_order_line. The model has a field called tax_ids, so my first assumption was to just put  tax_ids=[tax_id], but that gets ignored.

After searching many internets, I found out that I need to do something like that:

'tax_ids':[[0, 0, {tax_id}]]

With this I'm getting some xmlrpclib.py error that I don't understand:

File "/usr/lib/python2.7/xmlrpclib.py", line 647, in __dump raise TypeError, "cannot marshal %s objects" % type(value) TypeError: cannot marshal <type 'set'> objects

I'm sorry for spamming the forum, but I cannot help myself with this guy's question, although it looks the same:


I added the comment, but I don't think that question will ever get to the top again, so that's why I'm posting a new one.

This is my actual code that creates an order:

vals = {
'session_id': sid,
'lines': []
for line in myord['lines']:
vals['lines'].append([0, 0, #I also don't understand why these zeros are here :(
'product_id': line['product_id'],
'price_unit': flaot(line['TotalWTax']),
'discount': float(line['DiscountPercent'],
'tax_ids': [[0,0, {line['Tax_id']}]], #This causes my script to crash
'qty': line['Quantity']


Adan Cortes Medina
On 11/29/16, 2:36 PM

If you want to create one or more new records, issue a 0 command like this:

other_table_record1 = { 'field1': value11, 'field2': value12}
other_table_record2 = { 'field1': value21, 'field2': value22}
record_to_update = { 'some_field': 'value', ...
    'other_table_ids': [(0,0,other_table_record1),(0,0,other_table_record2)] # Must be a list, so keep the square brackets

So, in short:

  • 0 commands must be given as a list of triplets

  • In each triplet, the 1st element is 0 and 3rd element must be a dictionary

Reference: BaseModel write method in models.py (around line 3438)

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

1 follower(s)


Asked: 5/25/16, 8:58 AM
Seen: 1314 times
Last updated: 11/29/16, 2:36 PM