ascetic_ddd.seedwork.domain.values.money.bank

Classes

Bank()

Handles currency conversion using exchange rates.

class ascetic_ddd.seedwork.domain.values.money.bank.Bank[source]

Bases: object

Handles currency conversion using exchange rates.

The Bank maintains a table of exchange rates and provides the reduce operation to convert expressions to a target currency.

add_rate(from_currency, to_currency, rate)[source]

Add an exchange rate.

Parameters:
from_currency

The source currency code

to_currency

The target currency code

rate

The exchange rate (how many from units equal one to unit)

Return type:

None

rate(from_currency, to_currency)[source]

Get the exchange rate between two currencies.

Parameters:
from_currency

The source currency code

to_currency

The target currency code

Return type:

int

Returns:

The exchange rate. Returns 1 if converting to the same currency.

reduce(source, to)[source]

Reduce an expression to a Money object in the target currency.

Parameters:
source

The expression to reduce

to

The target currency code

Return type:

Money

Returns:

Money object in the target currency