MathieuM
MathieuM

Reputation: 1

Odoo v8 PHP Insert One2many or Many2many field

I am trying in Odoo v8 to create an invoice and its invoice lines using PHP. However, when creating an invoice line I need to population invoice_line_tax_id which is a many2many field.

I have tried to read this page but I cannot figure it out : https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.write

Here is how I create an invoice line

$result = $models->execute_kw($db, $uid, $password,
    'account.invoice.line', 'create',
    array(array(
        'invoice_id'=> 15,
        'product_id'=> 2,
        'quantity'=> 1,
        'name'=> 'Abonnement standard' ,
        'price_unit' => 50 ,
        'invoice_line_tax_id' => array( 0 , false , array( 2 ) )
    )));

I have the following error in return :

string 'Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 75, in xmlrpc_return result = openerp.http.dispatch_rpc(service, method, params) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc result = dispatch(method, params) File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch res = fn(db, uid, *params) File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", li'... (length=2004)

If I just put the invoice_line_tax_id this way :

'invoice_line_tax_id' => array( 0 , false , 2 )

It works but no tax is inserted.

Any idea how to make this work ?

Thanks in advance.

Upvotes: 0

Views: 912

Answers (2)

Bio
Bio

Reputation: 103

For those (like me) who struggle with odoo 10 :

Assuming your tax_id 1 exist in account_tax, correct syntax is invoice_line_tax_ids (note the final s) :

   'invoice_line_tax_ids'=> [[4,[1],false]]

Upvotes: 0

mauronet
mauronet

Reputation: 890

For me, it worked this way:

'invoice_line_tax_id'=>array(array(4, $tax_id,false))

I used 4 option because the tax is already created.

I think the other array is necessary because in documentation said:

This format is a list of triplets executed sequentially

Upvotes: 2

Related Questions