-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtienda.py
181 lines (128 loc) · 5.62 KB
/
tienda.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
from abc import ABC, abstractmethod
from producto import Producto
class Tienda(ABC):
def __init__(self, nombre:str, costo_delivery: int): #este es el constructor de la tienda. Los argumentos "vienen de la calle"
self.__nombre = nombre #esto viene de afuera (por argumento)
self.__costo_delivery = costo_delivery #esto viene de afuera (por argumento)
self.__productos = [] #esta variable es de uso interno de la tienda (no viene de afuera)
@abstractmethod
def ingresar_producto(self, nombre: str, precio:int, stock:int):
pass
@abstractmethod
def listar_producto(self):
pass
@abstractmethod
def realizar_venta(self, nombre :str, cantidad: int):
pass
@property
def nombre(self):
return self.__nombre
@property
def costo_delivery(self):
return self.__costo_delivery
@property
def productos(self):
return self.__productos
class TiendaRestaurante(Tienda):
tipo = "Restaurante"
def ingresar_producto(self, nombre: str, precio: int, stock: int = 0) -> None: #decia def ingresar_producto(self, nombre: str, precio: int, stock: int):
p = Producto(nombre, precio, 0) #elimine str e int. estaba como (nombre: str, precio: int, stock: int)
if p in self.productos:
pass
else:
self.productos.append(p)
def listar_producto(self):
lista = []
for producto in self.productos:
lista.append((producto.nombre, producto.precio))
return lista
def realizar_venta(self, nombre: str, cantidad: int):
pass
class TiendaSupermercado(Tienda):
tipo = "Supermercado"
def ingresar_producto(self, nombre: str, precio: int, stock: int) -> None:
p = Producto(nombre, precio, stock)
if p in self.productos:
indice = self.productos.index(p)
self.productos[indice] += p
else:
self.productos.append(p)
def listar_producto(self):
lista = []
for producto in self.productos:
mensaje = "Pocos productos disponibles"
if producto.stock < 10:
lista.append((producto.nombre, producto.precio, producto.stock, mensaje))
else:
lista.append((producto.nombre, producto.precio, producto.stock))
return lista
def realizar_venta(self, nombre: str, cantidad: int):
venta = Producto(nombre, 5000, cantidad )
if venta in self.productos:
indice = self.productos.index(venta)
if cantidad > self.productos[indice].stock:
self.productos[indice].stock = 0
else:
self.productos[indice] -= venta
else:
pass
class TiendaFarmacia(Tienda):
tipo = "Farmacia"
def ingresar_producto(self, nombre: str, precio: int, stock: int) -> None:
p = Producto(nombre, precio, stock)
if p in self.productos:
indice = self.productos.index(p)
self.productos[indice] += p
else:
self.productos.append(p)
#no se puede solicitar una cantidad superior a 3 por producto en cada venta
#“Envío gratis al solicitar este producto” junto al precio de los productos con un valor superior a $15.000.
def listar_producto(self):
lista = []
for producto in self.productos:
mensaje = "Envío gratis al solicitar este producto"
if producto.precio > 15000:
lista.append((producto.nombre, producto.precio, producto.stock, mensaje))
else:
lista.append((producto.nombre, producto.precio, producto.stock))
return lista
def realizar_venta(self, nombre: str, cantidad: int):
if cantidad <= 3:
venta = Producto(nombre, 5000, cantidad )
if venta in self.productos:
indice = self.productos.index(venta)
if cantidad > self.productos[indice].stock:
self.productos[indice].stock = 0
else:
self.productos[indice] -= venta
else:
pass
else:
pass
if __name__ == "__main__":
f01 = TiendaFarmacia('DrSami', 1000)
super01 = TiendaSupermercado('Santa Isabela', 2000)
restobar01 = TiendaRestaurante('Los Pollos Hermanos', 1500)
print(super01.listar_producto())
super01.ingresar_producto('Pavo 200 gr', 1500, 20)
print(super01.listar_producto())
super01.ingresar_producto('pavo 200 gr', 1500, 30)
print(super01.listar_producto())
super01.ingresar_producto('Leche 1lt', 900, 30)
print(super01.listar_producto())
print("***resumen de productos en super01:***")
for item in super01.listar_producto():
print(item)
print("----------------------")
f01.ingresar_producto('Aspirina', 1500, 20)
print(f01.listar_producto())
f01.ingresar_producto('Aspirina', 1500, 30)
print(f01.listar_producto())
f01.ingresar_producto('Nexium', 2000, 100)
print(f01.listar_producto())
f01.realizar_venta('Aspirina', 5)
print(f01.listar_producto(), "no realiza la venta porque el máximo permitido es 3")
f01.realizar_venta('Nexium', 2)
print(f01.listar_producto())
print(f"Venta exitosa. Gracias por comprar en {f01.nombre}")
####################################################################################