-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbody.py
More file actions
91 lines (72 loc) · 2.88 KB
/
Copy pathbody.py
File metadata and controls
91 lines (72 loc) · 2.88 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from datetime import date
#from storage import save_products_to_file, if_products_are_the_same, save_customers_to_file
products = []
orders = []
class Customer:
_id_counter = 1
def __init__(self, first_name, last_name, password):
self.first_name = first_name
self.last_name = last_name
self.password = password
self.id = Customer._id_counter
Customer._id_counter += 1
def __str__(self):
return f"{self.id}: {self.first_name} {self.last_name}"
class Product:
def __init__(self, name, brand, amount, price):
self.name = name
self.brand = brand
self.amount = amount
self.price = price
def __str__(self):
return f"{self.name} ({self.brand}) — {self.amount} in stock @ {self.price:.2f}"
# Funkcja, która wyświetla ekran dla customera.
def display_for_customer(self, idx=None):
if idx is not None:
print(f"{idx}. {self.name} by {self.brand} — {self.price:.2f}$")
else:
print(f"{self.name} by {self.brand} — {self.price:.2f}$")
class Order:
id_counter = 1
def __init__(self, customer):
self.id_n = Order.id_counter
self.customer = customer
self.date = date.today()
self.total_orders = 0
self.orders = []
def add_order(self, product, amount):
self.orders.append({product.name: amount})
self.total_orders += product.price * amount
def showing_order(self):
print(self.id_n, self.date, self.customer.name, self.total_orders, self.orders)
def total_price(self):
pass
class Admin:
def __init__(self, username):
self.username = username
def add_product(self):
from storage import if_products_are_the_same
name = input("Product name: ")
from storage import save_products_to_file
save_products_to_file(products)
try:
price = float(input("Product price: "))
amount = int(input("Amount of the product: "))
brand = str(input("Product brand: "))
product = Product(name, brand, amount, price)
products.append(product)
print(f"Product {name} {brand} added successfully. Amount: {amount}")
save_products_to_file(products)
merged = if_products_are_the_same()
print(f"Finalized {len(merged)} unique product in the file.")
except ValueError:
print("Invalid price. Try again")
def show_products(self):
# This functions shows all available products in the e-shop
print("__________PRODUCTS__________")
if not products:
print("No products in inventory")
else:
for idx, p in enumerate(products, start=1):
print(f"{idx}. {p.name} ({p.brand}: {p.amount}) in stock. Price: {p.price:.2f}$")
print(f"Total price: {(p.price * p.amount)}$")