def insertar_arancel(request): """ Recibe un monto y una lista de id's de alumnos para asignarle un arancel """ if request.GET and request.GET['monto'] and request.GET['ids'] and request.GET['concepto']: try: ids = request.GET['ids'].split(",") monto = request.GET['monto'] concepto = request.GET['concepto'] alumnos = Alumno.objects.filter(pk__in=ids) for alumno in alumnos: cuota = Cuota(alumno=alumno, importe=monto, deuda=monto, fecha=datetime.today(), paga=False, concepto=concepto) cuota.save() data = json.dumps({'resultado':True}, cls=DjangoJSONEncoder) return HttpResponse(data, mimetype='application/json') except: data = json.dumps({'resultado':False}, cls=DjangoJSONEncoder) return HttpResponse(data, mimetype='application/json')
def generate_payments(): ''' se podria pasar como parametro un "payment date" para generar cuotas de meses determinados. devuelve true si ya se habian generado y false sino. ''' amount = 0 #Analiza si debe crear las cuotas del mes actual. today = date.today() today_tuple = (today.year, today.month) # hacer un get y no un filter(ahorro de queries) c = Cuota.objects.filter(fecha__month=today.month, fecha__year=today.year) if not c and today.month not in SIN_CUOTA: students = Alumno.objects.all() for student in students: services = ServicioSuscripto.objects.filter(alumno=student) for service in services: amount += service.importe c = Cuota(alumno=student, importe=amount, deuda=amount, fecha=today) c.save() amount = 0 return False return True