Intechnity-com / OdooJsonRpcClient

Odoo Client Json Rpc
MIT License
66 stars 29 forks source link

How to write Many2Many fields? (ODOO V12) #35

Open luke92 opened 2 years ago

luke92 commented 2 years ago

Hi, i have a problem for write some fields that are many2many fields

In this case, i'm creating a Invoice That invoice has invoice lines where each line has an array of taxes lines Using the library i set the tax ids but after create the invoice line the taxes not appear

This is an example of Invoice created from ODOO V12 using web browser image image

And this is an example of Invoice created from ODOO V12 using library PortaCapena image

I'm using this table "account.invoice" image with one2many relation to "account.invoice.line" image Then i set the tax_ids for this invoice lines in field "invoice_line_tax_ids" (This field is a many2many field type) image image

I'm setting the tax_id correctly

This is my code (My repo is here https://github.com/luke92/OdooNetFramework) The variable taxesId is getting from the product model First i create the invoice image After that i save each invoice line setting the id of invoice image

How can i save the "account.invoice.line" with "invoice_line_tax_ids" ?

In case of doubt, I am at your disposal

Thanks, Regards,

patricoos commented 2 years ago

Hi, I think I had once a similar issue and as I remember, you should use a different column for this, or add this tax to the product at first. I'll try to find some time on the weekend to check it.

Check this example with purchase order: PortaCapena.OdooJsonRpcClient.Example/OdooClientTests.cs - L654

luke92 commented 2 years ago

Hi, I think I had once a similar issue and as I remember, you should use a different column for this, or add this tax to the product at first. I'll try to find some time on the weekend to check it.

Check this example with purchase order: PortaCapena.OdooJsonRpcClient.Example/OdooClientTests.cs - L654

Thanks Patrick!

I tried what you mention (even with your new column too) but it doesn't work image image

luke92 commented 2 years ago

@patricoos I have a solution for this!

Here is my solution https://github.com/luke92/OdooNetFramework/blob/main/OdooIntegration/OdooIntegration.ConsoleApp/Many2ManyHelpers/OdooMany2ManyService.cs

Basicallly i authenticate with {baseUrl}/web/session/authenticate Sending a json for authenticate and get session_id {"jsonrpc":"2.0","params":{"db":"database","login":"username","password":"pass"}}

And then send a json structure to this url: {baseUrl}/web/dataset/call_kw { "jsonrpc": "2.0", "method": "call", "params": { "args": [ [ 60191 ], { "invoice_line_tax_ids": [ [ 6, false, [ 3 ] ] ] } ], "model": "account.invoice.line", "method": "write", "kwargs": { } }, "id": 12 }

The trick is replace the content of property args image image

Also for invoices, is necessary add taxline to invoice (add taxes in invoice line not generate taxes for invoice) image

patricoos commented 2 years ago

Congratulations! Good job, luke92 In the future, I will implement web client to my library, based on your example Thanks a lot!