From 8656ec69485b5fe91645db5845e1b66ce93971cf Mon Sep 17 00:00:00 2001 From: Mateo Morinigo <84980263+matemorinigo@users.noreply.github.com> Date: Sun, 19 Dec 2021 20:44:31 -0300 Subject: [PATCH 1/3] =?UTF-8?q?A=C3=B1adido=20testing.py=20y=20.gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Archivos locales con los que estuve trabajando --- .gitignore | 2 ++ testing.py | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 .gitignore create mode 100644 testing.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6bf5235 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +archivos +**/*.xlsx diff --git a/testing.py b/testing.py new file mode 100644 index 0000000..fbfc2b0 --- /dev/null +++ b/testing.py @@ -0,0 +1,82 @@ +from openpyxl import workbook +from openpyxl import load_workbook +from openpyxl import cell + +global run +run = True + +while run == True: + ruta1 = str(input("Ubicacion del libro : ")) + archivo = load_workbook(ruta1) #Abre el archivo Excel del libro a utilizar + hoja = archivo.active + mes = int(input('Mes a cargar (insertar nº del 1-12): ')) + año = str(input('Año del libro (ejemplo: 2020): ')) + + global totalmes + if mes == 1: + totalmes = f"TOTALES AL 31/01/{año}" + elif mes == 2: + totalmes = f"TOTALES AL 28/02/{año}" + elif mes == 3: + totalmes = f"TOTALES AL 31/03/{año}" + elif mes == 4: + totalmes = f"TOTALES AL 30/04/{año}" + elif mes == 5: + totalmes = f"TOTALES AL 31/05/{año}" + elif mes == 6: + totalmes = f"TOTALES AL 30/06/{año}" + elif mes == 7: + totalmes = f"TOTALES AL 31/07{año}" + elif mes == 8: + totalmes = f"TOTALES AL 31/08/{año}" + elif mes == 9: + totalmes = f"TOTALES AL 30/09/{año}" + elif mes == 10: + totalmes = f"TOTALES AL 31/10/{año}" + elif mes == 11: + totalmes = f"TOTALES AL 30/11/{año}" + elif mes == 12: + totalmes = f"TOTALES AL 31/12/{año}" + else: + print("Error en el mes (linea 12-37)") + + + for celda in hoja['A']: #Recorre la columna A en busca de la fila donde estan los valores + if celda.value == totalmes: + fila = celda.row + netogravado = hoja[f"E{fila}"].value + iva = hoja[f"F{fila}"].value + importetotal = hoja[f"G{fila}"].value + else: + if celda.value == f"TOTALES AL 29/02/{año}": + fila = celda.row + netogravado = hoja[f"E{fila}"].value + iva = hoja[f"F{fila}"].value + importetotal = hoja[f"G{fila}"].value + + + ruta2 = input("Ubicacion del archivo DDJJ Ganancias: ") + archivo2 = load_workbook(ruta2) + + libro = int(input('Libro (ventas=1, compras=2): ')) + + if libro == 1: + hoja2 = archivo2['VENTAS'] + if mes == 1: + hoja2.cell(row=8, column=5).value = netogravado + archivo2.save(ruta2) + elif libro == 2: + hoja2 = archivo2['COMPRAS'] + + global notError + notError = False + while notError == False: + sigLibro = int(input('¿Desea ingresar otro libro?(Si=1, No=2): ')) + if sigLibro == 1: + run = True + notError = True + elif sigLibro == 2: + run = False + notError = True + else: + notError = False From 1efaf5683e57289ec5f8a432e9e5f7f51eb4ad1b Mon Sep 17 00:00:00 2001 From: Mateo Morinigo Date: Sun, 19 Dec 2021 21:35:49 -0300 Subject: [PATCH 2/3] V1.1 con notas --- testing.py | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/testing.py b/testing.py index fbfc2b0..c1e3d9c 100644 --- a/testing.py +++ b/testing.py @@ -3,7 +3,7 @@ from openpyxl import cell global run -run = True +run = True #Crea una variable para que el script siga corriendo siempre que el usuario quiera while run == True: ruta1 = str(input("Ubicacion del libro : ")) @@ -12,7 +12,7 @@ mes = int(input('Mes a cargar (insertar nº del 1-12): ')) año = str(input('Año del libro (ejemplo: 2020): ')) - global totalmes + global totalmes #Crea la variable donde se alojaran los totales de los meses, para asi encontrar mas facilmente los datos necesarios if mes == 1: totalmes = f"TOTALES AL 31/01/{año}" elif mes == 2: @@ -41,14 +41,14 @@ print("Error en el mes (linea 12-37)") - for celda in hoja['A']: #Recorre la columna A en busca de la fila donde estan los valores - if celda.value == totalmes: + for celda in hoja['A']: #Recorre la columna A en busca de la fila donde estan los valores, gracias a la variable totalmes + if celda.value == totalmes: fila = celda.row - netogravado = hoja[f"E{fila}"].value + netogravado = hoja[f"E{fila}"].value #Busca los valores del neto gravado, el IVA, y el total en base a la fila donde encontro a la variable totalmes iva = hoja[f"F{fila}"].value importetotal = hoja[f"G{fila}"].value else: - if celda.value == f"TOTALES AL 29/02/{año}": + if celda.value == f"TOTALES AL 29/02/{año}": #Evita que el script se rompa, en el caso de que un libro sea de un año bisiesto fila = celda.row netogravado = hoja[f"E{fila}"].value iva = hoja[f"F{fila}"].value @@ -56,27 +56,29 @@ ruta2 = input("Ubicacion del archivo DDJJ Ganancias: ") - archivo2 = load_workbook(ruta2) + archivo2 = load_workbook(ruta2) #Busca y abre el archivo donde se alojaran los datos del libro + global notError1 + notError1 = False #Evita errores en el caso de que el usuario inserte mal el numero + while notError1 == False: + libro = int(input('Libro (ventas=1, compras=2): ')) #El usuario decide si va a cargar un libro de Ventas o de compras) + if libro == 1: + hoja2 = archivo2['VENTAS'] + if mes == 1: + hoja2.cell(row=8, column=5).value = netogravado + archivo2.save(ruta2) + notError1 = True + elif libro == 2: + hoja2 = archivo2['COMPRAS'] - libro = int(input('Libro (ventas=1, compras=2): ')) - - if libro == 1: - hoja2 = archivo2['VENTAS'] - if mes == 1: - hoja2.cell(row=8, column=5).value = netogravado - archivo2.save(ruta2) - elif libro == 2: - hoja2 = archivo2['COMPRAS'] - - global notError - notError = False - while notError == False: + global notError2 + notError2 = False + while notError2 == False: sigLibro = int(input('¿Desea ingresar otro libro?(Si=1, No=2): ')) if sigLibro == 1: run = True - notError = True + notError2 = True elif sigLibro == 2: run = False - notError = True + notError2 = True else: - notError = False + notError2 = False From c9528e42c1f63b90c810699c314fb7ae4a72765e Mon Sep 17 00:00:00 2001 From: Mateo Morinigo Date: Mon, 20 Dec 2021 11:41:38 -0300 Subject: [PATCH 3/3] Agrega algoritmo para buscar donde cambiar los datos --- testing.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/testing.py b/testing.py index c1e3d9c..5c11d8b 100644 --- a/testing.py +++ b/testing.py @@ -11,31 +11,44 @@ hoja = archivo.active mes = int(input('Mes a cargar (insertar nº del 1-12): ')) año = str(input('Año del libro (ejemplo: 2020): ')) - + + global nombremes global totalmes #Crea la variable donde se alojaran los totales de los meses, para asi encontrar mas facilmente los datos necesarios if mes == 1: + nombremes = "ENERO" totalmes = f"TOTALES AL 31/01/{año}" elif mes == 2: + nombremes = "FEBRERO" totalmes = f"TOTALES AL 28/02/{año}" elif mes == 3: + nombremes = "MARZO" totalmes = f"TOTALES AL 31/03/{año}" elif mes == 4: + nombremes = "ABRIL" totalmes = f"TOTALES AL 30/04/{año}" elif mes == 5: + nombremes = "MAYO" totalmes = f"TOTALES AL 31/05/{año}" elif mes == 6: + nombremes = "JUNIO" totalmes = f"TOTALES AL 30/06/{año}" elif mes == 7: + nombremes = "JULIO" totalmes = f"TOTALES AL 31/07{año}" elif mes == 8: + nombremes = "AGOSTO" totalmes = f"TOTALES AL 31/08/{año}" elif mes == 9: + nombremes = "SEPTIEMBRE" totalmes = f"TOTALES AL 30/09/{año}" elif mes == 10: + nombremes = "OCTUBRE" totalmes = f"TOTALES AL 31/10/{año}" elif mes == 11: + nombremes = "NOVIEMBRE" totalmes = f"TOTALES AL 30/11/{año}" elif mes == 12: + nombremes = "DICIEMBRE" totalmes = f"TOTALES AL 31/12/{año}" else: print("Error en el mes (linea 12-37)") @@ -57,14 +70,28 @@ ruta2 = input("Ubicacion del archivo DDJJ Ganancias: ") archivo2 = load_workbook(ruta2) #Busca y abre el archivo donde se alojaran los datos del libro + global notError1 notError1 = False #Evita errores en el caso de que el usuario inserte mal el numero + while notError1 == False: libro = int(input('Libro (ventas=1, compras=2): ')) #El usuario decide si va a cargar un libro de Ventas o de compras) if libro == 1: hoja2 = archivo2['VENTAS'] if mes == 1: - hoja2.cell(row=8, column=5).value = netogravado + for celda in hoja2['A']: + if celda.value == nombremes: + global columna + fila = celda.row + for celda2 in hoja2['E']: + if celda2.value == "gravado": + columna = celda2.column + else: + for celda3 in hoja2['C']: + if celda3.value == "$": + columna = celda3.column + hoja2.cell(row= fila, column= columna) + archivo2.save(ruta2) notError1 = True elif libro == 2: @@ -72,6 +99,7 @@ global notError2 notError2 = False + while notError2 == False: sigLibro = int(input('¿Desea ingresar otro libro?(Si=1, No=2): ')) if sigLibro == 1: