def ticket_get(id): itemlist = list() # get ORG and NIF from 'users' org = 'ORG' org = config.DB.select('users', where="username = $org limit 1", vars=locals()).list(); nif = 'NIF' nif = config.DB.select('users', where="username = $nif limit 1", vars=locals()).list(); # get books IDs ticket = config.DB.select('tickets', where="id=$id limit 1", vars=locals()) stritems = ticket[0]['libros'] splited = stritems.split(', ') # sort books IDs res = map(int, splited) for i in map(str, sorted(res)): itemlist.append(config.DB.select('books', where="id = $i limit 1", vars=locals()).list()) # get ticket ticket = config.DB.select('tickets', where="id=$id limit 1", vars=locals()) return render.printandarchive(ticket[0], itemlist, org[0], nif[0], enabled=False)
def printandarchive(session): # compute total del session.dbitems[:] total = 0 for item in session.items: for i in item: s = int(i['stock']) iid = int(i['id']) session.dbitems.append(i['id']) if session.mode: total = total - float(i['precio']) s = s + 1 else: total = total + float(i['precio']) s = s - 1 # update socio # update stock config.DB.update('books', where="id = $iid", stock=s, vars=locals()) # sort ticket db items as string res = str(sorted(session.dbitems)).strip('[]') # get student data student = config.DB.select('students', where="id = $session.studid limit 1", vars=locals()).list() sname = student[0]['nombre'] grade = student[0]['curso'] # archive config.DB.insert('tickets', dependiente=session.name, alumno=sname, curso=grade, libros=res, total=total, date=datetime.now().strftime("%d-%m-%Y %H:%M:%S")) # get ORG and NIF from 'users' org = 'ORG' org = config.DB.select('users', where="username = $org limit 1", vars=locals()).list() nif = 'NIF' nif = config.DB.select('users', where="username = $nif limit 1", vars=locals()).list() # print ticket = config.DB.select('tickets', order="id desc limit 1").list() return render.printandarchive(ticket[0], sorted(session.items, key=lambda k: k[0]['id']), org[0], nif[0], enabled=True)