1

While the code runs without issues, I cannot locate the "perro.docx" document (the one with the replaceable variables). It's not in the same folder as my Python file and document template. Additionally, I sometimes encounter an error that states the document template cannot be found, even though it's in the same folder. As a beginner, I'm having difficulty finding a solution to this problem. I would greatly appreciate any assistance you can provide. Thank you.

from docxtpl import DocxTemplate


def Datos_Entrada(mensaje): 
    while True:  
        try: 
            Entrada = int(input(mensaje))
            if Entrada >= 0 :
                return Entrada
            else: 
                print("Valor no Valido")

        except ValueError: 
            print("Valor equivocado")

#Datos Obtenidos por el Usuario 
def Operaciones(): 

    Unidades_Servicios_hechos = Datos_Entrada("Unidades Vendidas/Servicios hechos:  ")
    Ingresos_Entrada = Datos_Entrada("Ingresos:  ")
    Cuentas_PorCobrar = Datos_Entrada("Cuentas Por Cobrar:  ")
    GastosOperativos_Entrada = Datos_Entrada("Gastos Operativos:  ")
    GastosAdminVentas_Entrada = Datos_Entrada("Gastos Admin/Ventas:  ")
    
    #Datos_Obtenidos = [Unidades_Servicios_hechos, Ingresos_Entrada, Cuentas_PorCobrar, GastosOperativos_Entrada, GastosAdminVentas_Entrada]
    #Operacioens sobre los Ingresos 
    
    IngresosPorProducto_Salida = Ingresos_Entrada / Unidades_Servicios_hechos

    #Operaciones sobre los Gastos 
    GastosTotales_Salida = GastosOperativos_Entrada + GastosAdminVentas_Entrada
    GastosPorProducto_Salida = GastosTotales_Salida / Unidades_Servicios_hechos
    

    #Operaciones para sacar datos de las utilidades
    UtilidadesOperativas_Salida = Ingresos_Entrada - GastosOperativos_Entrada
    UtilidadesTotales_Salida = Ingresos_Entrada - GastosTotales_Salida 
    MargenGanancia_Salida = UtilidadesTotales_Salida / Ingresos_Entrada * 100
    UtilidadesPorProducto_Salida = UtilidadesTotales_Salida / Unidades_Servicios_hechos

    return Unidades_Servicios_hechos, Ingresos_Entrada, Cuentas_PorCobrar, GastosOperativos_Entrada, GastosAdminVentas_Entrada, IngresosPorProducto_Salida, GastosPorProducto_Salida, GastosTotales_Salida, UtilidadesOperativas_Salida, UtilidadesTotales_Salida, MargenGanancia_Salida, UtilidadesPorProducto_Salida
Operaciones()
    

#Imprimir los datos Obtenidos 
def Documento():
    Documento_Input = DocxTemplate("C:/Users/980014096/OneDrive/Escritorio/Python/PROYECTOS/Análisis_Periodo/Documento.docx")

    Unidades_Servicios_hechos, Ingresos_Entrada, Cuentas_PorCobrar, GastosOperativos_Entrada, GastosAdminVentas_Entrada, IngresosPorProducto_Salida, GastosPorProducto_Salida, GastosTotales_Salida, UtilidadesOperativas_Salida, UtilidadesTotales_Salida, MargenGanancia_Salida, UtilidadesPorProducto_Salida = Operaciones()

    context = {
        'A': Unidades_Servicios_hechos,
        'B' : Ingresos_Entrada,
        'C' : Cuentas_PorCobrar,
        'D' : GastosOperativos_Entrada,
        'E' : GastosAdminVentas_Entrada,
        'F' : GastosTotales_Salida,
        'G' : IngresosPorProducto_Salida,
        'H' : GastosPorProducto_Salida,
        'I' : UtilidadesOperativas_Salida,
        'J' : UtilidadesTotales_Salida,
        'K' : MargenGanancia_Salida,
        'M' : UtilidadesPorProducto_Salida,
    }    

    Documento_Input.render(context)
    Documento_Input.save("Perro.docx")
    print("El archivo se ha guardado correctamente")
    

print("Lo lograste")

I've attempted to move the files to different folders, rename them, and use the exact path, but I'm still encountering issues. When I try to access the documents, I receive an error message stating that the newly saved document cannot be found. This is my first time using this particular library,

3
  • The only function that is called is Operaciones(). The document save, Documento_Input.save("Perro.docx") is in the function Documento() which is never called. Commented Apr 28, 2023 at 13:11
  • Yes, i decide to remake my code, i also make a basic GUI, if could give me your opinion on my new code, i´ll be very pleased, thanks for your time. forum.freecodecamp.org/t/… Commented May 7, 2023 at 20:41
  • Can you add the error message that you mentioned to your question? Also, the code for rendering the document is in Operaciones but it's never called. Commented Aug 30, 2023 at 7:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.