tinyerp / odooly

Python library and CLI to interact with Odoo and OpenERP.
https://odooly.rtfd.io/
Other
60 stars 33 forks source link

Support question: How do I create expenses with tax correctly calculated? #11

Open partoneoftwo opened 4 years ago

partoneoftwo commented 4 years ago

How do I create expenses with tax correctly calculated?

When I use odooly to create an expense, I am able to create the expense, with the correct product chosen, and the specified date and amount. However the total is not correct, because the product I choose should have a TAX on it. Since all transactions on my expenses must show excluding and including VAT.

The goal here is: That the tax amount on the expense created by Odooly is calculated correctly.

My server/Odoo instance: In my case it works perfectly when manually entered, and the views and frontend calculate the tax value correctly when I use the mouse to select the correct product, the correct values are also then persisted to the database when clicking save.

The command I have tried to run is the following: ``

env['hr.expense'].create({'name': "Tiny Lasagna", 'product_uom_id': '1', 'quantity': '1', 'company_id': '1', 'unit_amount': '20', 'date': '2020-01-19','currency_id': '14','account_id': '205','payment_mode': 'own_account','analytic_account_id': '' ,'create_uid': '6','product_id': '5','company_currency_id': '14','sale_order_id': '','currency_id': '14','analytic_tag_ids': '','tax_ids':'','can_be_reinvoiced': '1','sale_order_id':'','description':'Little Bits','reference': 'Interdimensional Cable'})

I have tried the following:

There seems to be a hint from a tangentially related question on the Odoo forums: - https://www.odoo.com/fr_FR/forum/aide-1/question/account-invoice-tax-is-not-calculated-from-line-data-imported-to-account-invoice-136828

Maybe the clue lies in the view for hr.expense located at Views ---> hr.expense.sheet.form, which refers to several fields that seem relevant to tax on expense.

But I can't figure it out... And now I've exhausted all options

Any help or pointers?

theangryangel commented 4 years ago

You probably need to trigger the onchange specs.

Take a look at this section from the odoo development cookbook -

https://books.google.co.uk/books?id=Kv7fDAAAQBAJ&pg=PA141&lpg=PA141&dq=odoo+onchange+specs&source=bl&ots=jHXh3AmkuI&sig=ACfU3U2PFFuyrOd7_kxnut0tLavHSteL4g&hl=en&sa=X&ved=2ahUKEwiLkKr8qZzoAhXSYcAKHdoQCEoQ6AEwBXoECAQQAQ#v=onepage&q=odoo%20onchange%20specs&f=false

partoneoftwo commented 4 years ago

After way too many hours, I managed to get the functionality in Odoo to trigger; calculate taxes on created Expenses.

It does indeed calculate taxes now, so this is great!

This was achieved by running this command from Odooly: env['hr.expense'].create({'product_id':39,'company_id':1,'employee_id':2,'name': "Zibby Tiny Lasagna",'unit_amount':'100','untaxed_amount':'100','quantity':'1','analytic_account_id':16,'company_currency_id':14,'account_id':'205','product_uom_id':1,'analytic_tag_ids':[('is_editable','0',[])],'tax_ids': [(6, 0, [5])]})

Remainder: The products are supposed to have a tax setting, but this is bruteforced by the tax_ids command above. So right now, Odoo doesn't follow which tax setting which was set in the product_id.

I found a clue, which got me closer to the solution here: https://www.odoo.com/es_ES/forum/ayuda-1/question/solved-get-and-set-default-tax-by-python-command-line-82209