Skip to content

Exchange Rate Design

Jonathan Niles edited this page Aug 13, 2018 · 3 revisions

This document describes the way bhima computes exchange rates.

Defining an Exchange Rates

New exchange rates are defined in the #/exchange module. They are stored in the exchange_rate table as a unique tuple of date, currency_id, enterprise_id, and value.

Computing an Exchange Rate for a Date

In general, exchange rates are only set when the rate changes. Exchange rates are computed by finding the last valid rate for a date. If the rate is not defined on a given date, the most recent record prior to that date is used.

Example

Date (dd/mm/yyyy) Rate (FC)
01/01/2016 930
05/01/2016 945
12/01/2016 965
17/01/2016 950
28/01/2016 1000

Using the above table, bhima's algorithm will compute:

  1. The rate on Jan 1st was 930FC.
  2. The rate on Jan 6th was 945FC.
  3. The rate on Jan 11th was 945FC.
  4. The rate on Jan 12th was 965FC.
  5. The rate on Jan 17th was 950FC.
  6. The rate on March 12th was 1000FC.