-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassArticle.py
More file actions
64 lines (51 loc) · 2.16 KB
/
Copy pathclassArticle.py
File metadata and controls
64 lines (51 loc) · 2.16 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Article:
# Definition des attributs de la classe Article
__reference: str
__nom: str
__prix_hors_taxes: float
__quantite_en_stock: int
# Constructeur
def __init__(self, reference, nom, prix_hors_taxes, quantite_en_stock):
self.__reference = reference
self.__nom = nom
self.__prix_hors_taxes = float(prix_hors_taxes)
self.__quantite_en_stock = quantite_en_stock
def afficher_info_article(self):
print(f"Reference : {self.__reference}\nNom : {self.__nom}\nPrix HT : {self.__prix_hors_taxes:.2f}$\nEn stock : {self.__quantite_en_stock}")
def get_nom(self):
return self.__nom
def get_prix_hors_taxes(self):
return self.__prix_hors_taxes
def get_quantite_en_stock(self):
return self.__quantite_en_stock
def set_prix_hors_taxes(self, prix_hors_taxes):
if prix_hors_taxes < 0:
print("❌ Prix invalide")
else:
self.__prix_hors_taxes = prix_hors_taxes
def set_quantite_en_stock(self, quantite_en_stock):
if quantite_en_stock < 0:
print("❌ Quantite invalide")
else:
self.__quantite_en_stock = quantite_en_stock
def approvisionner(self, nb_articles: int):
self.__quantite_en_stock += nb_articles
print(f"✅ {nb_articles} article(s) ajouté(s). Stock: {self.__quantite_en_stock}")
def vendre(self, nb_articles: int):
if nb_articles > self.__quantite_en_stock:
print("❌ Vente non réussie : stock insuffisant.")
else:
self.__quantite_en_stock -= nb_articles
prix_ttc = self.calculer_prix_total(nb_articles)
print(f"✅ Vente réussie\nQuantité restante : {self.__quantite_en_stock}\nMontant total TTC : {prix_ttc:.2f}$")
def calculer_prix_total(self, nb_articles: int):
# Calcul avec TVA/GST (5% au Canada)
prix_ht = self.__prix_hors_taxes * nb_articles
prix_ttc = prix_ht * 1.15
return prix_ttc
# -----------------Programme principale------------------
art1 = Article(125, "Lait", 5.85, 55)
art1.approvisionner(100)
art1.vendre(1000)
art1.vendre(15)
art1.afficher_info_article()