def view(request): data = {'title': 'Reports'} addUserData(request, data) if 'action' in request.GET: action = request.GET['action'] if action == 'data': try: m = request.GET['model'] if 'q' in request.GET: q = request.GET['q'].upper() if ':' in m: sp = m.split(':') model = eval(sp[0]) query = model.flexbox_query(q) for n in range(1, len(sp)): query = eval('query.filter(%s)' % (sp[n])) else: model = eval(request.GET['model']) query = model.flexbox_query(q) else: model = eval(request.GET['model']) query = model.flexbox_query('') data = { "results": [{ "id": x.id, "name": x.flexbox_repr(), "alias": x.flexbox_alias() } for x in query] } return HttpResponse(json.dumps(data), content_type='application/json') except Exception as ex: return bad_json(error=1) return HttpResponseRedirect('/reportes') else: return render_to_response("reportes/reportesbs.html", data)
def view(request): data = {'title': 'Purchase'} addUserData(request, data) if request.method == 'POST': action = request.POST['action'] if action == 'ingresoinv': try: with transaction.atomic(): datos = json.loads(request.POST['datos']) ingresoprod = IngresoProducto( proveedor_id=datos['proveedor'], numerodocumento=datos['numerodocumento'], descripcion=datos['descripcion']) ingresoprod.save() salva_auditoria(request, ingresoprod, ACCION_ADICIONAR) # Items items = datos['items'] for d in items: codigo = d['codigo'] if Producto.objects.filter(codigo=codigo).exists(): producto = Producto.objects.filter( codigo=codigo)[0] detalleingprod = DetalleIngresoProducto( purchase=ingresoprod, producto=producto, cantidad=Decimal(d['cantidad']), costo=Decimal(d['costo']), valor=Decimal(d['valor'])) detalleingprod.save() salva_auditoria(request, detalleingprod, ACCION_ADICIONAR) # Actualizar Inventario Real if InventarioReal.objects.filter( producto=producto).exists(): inventarioreal = InventarioReal.objects.filter( producto=producto)[0] inventarioreal.cantidad = inventarioreal.cantidad + detalleingprod.cantidad inventarioreal.valor = inventarioreal.valor + detalleingprod.valor inventarioreal.costo = inventarioreal.valor / inventarioreal.cantidad inventarioreal.save() else: inventarioreal = InventarioReal( producto=detalleingprod.producto, cantidad=detalleingprod.cantidad, costo=detalleingprod.costo, valor=detalleingprod.valor) inventarioreal.save() salva_auditoria(request, inventarioreal, ACCION_ADICIONAR) return ok_json({'numero_purchase': ingresoprod.repr_id()}) except Exception: return bad_json(error=1) elif action == 'chequeacodigos': codigos = request.POST['codigos'].split(",") if Producto.objects.filter(codigo__in=codigos).exists(): cod_existen = [ x.codigo for x in Producto.objects.filter(codigo__in=codigos) ] return ok_json({"codigosexisten": cod_existen}) else: return bad_json(error=1) elif action == 'comprobarnumero': proveedor = Proveedor.objects.get(pk=request.POST['pid']) numero = request.POST['numero'] if IngresoProducto.objects.filter(numerodocumento=numero, proveedor=proveedor).exists(): return bad_json(error=1) else: return ok_json() else: data['fechahoy'] = datetime.today() data['form'] = IngresoProductoForm( initial={'fechadocumento': data['fechahoy']}) data['form4'] = DetalleIngresoProductoForm() data['form_entidad'] = ProveedorForm(prefix='proveedor') return render_to_response("ingresoinv/ingresoinv.html", data)
def view(request): ex = None data = {'title': 'Cash Register Sessions'} addUserData(request, data) if request.method == 'POST': action = request.POST['action'] if action == 'abrirsesion': f = SesionCajaForm(request.POST) if f.is_valid(): try: with transaction.atomic(): sc = SesionCaja( fondo=f.cleaned_data['fondo'], fecha=datetime.now(), facturaempieza=f.cleaned_data['facturaempieza'], facturatermina=f.cleaned_data['facturaempieza'], abierta=True, cajero=f.cleaned_data['cajero']) sc.save() salva_auditoria(request, sc, ACCION_ADICIONAR) return ok_json() except Exception: return bad_json(error=1) else: return bad_json(error=1) elif action == 'cerrarsesion': sesion = SesionCaja.objects.get(pk=request.POST['id']) f = CierreSesionCajaForm(request.POST) if f.is_valid(): try: with transaction.atomic(): closed_session = CierreSesionCaja( sesion=sesion, bill100=f.cleaned_data['bill100'], bill50=f.cleaned_data['bill50'], bill20=f.cleaned_data['bill20'], bill10=f.cleaned_data['bill10'], bill5=f.cleaned_data['bill5'], bill2=f.cleaned_data['bill2'], bill1=f.cleaned_data['bill1'], total=0, enmonedas=f.cleaned_data['enmonedas'], deposito=f.cleaned_data['deposito']) closed_session.save() sesion.abierta = False sesion.save() salva_auditoria(request, closed_session, ACCION_MODIFICAR) return ok_json() except Exception: return bad_json(error=2) else: return bad_json(error=2) return bad_json(error=0) else: if 'action' in request.GET: action = request.GET['action'] if action == 'addsesion': try: data['title'] = 'Open Cash Register Session' data['form'] = SesionCajaForm() return render_to_response("caja/adicionarbs.html", data) except Exception: pass elif action == 'closesesion': try: data['title'] = 'Close Cash Register Session' data['sesioncaja'] = SesionCaja.objects.get( pk=request.GET['id']) data['form'] = CierreSesionCajaForm() return render_to_response("caja/cerrarsesionbs.html", data) except Exception: pass return HttpResponseRedirect( url_back(request, mensaje_excepcion(ex.args[0]))) sesiones = SesionCaja.objects.all() paging = MiPaginador(sesiones, 25) p = 1 try: if 'page' in request.GET: p = int(request.GET['page']) page = paging.page(p) except: page = paging.page(1) data['paging'] = paging data['rangospaging'] = paging.rangos_paginado(p) data['page'] = page data['sesiones'] = page.object_list data['exists_open_sessions'] = SesionCaja.objects.filter( abierta=True).exists() return render_to_response("caja/sesionesbs.html", data)
def view(request): ex = None data = {'title': 'Customers'} addUserData(request, data) if request.method == 'POST': action = request.POST['action'] if action == 'add': f = ClienteForm(request.POST) if f.is_valid(): try: with transaction.atomic(): ruc = f.cleaned_data['ruc'] if not Cliente.objects.filter(ruc=ruc).exists(): cliente = Cliente(ruc=f.cleaned_data['ruc'], nombre=f.cleaned_data['nombre'], direccion=f.cleaned_data['direccion'], email=f.cleaned_data['email'], telefono=f.cleaned_data['telefono']) cliente.save() salva_auditoria(request, cliente, ACCION_ADICIONAR) return ok_json() else: return bad_json(mensaje='Identification already exists') except Exception: return bad_json(error=1) else: return bad_json(error=1) elif action == 'edit': cliente = Cliente.objects.get(pk=request.POST['id']) f = ClienteForm(request.POST) if f.is_valid(): try: with transaction.atomic(): ruc = f.cleaned_data['ruc'] if not Cliente.objects.filter(ruc=ruc).exclude(id=cliente.id).exists(): cliente.ruc = f.cleaned_data['ruc'] cliente.nombre = f.cleaned_data['nombre'] cliente.direccion = f.cleaned_data['direccion'] cliente.email = f.cleaned_data['email'] cliente.telefono = f.cleaned_data['telefono'] cliente.save() salva_auditoria(request, cliente, ACCION_MODIFICAR) return ok_json() else: return bad_json(mensaje='Identification already exists') except Exception: return bad_json(error=2) else: return bad_json(error=2) elif action == 'delete': try: with transaction.atomic(): cliente = Cliente.objects.get(pk=request.POST['id']) salva_auditoria(request, cliente, ACCION_ELIMINAR) cliente.delete() return ok_json() except Exception: return bad_json(error=3) return bad_json(error=0) else: if 'action' in request.GET: action = request.GET['action'] if action == 'add': try: data['title'] = 'Add Customer' data['form'] = ClienteForm() return render_to_response("clientes/add.html", data) except Exception as ex: pass elif action == 'edit': try: data['title'] = 'Edit Customer' data['cliente'] = cliente = Cliente.objects.get(pk=request.GET['id']) initial = model_to_dict_safe(cliente) data['form'] = ClienteForm(initial=initial) return render_to_response("clientes/edit.html", data) except Exception as ex: pass elif action == 'delete': try: data['title'] = 'Delete Customer' data['cliente'] = Cliente.objects.get(pk=request.GET['id']) return render_to_response("clientes/delete.html", data) except Exception as ex: pass return HttpResponseRedirect(url_back(request, mensaje_excepcion(ex.args[0]))) else: search = None if 's' in request.GET: search = request.GET['s'] if search: clientes = Cliente.objects.filter(Q(nombre__icontains=search) | Q(identificacion__icontains=search)) else: clientes = Cliente.objects.all() paging = MiPaginador(clientes, 25) p = 1 try: if 'page' in request.GET: p = int(request.GET['page']) page = paging.page(p) except: page = paging.page(1) data['paging'] = paging data['rangospaging'] = paging.rangos_paginado(p) data['page'] = page data['search'] = search if search else "" data['clientes'] = page.object_list return render_to_response("clientes/clientes.html", data)
def view(request): ex = None data = {'title': 'Products'} addUserData(request, data) if request.method == 'POST': action = request.POST['action'] if action == 'add': f = ProductoForm(request.POST) if f.is_valid(): try: with transaction.atomic(): producto = Producto(codigo=f.cleaned_data['codigo'], codigobarra=f.cleaned_data['codigobarra'], descripcion=f.cleaned_data['descripcion'], unidadmedida=f.cleaned_data['unidadmedida'], tipoproducto=f.cleaned_data['tipoproducto'], alias=f.cleaned_data['alias'], pvp=f.cleaned_data['pvp']) producto.save() salva_auditoria(request, producto, ACCION_ADICIONAR) return ok_json() except Exception: return bad_json(error=1) else: return bad_json(error=1) elif action == 'edit': producto = Producto.objects.get(pk=request.POST['id']) f = ProductoForm(request.POST) if f.is_valid(): try: with transaction.atomic(): producto.codigo = f.cleaned_data['codigo'] producto.codigobarra = f.cleaned_data['codigobarra'] producto.descripcion = f.cleaned_data['descripcion'] producto.unidadmedida = f.cleaned_data['unidadmedida'] producto.tipoproducto = f.cleaned_data['tipoproducto'] producto.alias = f.cleaned_data['alias'] producto.pvp = f.cleaned_data['pvp'] producto.save() salva_auditoria(request, producto, ACCION_MODIFICAR) return ok_json() except Exception: return bad_json(error=2) else: return bad_json(error=1) elif action == 'delete': producto = Producto.objects.get(pk=request.POST['id']) try: with transaction.atomic(): salva_auditoria(request, producto, ACCION_ELIMINAR) producto.delete() return ok_json() except Exception: return bad_json(error=3) elif action == 'cargarfoto': producto = Producto.objects.get(pk=request.POST['id']) form = FotoProductoForm(request.POST, request.FILES) if form.is_valid(): try: with transaction.atomic(): foto = request.FILES['foto'] if foto: producto.foto = foto producto.save() return ok_json() except Exception: return bad_json(error=2) else: return bad_json(error=1) elif action == 'actualizacodigoprod': try: tipoprod = TipoProducto.objects.get(pk=request.POST['tipoid']) if tipoprod.producto_set.exists(): nuevocodigo = int(tipoprod.producto_set.latest('id').codigo) + 1 else: nuevocodigo = tipoprod.inicial + 1 return ok_json(data={"nuevocodigo": str(nuevocodigo)}) except Exception: return bad_json() elif action == 'favorito': try: producto = Producto.objects.get(pk=request.POST['idprod']) if producto.esfavorito: producto.esfavorito = False else: producto.esfavorito = True producto.save() return HttpResponse(json.dumps({"result": "ok"}), content_type="application/json") except Exception as ex: return HttpResponse(json.dumps({"result": "bad"}), content_type="application/json") elif action == 'existencia': try: producto = Producto.objects.get(pk=request.POST['idprod']) if producto.tieneinv: producto.tieneinv = False else: producto.tieneinv = True producto.save() return HttpResponse(json.dumps({"result": "ok"}), content_type="application/json") except Exception as ex: return HttpResponse(json.dumps({"result": "bad"}), content_type="application/json") return bad_json(error=0) else: if 'action' in request.GET: action = request.GET['action'] if action == 'add': try: data['title'] = 'Add Product' form = ProductoForm() form.for_addproducto() data['form'] = form return render_to_response('productos/add.html', data) except Exception as ex: pass elif action == 'edit': try: data['title'] = 'Edit Product' data['producto'] = producto = Producto.objects.get(pk=request.GET['id']) initial = model_to_dict(producto) form = ProductoForm(initial=initial) form.for_editproducto() data['form'] = form return render_to_response('productos/edit.html', data) except Exception as ex: pass elif action == 'delete': try: data['title'] = 'Delete Product' data['producto'] = producto = Producto.objects.get(pk=request.GET['id']) return render_to_response('productos/delete.html', data) except Exception as ex: pass elif action == 'cargarfoto': try: data['title'] = 'Upload Photo' data['producto'] = Producto.objects.get(pk=request.GET['id']) data['form'] = FotoProductoForm() return render_to_response('productos/cargarfoto.html', data) except Exception as ex: pass return HttpResponseRedirect(url_back(request, mensaje_excepcion(ex.args[0]))) else: search = None tipo = None if 't' in request.GET: tipo = request.GET['t'] if 's' in request.GET: search = request.GET['s'] if search: productos = Producto.objects.filter(Q(codigo__icontains=search) | Q(codigobarra__icontains=search) | Q(descripcion__icontains=search)) elif tipo: productos = Producto.objects.filter(tipoproducto__id=tipo) else: productos = Producto.objects.filter(activo=True) paging = MiPaginador(productos, 50) p = 1 try: if 'page' in request.GET: p = int(request.GET['page']) page = paging.page(p) except: page = paging.page(p) data['paging'] = paging data['rangospaging'] = paging.rangos_paginado(p) data['page'] = page data['search'] = search if search else "" data['productos'] = page.object_list data['tipos_productos'] = TipoProducto.objects.all() data['tipoid'] = int(tipo) if tipo else "" return render_to_response("productos/productos.html", data)
def view(request): ex = None data = {'title': 'Suppliers'} addUserData(request, data) if request.method == 'POST': action = request.POST['action'] if action == 'add': f = ProveedorForm(request.POST) if f.is_valid(): try: with transaction.atomic(): identificacion = f.cleaned_data['identificacion'] if not Proveedor.objects.filter(identificacion=identificacion).exists(): proveedor = Proveedor(identificacion=f.cleaned_data['identificacion'], nombre=f.cleaned_data['nombre'], alias=f.cleaned_data['alias'], direccion=f.cleaned_data['direccion'], telefono=f.cleaned_data['telefono'], celular=f.cleaned_data['celular'], email=f.cleaned_data['email']) proveedor.save() salva_auditoria(request, proveedor, ACCION_ADICIONAR) return ok_json() else: return bad_json(mensaje='Identification already exists') except Exception: return bad_json(error=1) elif action == 'edit': proveedor = Proveedor.objects.get(pk=request.POST['id']) f = ProveedorForm(request.POST) if f.is_valid(): try: with transaction.atomic(): identificacion = f.cleaned_data['identificacion'] if not Proveedor.objects.filter(identificacion=identificacion).exclude(id=proveedor.id).exists(): proveedor.identificacion = f.cleaned_data['identificacion'] proveedor.nombre = f.cleaned_data['nombre'] proveedor.alias = f.cleaned_data['alias'] proveedor.direccion = f.cleaned_data['direccion'] proveedor.telefono = f.cleaned_data['telefono'] proveedor.celular = f.cleaned_data['celular'] proveedor.email = f.cleaned_data['email'] proveedor.save() salva_auditoria(request, proveedor, ACCION_ADICIONAR) return ok_json() else: return bad_json(mensaje='Identification already exists') except Exception: return bad_json(error=2) elif action == 'delete': proveedor = Proveedor.objects.get(pk=request.POST['id']) try: with transaction.atomic(): proveedor.delete() return ok_json() except Exception: return bad_json(error=3) return bad_json(error=0) else: if 'action' in request.GET: action = request.GET['action'] if action == 'add': try: data['title'] = 'Add Supplier' data['form'] = ProveedorForm() return render_to_response("proveedores/add.html", data) except Exception as ex: pass elif action == 'edit': try: data['title'] = 'Edit Supplier' data['proveedor'] = proveedor = Proveedor.objects.get(pk=request.GET['id']) initial = model_to_dict_safe(proveedor) data['form'] = ProveedorForm(initial=initial) return render_to_response("proveedores/edit.html", data) except Exception as ex: pass elif action == 'delete': try: data['title'] = 'Delete Supplier' data['proveedor'] = Proveedor.objects.get(pk=request.GET['id']) return render_to_response("proveedores/delete.html", data) except Exception as ex: pass return HttpResponseRedirect(url_back(request, mensaje_excepcion(ex.args[0]))) else: search = None if 's' in request.GET: search = request.GET['s'] if search: proveedores = Proveedor.objects.filter(Q(nombre__icontains=search) | Q(identificacion__icontains=search) | Q(alias__icontains=search)) else: proveedores = Proveedor.objects.all() paging = MiPaginador(proveedores, 25) p = 1 try: if 'page' in request.GET: p = int(request.GET['page']) page = paging.page(p) except: page = paging.page(1) data['paging'] = paging data['rangospaging'] = paging.rangos_paginado(p) data['page'] = page data['search'] = search if search else "" data['proveedores'] = page.object_list return render_to_response("proveedores/proveedores.html", data)