Skip to Content
Menu
This question has been flagged
1 Reply
2668 Views
def currency_convert(amount, currency):
SAR = docs.env['res.currency'].sudo().search([('name', '=', 'SAR')])
convert_currency = currency.compute(amount, SAR)
return convert_currency

This function convert into sar with latest exchange rate but i want it to convert with according to date same as invoice date and exchange rate date help please i tried but not getting it



Avatar
Discard
Best Answer

Hi Muhammad Kamil,
Compute function has already that functionality. You need to pass the date with context and called the compute method from the currency model.Please try with this code.

    convert_currency = currency.with_context(date= your invoice date).compute(amount, SAR)


This will find the currency rate <= to your invoice date.
Hope it will help you
Please Vote for the Answer if works.

Avatar
Discard

Hi Malay,

I'm trying it from € to usd in qweb

<t t-set="convert_currency" t-value="o.currency_id.with_context(date = o.date).compute(o.amount_total, USD)" />
<t t-esc="convert_currency" />
but it doesn't work, it show the same amount, what I'm doing wrong?
br

Hi,
Please check your record currency "o.currency_id".
Please check the date "o.date" and the currency rate for the USD.

Please check the condition of currency rate date <= to your invoice date.

Hope it will help you.

Related Posts Replies Views Activity
2
Feb 22
6918
2
Aug 23
1649
0
Oct 20
2519
4
Oct 19
3066
2
Feb 24
80