Matt Fletcher
Matt Fletcher

Reputation: 9220

Set the tax_id for a sales order with PHP api in Odoo

I'm having a strange amount of trouble setting tax_id on Odoo sale.order.line models. My inital code is somewhat like this:

$sale_order_line = $models->execute_kw($info['database'], $info['uid'], $info['password'], 'sale.order.line', 'create', array(
  array(
    'name' => $product['name'],
    'order_id' => (int) $sale_order,
    'product_id' => (int) $product['id'],
    'product_uom' => 1,
    'product_uom_qty' => (float) $line_item->quantity->value(),
    'price_unit' => $product['list_price'],
    'tax_id' => array(13),
  )
));

The id of 13 definitely exists and has been set on order line items created in the front end. I've tried passing it in as a single integer, string, array of integers, array of strings, array of arrays of integers, etc etc, but still no tax_id is set when retrieving the model back again.

I even tried doing a create with no tax and then doing a write afterwards to set the tax, because I thought perhaps with a many2many relationship, that would be the only way to get it to recognise the connection between them, but that didn't work either.

Thanks in advance.

Upvotes: 0

Views: 1225

Answers (1)

Prakash Kumar
Prakash Kumar

Reputation: 2594

As tax_id is the Many2many field , so use can not pass the direct array of id in to it.

use this syntax 'tax_id'=>array(array(6,0,array(13)))

For more info visit my answer here create-a-record-into-many2many-table

I Hope it may solved your issue .

Upvotes: 4

Related Questions