def edit_tank(tank_id): # falta checagem de boia rcv = request.get_json() if 'capacity' in rcv: query = WaterTank.update(capacity=rcv['capacity']).where( WaterTank.id == tank_id) query.execute() if 'waterLevel' in rcv: query = WaterTank.update(waterLevel=rcv['waterLevel']).where( WaterTank.id == tank_id) query.execute() if 'temperature' in rcv: query = WaterTank.update(temperature=rcv['temperature']).where( WaterTank.id == tank_id) query.execute() if 'salinity' in rcv: query = WaterTank.update(salinity=rcv['salinity']).where( WaterTank.id == tank_id) query.execute() if 'turbidity' in rcv: query = WaterTank.update(turbidity=rcv['turbidity']).where( WaterTank.id == tank_id) query.execute() if 'buoy' in rcv: buoy = Buoy.select().where(Buoy.id == rcv['buoy']) if buoy.exists(): query = WaterTank.update(buoy=rcv['buoy']).where( WaterTank.id == tank_id) query.execute() else: if rcv['buoy'] == 0: query = WaterTank.update(buoy=None).where( WaterTank.id == tank_id) query.execute() if 'production' in rcv: production = Production.select().where( Production.id == rcv['production']) if production.exists(): if production[0].startDate == None: data_start = datetime.datetime.now().strftime("%Y-%m-%d") query = Production.update(startDate=data_start).where( Production.id == rcv['production']) query.execute() query = WaterTank.update(production=rcv['production']).where( WaterTank.id == tank_id) query.execute() else: if rcv['production'] == 0: query = WaterTank.update(production=None).where( WaterTank.id == tank_id) query.execute() if 'feedingschedule' in rcv: feedingschedule = FeedingSchedule.select().where( FeedingSchedule.id == rcv['feedingschedule']) if feedingschedule.exists(): query = WaterTank.update( feedingschedule=rcv['feedingschedule']).where( WaterTank.id == tank_id) query.execute() if 'qtyShrimps' in rcv: query = WaterTank.update(qtyShrimps=rcv['qtyShrimps']).where( WaterTank.id == tank_id) query.execute() tank_now = WaterTank.select().where(WaterTank.id == tank_id) prod_id = tank_now[0].production tanks = json.loads(get_tanks_associated_with_production(prod_id)) qty_total = 0 for tank in tanks: qty_tank = tank['qtyShrimps'] qty_total = qty_total + qty_tank query = Production.update(estimatedAmount=qty_total).where( Production.id == prod_id) query.execute() return Response('{}', status=200)
def get_all_productions(): productions = Production.select() resposta = [p.get_dict() for p in productions] return json.dumps(resposta)