示例#1
0
def edit_production(production_id):
    try:
        rcv = request.get_json()
        if 'name' in rcv:
            query = Production.update(name=rcv['name']).where(
                Production.id == production_id)
            query.execute()
        if 'client':
            query = Production.update(client=rcv['client']).where(
                Production.id == production_id)
            query.execute()
        if 'shrimpClass' in rcv:
            query = Production.update(shrimpClass=rcv['shrimpClass']).where(
                Production.id == production_id)
            query.execute()
        if 'requestedAmount' in rcv:
            query = Production.update(
                requestedAmount=rcv['requestedAmount']).where(
                    Production.id == production_id)
            query.execute()
        if 'estimatedAmount' in rcv:
            query = Production.update(
                estimatedAmount=rcv['estimatedAmount']).where(
                    Production.id == production_id)
            query.execute()
        if 'endDate' in rcv:
            newEndDate = datetime.strptime(rcv['endDate'], '%Y-%m-%d')
            query = Production.update(endDate=newEndDate).where(
                Production.id == production_id)
            query.execute()
        return Response('{}', status=200)
    except:
        return Response('{}', status=503)
示例#2
0
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)