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.

0

Understanding many2many field and API create method

By
Prowler
on 5/25/16, 8:58 AM 409 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:

https://www.odoo.com/forum/help-1/question/php-xpml-rpc-sale-order-line-tax-id-12763

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,
'partner_id':myord['partner_id'],
'pricelist_id':myord['pricelist_id'],
'user_id':myord['Cashier_user_id'],
'lines': []
}
d
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']
}
])

 

0
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)

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

1 follower(s)

Stats

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