DEV Community

Exchange Rate API
Exchange Rate API

Posted on

Q&A: How Do I Fetch RBI or SBI Exchange Rates Automatically in Odoo 16?

This question comes up on the Odoo forum again and again. One recent version, asked on odoo.com, reads roughly:

We run Odoo 16 Enterprise with Indian accounting. For customer invoices and customer receipts we need the daily rate from the Reserve Bank of India or State Bank of India for USD, EUR, GBP and so on. Odoo fetches rates from the European Central Bank and other international banks, but there is no RBI or SBI option. Is there anything built in? If not, what's the recommended way to build it?

The answer it got there was "not built in, check whether RBI or SBI have an API". That's true, but it stops short of a solution. Here are the questions as a Q&A, with working answers.


Q1. Does Odoo 16 have an RBI or SBI rate provider?

No. In Odoo Enterprise, Accounting > Configuration > Settings > Currencies > Automatic Currency Rates offers a fixed list of providers (the European Central Bank, Bank of Canada, Banxico and a few others, mostly tied to a country's localisation). India isn't one of them. Odoo Community has no automatic rates at all without the OCA currency_rate_update module, which doesn't include India either.

The ECB does publish an INR rate, but it's the ECB's euro reference rate, not the RBI's rate, so it doesn't satisfy "as per RBI".

Q2. Should it be RBI or SBI?

They're different rates for different jobs, so decide first:

Purpose Rate usually used Why
Customer invoices, vendor bills and month-end revaluation in the books (AS 11 / Ind AS 21) RBI / FBIL reference rate An official, published daily spot rate that auditors can check
Income-tax conversions under Rule 115 (and Rule 26 for TDS) SBI TT buying rate Named by the Income-tax Rules
GST value of goods, customs on a bill of entry or shipping bill CBIC notified rate Section 14 of the Customs Act; CGST Rule 34(1)
What the bank actually credited on a receipt Your bank's rate on the advice That's the cash you got

For "customer invoicing and customer receipts", the usual answer is the RBI reference rate for the invoice. At receipt, the payment is recorded in foreign currency and Odoo posts the difference to the exchange gain/loss account automatically. You don't need SBI's rate in Odoo for that; you need the right amount from the bank advice.

If your CA wants SBI's TT rate anyway (some firms use it for everything to keep one source), Q5 shows how.

Q3. Does the RBI have an API?

Not a documented developer API. The reference rate is computed by FBIL (Financial Benchmarks India) and published around 1:30 pm IST and listed by the RBI on its website each business day for USD, EUR, GBP and JPY. FBIL's site serves the table to its own web page, and the RBI publishes an archive, but neither is a supported, keyed API you can build on. SBI publishes its card rates as a PDF.

So you either scrape those pages, or use an API that already carries them. The examples below use AllRatesToday, which serves the RBI/FBIL reference rate (history back to 2003) and SBI's TT buying and selling rates (history back to 2020) as JSON. Disclosure: that's our product. The Odoo side works the same with any source.

Q4. What's the cleanest way to get RBI rates into Odoo's own "Automatic Currency Rates"?

Add a provider module. Odoo's currency_rate_live module (Enterprise) is built to be extended: a provider is a selection_add on res.company.currency_provider plus a _parse_<provider>_data(available_currencies) method that returns rates. Odoo's daily cron, the Interval setting and the Update now button then work unchanged.

There's an open-source addon that does exactly this, odoo-central-bank-rates (LGPL-3). You choose AllRatesToday (official central-bank rates) as the service and set the bank code to rbi. Two notes for the forum's case:

  • It targets Odoo 17. The extension points it uses (currency_provider, _parse_*_data, the settings view) also exist in Odoo 16's currency_rate_live, so backporting means changing version in the manifest to 16.0.x and testing it in a staging database. We haven't tested 16 ourselves.
  • Direction is handled. The RBI quotes INR per 1 foreign unit; Odoo stores foreign units per 1 company currency unit. The addon inverts the rows, and Odoo rebases them to the company currency, so an INR company gets USD = 1 / 92.4895 = 0.010812 for 25 November 2026.

For Odoo Community, the same repo has a provider for the OCA currency_rate_update module.

Q5. I don't want to install a module. Is there a simpler way?

Yes. Run a small job outside Odoo (cron, a CI scheduler, or Odoo's own scheduled action calling the same logic) that reads the rate and writes res.currency.rate over XML-RPC. This version loads the RBI reference rate, or SBI's TT rate if you pass --sbi:

import sys, xmlrpc.client, requests

ODOO, DB, USER, PWD = "https://yourco.odoo.com", "yourco", "admin@yourco.in", "api-key-or-password"
H = {"Authorization": "Bearer art_live_your_key"}
CURRENCIES = ["USD", "EUR", "GBP", "AED"]

def rbi():
    t = requests.get("https://allratestoday.com/api/v1/central-bank/rbi/latest", headers=H, timeout=30).json()
    return t["rate_date"], {r["base"]: r["value"] for r in t["rates"] if r["quote"] == "INR"}

def sbi(side="buy"):                                  # TT buying (or 'sell') rate
    b = requests.get("https://allratestoday.com/api/v1/bank-rates/in/sbi", headers=H, timeout=30).json()
    return b["captured_at"][:10], {r["ccy"]: r[side] for r in b["rates"]}

rate_date, inr_per = sbi() if "--sbi" in sys.argv else rbi()

common = xmlrpc.client.ServerProxy(f"{ODOO}/xmlrpc/2/common")
uid = common.authenticate(DB, USER, PWD, {})
m = xmlrpc.client.ServerProxy(f"{ODOO}/xmlrpc/2/object")
call = lambda model, method, *a, **kw: m.execute_kw(DB, uid, PWD, model, method, list(a), kw)

company_id = call("res.users", "read", [uid], fields=["company_id"])[0]["company_id"][0]
for code in CURRENCIES:
    if code not in inr_per:
        continue
    cur = call("res.currency", "search", [("name", "=", code)])
    if not cur:
        continue
    vals = {"rate": 1 / inr_per[code]}                # Odoo: foreign units per 1 INR
    existing = call("res.currency.rate", "search",
                    [("currency_id", "=", cur[0]), ("name", "=", rate_date), ("company_id", "=", company_id)])
    if existing:
        call("res.currency.rate", "write", existing, vals)
    else:
        call("res.currency.rate", "create", [{**vals, "currency_id": cur[0],
                                              "name": rate_date, "company_id": company_id}])
    print(code, rate_date, inr_per[code])
Enter fullscreen mode Exit fullscreen mode

Three details that matter:

  • Date the rate with the publisher's date (rate_date), not the day the job ran. On a weekend or holiday the latest RBI table is the last business day's; writing it under today's date would make a Saturday invoice look like it used a Saturday rate.
  • Run it after publication. The RBI rate is out by about 1:30 pm IST, so schedule the job for mid-afternoon on business days. A run at 9 am loads yesterday's rate.
  • Inverse direction. Odoo's rate field is foreign currency per 1 company currency unit. Write 1 / 92.4895, not 92.4895, or every invoice will be off by a factor of about 8,500.

Q6. What about invoices dated in the past, or a backlog of missing days?

Odoo uses the latest rate on or before the invoice date, so gaps are tolerated, but a missing day means an invoice converts at an older rate. To backfill, call the dated endpoint (/api/v1/central-bank/rbi/2026-11-18) or the history endpoint (/api/v1/central-bank/rbi/history?from=...&to=...) and write one row per published date with the same loop. Past dates need a paid plan on our API; the RBI archive is free if you're willing to parse it.

Q7. Will Odoo calculate the exchange difference at receipt correctly?

Yes. If the invoice is in USD at the RBI rate and you register the payment in USD with the bank's actual rupee amount (or the rate on the receipt date), Odoo posts the realised exchange gain or loss to the account set under Accounting > Configuration > Settings > Default Accounts. For month-end unrealised differences on open invoices, Odoo Enterprise's unrealised currency gains/losses tooling (its name and location vary by version) uses the rate loaded for the closing date. That's another reason to load the rate every business day.


Summary

  • Odoo 16 has no RBI or SBI provider. The ECB's INR rate isn't the RBI rate.
  • For invoices and books, use the RBI/FBIL reference rate. Use SBI TT only where a rule names it (income tax), and CBIC for customs and GST on goods.
  • Either add a provider to currency_rate_live (the open-source addon targets 17 and should backport to 16), or run a 40-line XML-RPC job daily after 1:30 pm IST.
  • Always store the publisher's date and write the inverse rate.

Links

RBI/FBIL figures are official reference rates; SBI figures are the rates SBI shows on its own website. Odoo is a trademark of Odoo S.A.; this is an independent integration.

Top comments (0)