Skip to content

Commit

Permalink
fix response
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardSchwarzkopf committed Apr 30, 2024
1 parent dce2532 commit f2c0608
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/services/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ async def update_transaction(
logger.warning(ACCOUNT_USER_ID_MISMATCH)
return None

# TODO: Use RoundedDecimal class here instead of round()
amount_updated = (
round(transaction_information.amount, 2) - transaction.information.amount
)
Expand Down
31 changes: 24 additions & 7 deletions app/utils/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from io import StringIO
from typing import List

from pydantic_core import core_schema

from app.utils.dataclasses_utils import ImportedTransaction


Expand All @@ -27,18 +29,17 @@ def __new__(cls, value: str | float | int | Decimal):
rounded_value = Decimal(value).quantize(Decimal("0.00"))
return Decimal.__new__(cls, rounded_value)

def __str__(self):
def __str__(self) -> str:
return str(self.quantize(Decimal("0.00")))

def __get_pydantic_core_schema__(self):
return {"type": "decimal"}

@classmethod
def __get_validators__(cls):
yield cls.validate
def __get_pydantic_core_schema__(cls, _source, _handler):
return core_schema.no_info_after_validator_function(
cls._validate, core_schema.decimal_schema()
)

@classmethod
def validate(cls, v: str | float | int | Decimal, _):
def _validate(cls, v: str | float | int | Decimal):
"""
Validates and rounds a value to two decimal places.
Expand Down Expand Up @@ -66,6 +67,22 @@ def validate(cls, v: str | float | int | Decimal, _):

return cls(rounded_value)

@classmethod
def _serialize(cls, value):
"""
Class method to serialize a value.
This class method serializes a given value.
Args:
value: The value to be serialized.
Returns:
The serialized value.
"""

return value


class TransactionCSV:
def __init__(self, transactions: List[ImportedTransaction]):
Expand Down

0 comments on commit f2c0608

Please sign in to comment.