-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomer.py
53 lines (41 loc) · 1.64 KB
/
customer.py
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
from user import User
from order import Order
class Customer(User):
counter = 0
all_customers=[]
def __init__(self,customer):
super().__init__(customer,'')
self.customer=customer
self.personal_orders=[]
Customer.counter += 1
self.id = Customer.counter
def add_order(self,item,quantity):
if item.stock >= quantity:
order = Order(self,item,quantity)
item.update_stock(quantity)
Order.all_orders.append(order)
self.personal_orders.append(order)
else:
print("there is no enough stock for this item")
def view_orders(self):
return self.personal_orders
def delete_order(self, order_id):
order_to_delete = None
for order in self.personal_orders:
if id(order) == order_id: # Using id() to identify the specific order
order_to_delete = order
break
if order_to_delete:
order_to_delete.item.restock(order_to_delete.quantity)
self.personal_orders.remove(order_to_delete)
Order.all_orders.remove(order_to_delete)
print(f"Order {order_id} has been deleted.")
else:
print("Order not found.")
def customer_total_pay(self):
customer_total_pay=0
for order in self.personal_orders:
customer_total_pay += order.order_cost()
return customer_total_pay
def __str__(self):
return f"{self.customer}, id:{self.id}"