feat: add max 2 decimal places validation to Money
This commit is contained in:
@@ -6,6 +6,12 @@ from decimal import Decimal
|
||||
class Money:
|
||||
amount: Decimal
|
||||
|
||||
def __post_init__(self):
|
||||
if self.amount.as_tuple().exponent < -2:
|
||||
raise ValueError(
|
||||
f"Money amount cannot have more than 2 decimal places: {self.amount}"
|
||||
)
|
||||
|
||||
def __add__(self, other):
|
||||
return Money(self.amount + other.amount)
|
||||
|
||||
|
||||
@@ -6,5 +6,6 @@ from domain.marketplace.money import Money
|
||||
@dataclass(frozen=True)
|
||||
class Price(Money):
|
||||
def __post_init__(self):
|
||||
super().__post_init__()
|
||||
if self.amount < 0:
|
||||
raise ValueError(f"Price cannot be negative: {self.amount}")
|
||||
|
||||
Reference in New Issue
Block a user