-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
269 lines (242 loc) · 10.1 KB
/
Copy pathmain.py
File metadata and controls
269 lines (242 loc) · 10.1 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import datetime
import os
import platform
from gestionVentas import(
VentaLocal,
VentaOnline,
GestionVentas,
)
def limpiar_pantalla():
''' Limpiar la pantalla según el sistema operativo'''
if platform.system() == 'Windows':
os.system('cls')
else:
os.system('clear') # Para Linux/Unix/MacOs
def mostrar_menu():
print("========== Menú de Gestión de Ventas ==========")
print('1. Agregar Venta Online')
print('2. Agregar Venta Local')
print("================== Consultas ==================")
print('3. Mostrar Todas las Ventas')
print('4. Mostrar Ventas OnLine')
print('5. Mostrar Ventas Locales')
print("========== Actualizar por ID de venta ==========")
print('6. Monto Total')
print('7. Cliente')
print('8. Productos')
print('9. Dirección del envio')
print('10. Vendedor')
print('======================================================')
print('11. Eliminarar Venta por ID')
print('======================================================')
print('12. Salir')
print('======================================================')
def ingresar_cliente():
while True:
try:
cliente = input('Ingrese el cliente: ')
if cliente:
return cliente
print("Error, debe ingresar el cliente... ")
except Exception as error:
print(f'Error inesperado: {error}')
def ingresar_monto_total():
while True:
try:
monto_total = round(
float(input('Ingrese el monto total de la venta: ')), 2)
if monto_total > 0:
return monto_total
else:
print('El monto total debe ser mayor a cero.')
except ValueError:
print('Error, debe ingresar un número valido.')
def ingresar_productos():
while True:
try:
productos = input(
'Ingrese los productos (separados por coma): ').split(',')
productos = [prod.strip()for prod in productos if prod.strip()]
if productos:
return productos
else:
print('Error, Debe ingresar al menos un producto válido.')
except ValueError:
print('Error, ha ocurrido un error al procesar los datos ingresados.-')
def ingresar_direccion_envio():
while True:
try:
direccion_envio = input('Ingrese la dirección del envio: ')
if direccion_envio:
return direccion_envio
else:
print('Error, debe ingresar alguna dirección.')
except ValueError:
print(
'Error, ha ocurrido un error al procesar los datos ingresados.-')
def ingresar_vendedor():
while True:
try:
vendedor = input('Ingrese el vendedor: ')
if vendedor:
return vendedor
else:
print('Error, debe ingresar el vendedor.')
except ValueError:
print(
'Error, ha ocurrido un error al procesar los datos ingresados.-')
def ingresar_buscar_id():
while True:
try:
id = int(input('Ingrese la ID de la venta que quiere buscar: '))
if id > 0:
return str(id)
else:
print('Error, la ID debe ser un numero entero positivo.')
print("Error, debe ingresar la ID... ")
except ValueError:
print('Error: debe ingresar un número entero.')
def ingresar_crear_id():
while True:
try:
id = int(input('Ingrese la ID de la venta que quiere agregar: '))
if id < 0:
print('Error, la ID debe ser un numero entero positivo.')
elif (gestion.leer_venta(str(id))):
print('Error, la ID ya existe, debe ingresar otro valor.')
else:
return str(id)
except ValueError:
print('Error: debe ingresar un número entero.')
def agregar_venta(gestion, tipo_venta):
try:
id_venta = ingresar_crear_id()
fecha = datetime.datetime.now().strftime("%d-%m-%y")
cliente=ingresar_cliente()
monto_total= ingresar_monto_total()
productos= ingresar_productos()
if tipo_venta == '1':
direccion_envio= ingresar_direccion_envio()
venta = VentaOnline(id_venta,fecha,cliente,productos,monto_total, direccion_envio)
elif tipo_venta == '2':
vendedor= ingresar_vendedor()
venta= VentaLocal(id_venta,fecha,cliente,productos, monto_total, vendedor)
else:
print('Opción inválida')
return
gestion.crear_venta(venta)
input('Presione enter para continuar...')
except ValueError as e:
print(f'Ingrese una opcion valida: {e}')
except Exception as e:
print(f'Error inesperado: {e}')
def buscar_venta_por_id(gestion):
id_venta = ingresar_id()
gestion.leer_venta(id_venta)
input('Presione enter para continuar...')
def actualizar_monto_total_venta(gestion):
id_venta = ingresar_buscar_id()
if gestion.leer_venta(id_venta):
venta = gestion.leer_venta(id_venta)
print(f"El monto de la venta que quiere actualizar es: {venta.monto_total}")
nuevo_monto_total = ingresar_monto_total()
gestion.actualizar_monto_total(id_venta, nuevo_monto_total)
input('Presione enter para continuar...')
def actualizar_cliente(gestion):
id_venta = ingresar_buscar_id()
if gestion.leer_venta(id_venta):
venta = gestion.leer_venta(id_venta)
print(f"El cliente que quiere actualizar es: {venta.cliente}")
nuevo_cliente =ingresar_cliente()
gestion.actualizar_cliente(id_venta, nuevo_cliente)
input('Presione enter para continuar...')
def actualizar_productos(gestion):
id_venta = ingresar_buscar_id()
if gestion.leer_venta(id_venta):
venta = gestion.leer_venta(id_venta)
print(f"Los productos que quiere actualizar son: {venta.productos}")
nuevos_productos = ingresar_productos()
gestion.actualizar_productos(id_venta, nuevos_productos)
input('Presione enter para continuar...')
def actualizar_direccion_envio(gestion):
id_venta = ingresar_buscar_id()
if gestion.leer_venta(id_venta):
venta = gestion.leer_venta(id_venta)
if isinstance(venta, VentaOnline):
print(f"La direccion que quiere actualizar es: {venta.direccion_envio}")
nueva_direccion = ingresar_direccion_envio()
gestion.actualizar_direccion_envio(id_venta, nueva_direccion)
else:
print('No existe una venta OnLIne Con esa ID.')
input('Presione enter para continuar...')
def actualizar_vendedor(gestion):
id_venta = ingresar_buscar_id()
if gestion.leer_venta(id_venta):
venta= gestion.leer_venta(id_venta)
if isinstance(venta,VentaLocal):
print(f"El vendedor que quiere actualizar es: {venta.vendedor}")
nuevo_vendedor = ingresar_vendedor()
gestion.actualizar_vendedor(id_venta, nuevo_vendedor)
else:
print('No existe una venta Local con esa ID')
input('Presione enter para continuar...')
def eliminar_venta_por_id(gestion):
id_venta = ingresar_buscar_id()
gestion.eliminar_venta(id_venta)
input('Presione enter para continuar...')
def mostrar_todas_las_ventas(gestion):
print('=============== Listado completo de las Ventas ==============')
for venta in gestion.leer_datos().values():
if 'direccion_envio' in venta:
print(f"id: {venta['id_venta']} - CLiente {venta['cliente']} - Monto: ${(venta['monto_total']):.2f} - VENTA ONLINE - Dirección envío: {venta['direccion_envio']}")
else:
print(
f"id: {venta['id_venta']} - CLiente {venta['cliente']} - Monto: ${(venta['monto_total']):.2f} - VENTA LOCAL - Vendedor: {venta['vendedor']}")
print('=====================================================================')
input('Presione enter para continuar...')
def mostrar_todas_las_ventas_online(gestion):
print('=============== Listado completo de las Ventas Online ==============')
for venta in gestion.leer_datos().values():
if 'direccion_envio' in venta:
print(f"id: {venta['id_venta']} - CLiente {venta['cliente']} - Monto: ${(venta['monto_total']):.2f} - Dirección envío: {venta['direccion_envio']}")
print('=====================================================================')
input('Presione enter para continuar...')
def mostrar_todas_las_ventas_local(gestion):
print('=============== Listado completo de las Ventas Local ==============')
for venta in gestion.leer_datos().values():
if 'vendedor' in venta:
print(f"id: {venta['id_venta']} - CLiente {venta['cliente']} - Monto: ${(venta['monto_total']):.2f} - Vendedor: {venta['vendedor']}")
print('=====================================================================')
input('Presione enter para continuar...')
if __name__ == '__main__':
archivo_ventas='ventas_db.json'
gestion = GestionVentas(archivo_ventas)
while True:
limpiar_pantalla()
mostrar_menu()
opcion = input('Seleccione una opción: ')
if opcion == '1' or opcion == '2':
agregar_venta(gestion, opcion)
elif opcion == '3':
mostrar_todas_las_ventas(gestion)
elif opcion == '4':
mostrar_todas_las_ventas_online(gestion)
elif opcion == '5':
mostrar_todas_las_ventas_local(gestion)
elif opcion == '6':
actualizar_monto_total_venta(gestion)
elif opcion == '7':
actualizar_cliente(gestion)
elif opcion == '8':
actualizar_productos(gestion)
elif opcion == '9':
actualizar_direccion_envio(gestion)
elif opcion == '10':
actualizar_vendedor(gestion)
elif opcion == '11':
eliminar_venta_por_id(gestion)
elif opcion == '12':
print('Saliendo del programa...')
break
else:
print('Opción no válida. Por favor, seleccione una opción válida (1-6)')