This question has been flagged

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']
}
])

 

Avatar
Discard
Best Answer

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)

Avatar
Discard