Fix: At times the report would fail with numbers not in multiples of .01

This commit is contained in:
Amritanshu Agrawal 2022-07-24 06:44:11 +05:30
parent c03210d965
commit 49b1ac61cf
2 changed files with 8 additions and 8 deletions

View File

@ -112,7 +112,7 @@ def build_report(
schemas.CashFlowItem(
name=account_type.name,
url=["/", "cash-flow", str(account_type.id)],
amount=amount * -1,
amount=round(amount * -1, 2),
)
)
@ -144,14 +144,14 @@ def build_report(
schemas.CashFlowItem(
name="Net increase in cash and cash equivalents",
url=[],
amount=total_amount,
amount=round(total_amount, 2),
),
schemas.CashFlowItem(
name="Cash and cash equivalents at beginning of period",
url=[],
amount=opening,
amount=round(opening, 2),
),
schemas.CashFlowItem(name="Cash and cash equivalents at end of period", url=[], amount=closing),
schemas.CashFlowItem(name="Cash and cash equivalents at end of period", url=[], amount=round(closing, 2)),
],
)
@ -188,8 +188,8 @@ def build_report_id(
schemas.CashFlowItem(
name=account.name,
url=["/", "ledger", str(account.id)],
amount=amount * -1,
amount=round(amount * -1, 2),
)
)
return cf, [schemas.CashFlowItem(name="total", url=[], amount=total_amount)]
return cf, [schemas.CashFlowItem(name="total", url=[], amount=round(total_amount, 2))]

View File

@ -2,7 +2,7 @@ from datetime import date, datetime
from decimal import Decimal
from typing import List, Optional, Union
from pydantic import Field, validator
from pydantic import validator
from pydantic.main import BaseModel
from . import to_camel
@ -11,7 +11,7 @@ from . import to_camel
class CashFlowItem(BaseModel):
name: str
url: Optional[List[str]]
amount: Decimal = Field(multiple_of=0.01)
amount: Decimal
class Config:
anystr_strip_whitespace = True