Skip to Content
Menu
This question has been flagged

I am trying to convert a float amount from one currency to another currency (odoo version 8), amount_currency is a float field. for example amount_currency has a usd currency then I want to convert it to company currency.

below is my code, tell me where I am wrong.

  @api.onchange('amount_currency')

    def currency_onchange(self):

        for move_line in self.amount_currency:

            res = self.env['res.currency'].compute(move_line.amount_currency,

                                                    move_line.company_id.currency_id)

Avatar
Discard
Best Answer

In your code, you have not specified from which currency you are trying to convert.

According to your code:

res = self.env['res.currency'].browse(FROM_CURRENCY).compute(move_line.amount_currency,

                                                    move_line.company_id.currency_id)


Refer below example: w.r.t Invoice for more details


inv = self.env['account.invoice'].browse(invoice_id)
currency = inv.currency_id.with_context(date=inv.date_invoice) # Invoice Currency
company_currency = inv.company_id.currency_id # Company Currency
currency.compute(AMOUNT, company_currency) # From Invoice Currency, amount is converted to Company's Currency
Avatar
Discard
Related Posts Replies Views Activity
0
Feb 16
4152
2
Mar 15
3988
0
Dec 24
35
1
May 24
1075
1
Jan 24
605