使用Odoo中的PHP api为销售订单设置tax_id


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

我在Odoo sale.order.line型号上设置tax_id时遇到了一个奇怪的问题。我的初始代码有点像这样:

$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),
  )
));

13的id肯定存在,并且已经在前端创建的订单行项目上设置。我已经尝试将其作为单个整数、字符串、整数数组、字符串数组、整数数组数组等传递,但在再次检索模型时仍然没有设置tax_id。

我甚至试着在不纳税的情况下做create,然后做write来设定税收,因为我认为也许有了many2many关系,这将是让它认识到它们之间联系的唯一方法,但这也不起作用。

提前谢谢。

由于tax_idMany2many字段,因此使用无法将id的直接数组传递给它。

使用此语法'tax_id'=>array(array(6,0,array(13)))

欲了解更多信息,请访问我的答案,在这里创建一个多人记录表

我希望它能解决你的问题。