Exemplo n.º 1
0
def getimagen(path):
    from aplicacion.modelos.ProductoImagen import ProductoImagen
    from aplicacion.config import app_config

    ruta = ProductoImagen.get_data(path)
    path = ruta[0]['imagen']
    # print("------------------")
    # print(app.config['ROOT_PATH']+ '/backend-py/aplicacion/clients/01/'+path)
    # print("------------------")
    return send_file(app.config['ROOT_PATH'] +
                     '/backend-py/aplicacion/clients/01/' + path)
Exemplo n.º 2
0
    def get(self):
        try:
            parser = reqparse.RequestParser()
            parser.add_argument(
                'id',
                type=str,
                required=True,
                help="Debe indicar id producto",
            )
            data = parser.parse_args()

            Prod = Producto.get_data(data['id'])
            if Prod:
                iva = Iva.get_data(Prod[0]["id_iva"])
                imagen = ProductoImagen.get_data_id(Prod[0]['id'])
                cliente = Cliente.get_data(Prod[0]['id_cliente'])

                Prod[0]["fix_iva"] = Prod[0]["precio"] - round(
                    Prod[0]["precio"] / iva[0]["valor"], 0)
                Prod[0]["cantidad"] = 1
                Prod[0]["fix_iva"] = int(Prod[0]["fix_iva"])
                Prod[0]["fix_precio_bruto"] = int(Prod[0]["precio"] -
                                                  Prod[0]["fix_iva"])
                Prod[0]['iva'] = int(iva[0]['valor'])
                Prod[0]["cantidad"] = 1
                Prod[0]["datos_cliente"] = cliente,
                Prod[0]["cliente_full_data"] = Persona.get_data(
                    cliente[0]["id_persona"]),
                Prod[0]["datos_tipo_producto"] = TipoProducto.get_data(
                    Prod[0]['id_tipo_producto']),
                Prod[0][
                    "ingredientes"] = ProductoIngrediente.IngredienteByProducto(
                        Prod[0]['id']),
                Prod[0]['imagen'] = imagen[0]['id']
                return Prod

            return None
        except Exception as e:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            msj = 'Error: ' + str(
                exc_obj) + ' File: ' + fname + ' linea: ' + str(
                    exc_tb.tb_lineno)
            return {"message": msj}, 500
Exemplo n.º 3
0
    def get(self):
        menu = []
        try:
            datos = Producto.getAll()
            return 'he'
            if datos:
                for row in datos:
                    imagen = ProductoImagen.get_data_id(row.id)

                    iva = Iva.get_data(row.id_iva)
                    fix_iva = row.precio - round(row.precio / iva[0]["valor"],
                                                 0)
                    fix_precio_bruto = row.precio - fix_iva

                    data = {
                        "id": row.id,
                        "nombre": row.nombre,
                        "id_cliente": row.id_cliente,
                        "id_tipo_producto": row.id_tipo_producto,
                        "precio": row.precio,
                        "cantidad": 1,
                        "created_at": str(row.created_at),
                        "updated_at": str(row.updated_at),
                        "descripcion": row.descripcion,
                        "imagen": imagen[0]['id'],
                        "iva": int(iva[0]['valor']),
                        "fix_iva": int(fix_iva),
                        "fix_precio_bruto": fix_precio_bruto
                    }

                    menu.append(data)

            return {"response": {"data": {"info": menu}}}, 200

        except Exception as e:
            print(" ## Error ## \n")
            print(e)
            print("\n")
            return {"message": "Ha ocurrido un error de conexión."}, 500
Exemplo n.º 4
0
 def post(self):
     try:
         # parser = reqparse.RequestParser()
         # parser.add_argument('idPrestador',
         #                     type=str,
         #                     required=True,
         #                     help="Debe indicar id prestador",
                             
         #                     )
         # parser.add_argument('idSucursal',
         #                     type=str,
         #                     required=False,
         #                     help="Debe indicar id Sucursal",
                             
         #                     )   
         # data = parser.parse_args()
         dataJson = request.get_json()
         insert = ProductoImagen.insert(dataJson)
         return insert
     except Exception as e:
         print(" ## Error ## \n")
         print(e)
         print("\n")
         return {"message": "Ha ocurrido un error de conexión."}, 500
Exemplo n.º 5
0
    def get(self):
        menu = []
        try:
            datos = ProductoImagen.getAll()
            if datos:
                for row in datos:
                    data = {
                        "id": row.id,
                        "imagen": row.imagen,
                        "id_producto": row.id_producto,
                        "created_at": str(row.created_at),
                        "updated_at": str(row.updated_at),
                    }
                    
                    menu.append(data)
                        
            return {  "response":{"data": { "info": menu }}}, 200
            

        except Exception as e:
            print(" ## Error ## \n")
            print(e)
            print("\n")
            return {"message": "Ha ocurrido un error de conexión."}, 500
Exemplo n.º 6
0
    def post(self):
        try:
            ruta = "/app/backend-py/aplicacion/clients/01/"
            # ruta = app.config['ROOT_PATH']+ '/backend-py/aplicacion/clients/01/'

            imagen = "noimage.png"
            if request.files["imagen"]:
                imagen = request.files["imagen"]
                filename = imagen.filename
                imagen.save(os.path.join(ruta, filename))
                params = request.form.to_dict()
                dataJson = params
                dataJson["imagen"] = imagen.filename
                dataJson["estado"] = 1
            insert = Producto.insert(dataJson)
            if insert:
                if 'imagen' in dataJson and dataJson["imagen"]:
                    imagen = dataJson["imagen"]

                jsonImagen = {"imagen": imagen, "id_producto": insert}
                Ima = ProductoImagen.insert(jsonImagen)
                response = {
                    "producto": insert,
                    "imagen": Ima,
                    "estado": 1,
                    "msj": "Registro exitoso"
                }
                return response
            return {"estado": 0, "msj": "ha ocurrido un error"}
        except Exception as e:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            msj = 'Error: ' + str(
                exc_obj) + ' File: ' + fname + ' linea: ' + str(
                    exc_tb.tb_lineno)
            return {"message": msj}, 500
Exemplo n.º 7
0
    def get(self):
        try:
            parser = reqparse.RequestParser()
            parser.add_argument(
                'id_cliente',
                type=str,
                required=False,
                help="Debe indicar id producto",
            )

            parser.add_argument(
                'id_tipo_producto',
                type=str,
                required=False,
                help="Debe indicar id producto",
            )
            parser.add_argument(
                'nombre',
                type=str,
                required=False,
                help="Debe indicar id producto",
            )

            data = parser.parse_args()
            iva = Iva.get_data(1)
            menu = []
            if 'id_cliente' in data and data['id_cliente'] is not None:
                datos = Producto.get_data_cliente(data['id_cliente'])
            elif 'id_tipo_producto' in data and data[
                    'id_tipo_producto'] is not None:
                datos = Producto.get_data_producto(data['id_tipo_producto'])
            elif 'nombre' in data and data['nombre'] is not None:
                datos = Producto.get_data_producto_name(data['nombre'])
            else:
                datos = Producto.getAll()

            if datos:
                for row in datos:
                    img = None
                    imagen = ProductoImagen.get_data_id(row.id)
                    if imagen:
                        img = imagen[0]['id']
                    iva = Iva.get_data(row.id_iva)
                    fix_iva = row.precio - round(row.precio / iva[0]["valor"],
                                                 2)
                    fix_precio_bruto = row.precio - fix_iva
                    data = {
                        "id":
                        row.id,
                        "sku":
                        row.sku,
                        "nombre":
                        row.nombre,
                        "id_cliente":
                        row.id_cliente,
                        "id_tipo_producto":
                        row.id_tipo_producto,
                        "precio":
                        row.precio,
                        "cantidad":
                        1,
                        "created_at":
                        str(row.created_at),
                        "updated_at":
                        str(row.updated_at),
                        "descripcion":
                        row.descripcion,
                        "imagen":
                        img,
                        "iva":
                        str(iva[0]['valor']),
                        "fix_iva":
                        str(fix_iva),
                        "fix_precio_bruto":
                        str(fix_precio_bruto),
                        "ingredientes":
                        ProductoIngrediente.IngredienteByProducto(row.id),
                    }

                    menu.append(data)

            return {"response": {"data": {"info": menu}}}, 200

        except Exception as e:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            msj = 'Error: ' + str(
                exc_obj) + ' File: ' + fname + ' linea: ' + str(
                    exc_tb.tb_lineno)
            return {"message": msj}, 500