def put(self, user, path_id): path_obj = (Path.select().where(Path.user == user, Path.id == path_id).get()) path_obj.last_ship_date = date.today() move = Move( value=path_obj.total, type=0, obs=f"GERADO DA VENDA DA ROTA {path_obj.id}", user=user, ) path_obj.save() move.save() result = {"msg": "sucesso"} return json_response(result, 200)
def get(self, user): routes = Path.select().where(Path.user == user) def parse(item): next_ship_date = item.last_ship_date + timedelta( days=item.step_days) now_date = date.today() result = next_ship_date - now_date days = result.days status = "atrasado" if days <= 0: status = "atrasado" if days > item.warning_sub_day: status = "no prazo" else: status = "atenção" return { "path_id": item.id, "client_id": item.client.id, "until_days": days, "status": status, } result = list(map(parse, routes)) atrasado = list(filter(lambda x: x["status"] == "atrasado", result)) atencao = list(filter(lambda x: x["status"] == "atenção", result)) no_prazo = list(filter(lambda x: x["status"] == "no_prazo", result)) header = { "qtd_atrasado": len(atrasado), "qtd_atencao": len(atencao), "qtd_no_prazo": len(no_prazo), "results": result, } return json_response(header, 200)