-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpricing.py
More file actions
33 lines (25 loc) · 927 Bytes
/
pricing.py
File metadata and controls
33 lines (25 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# built-in librairies
from dataclasses import dataclass
from typing import ClassVar
# additional librairies
from currency_converter import CurrencyConverter
@dataclass
class Offer:
TVA: ClassVar[float] = 1.2
price_usd_ht: float
quantity: int
def __repr__(self) -> str:
# renvoie une string qui vérifie : self = eval(repr(self))
return f"Price(price_usd_ht={self.price_usd_ht}, " \
f"quantity={self.quantity})"
def __str__(self) -> str:
# prend le rôle de ton "to_string" et permet de faire les conversions
# plus pythoniquement
return f"{self.quantity:>3} pcs for " \
f"{self.price_eur_ttc:8.2f}€ TTC"
@property
def price_eur_ht(self) -> float:
return CurrencyConverter().convert(self.price_usd_ht, 'USD', 'EUR')
@property
def price_eur_ttc(self) -> float:
return self.price_eur_ht * self.TVA