macxred / cashctrl_ledger

Implementation of the abstract pyledger.LegderEngine interface with CashCtrl accounting service.
MIT License
0 stars 0 forks source link

Round amount to Currency's Precision #35

Closed lasuk closed 2 months ago

lasuk commented 5 months ago

Background

CashCtrl stores a transactions' currencyRate instead of the base_currency_amount, while pyledger and most large accounting systems choose the more flexible approach and store a transactions' base_currency_amount.

When mapping to/from CashCtrl, we compute base_currency_amount = amount * currencyRate. We currently round this amount to eight digits after the comma. The eight digits are arbitrarily chosen and hard coded.

Task

  1. Implement CashCtrlLedger.precision(currency: str) -> float to fetch the smallest increment for amounts in the specified currency from CashCtrl.
  2. Overload LedgerEngine.round_to_precision with a vectorized version.
    # existing
    LedgerEngine.round_to_precision(amount: float, currency: str) -> float
    # new
    LedgerEngine.round_to_precision(amount: pd.series, currency: pd.series) -> pd.series
  3. Use LedgerEngine.round_to_precision instead of round(..., 8) to round the base_currency_amount. See TODOs in cashctrl_ledger.
AlexTheWizardL commented 3 months ago

Possible understanding

CashCtrlLedger.precision(currency: str) -> float.

Following question

AlexTheWizardL commented 3 months ago

Correct understanding

precision(currency: str) -> float and precision is the smallest increment for amounts in a specified currency is the "smallest unit of currency" or "currency subunit." Example:

USD -> smallest is CENT -> 0.01
Mauritania -> Khoums -> 0.00005
Madagascar -> Iraimbilanja -> 0.00005