예제 #1
0
def create_supplier():
    Session = sessionmaker(bind=db.engine)
    session = Session()
    data = json.loads(request.form['sendData'])

    try:
        cache.delete('all_suppliers')

        session.execute(
            "INSERT INTO supplier VALUES (default ,:name, :email, :phone, 1)",
            {
                'name': data['name'],
                'email': data['email'],
                'phone': data['phone']
            })
        session.commit()
    except:
        session.rollback()
        session.close()
        return json.dumps({'success': False}), 500, {
            'ContentType': 'application/json'
        }

    session.close()
    return json.dumps({'success': True}), 200, {
        'ContentType': 'application/json'
    }
예제 #2
0
def delete_part():
    """main drop page"""
    Session = sessionmaker(bind=db.engine)
    session = Session()
    data = json.loads(request.form['sendData'])
    id = data['id']
    key = "parts_installed_"

    try:
        res = session.execute(
            "select distinct allparts.installed_in from allparts where allparts.id=:id",
            {'id': id})
        res = res.fetchall()

        for row in res:
            key = key + str(row[0])

        cache.delete('in_service')
        cache.delete(key)

        # reduce quantity, delete if now zero
        session.query(AllParts).filter(AllParts.id == id).update(
            {'quantity': AllParts.quantity - int(data['quantity'])})
        part = session.query(AllParts).filter(AllParts.id == id).first()

        if int(part.quantity) == 0:
            session.query(AllParts).filter(AllParts.id == id).update({
                'active':
                0,
                'delete':
                time.strftime('%Y-%m-%d %H:%M:%S')
            })

        res = session.execute(
            "select allparts.create, allparts.part from allparts where allparts.id=:id",
            {'id': id})

        for i in range(int(data['quantity'])):
            for row in res:
                session.execute(
                    "insert into failed values (default, :create, :part, NOW())",
                    {
                        'part': str(row[0]),
                        'create': str(row[1])
                    })

        session.commit()
    except:
        session.rollback()
        session.close()
        return json.dumps({'success': False}), 500, {
            'ContentType': 'application/json'
        }

    session.close()
    return json.dumps({'success': True}), 200, {
        'ContentType': 'application/json'
    }
예제 #3
0
def create_part():
    """ {name: $('#equipmentName').val(), year: $('#partSelect').val(), supplier: $('#partSelect2').val(),
          harvest: $('#partRadio1').is(":checked"), spraying:$('#partRadio2').is(":checked"),
              seeding: $('#partRadio3').is(":checked"), winter: $('#partRadio4').is(":checked")}"""
    Session = sessionmaker(bind=db.engine)
    session = Session()
    data = json.loads(request.form['sendData'])

    try:
        cache.delete('all_active_parts')

        session.execute(
            'Insert into mlmodels values(default, :name, 0, 0, 0, 0, 0)',
            {'name': data['name']})

        res = session.execute('select max(id) from mlmodels')
        maxKey = 0

        for row in res:
            maxKey = row[0]

        session.execute(
            "INSERT INTO parts VALUES (default ,:name, :supplier, :quantity, :location, 1, :harvest, :spraying, :seeding, :winter, :model)",
            {
                'name': data['name'],
                'supplier': data['supplier'],
                'quantity': data['quantity'],
                'location': data['location'],
                'harvest': 1 if data['harvest'] else 0,
                'spraying': 1 if data['spraying'] else 0,
                'seeding': 1 if data['seeding'] else 0,
                'winter': 1 if data['winter'] else 0,
                'model': maxKey
            })
        session.commit()
    except:
        session.rollback()
        session.close()
        return json.dumps({'success': False}), 500, {
            'ContentType': 'application/json'
        }

    session.close()
    return json.dumps({'success': True}), 200, {
        'ContentType': 'application/json'
    }
예제 #4
0
def supplier_set():
    Session = sessionmaker(bind=db.engine)
    session = Session()
    data = json.loads(request.form['sendData'])
    key = "part_" + str(data['id']) + "_"

    try:
        cache.delete('all_active_parts')
        cache.delete(key)
        session.query(Parts).filter(Parts.id == data['id']).update({'quantity': data['quantity'], 'name': data['name']})
        session.commit()
    except:
        session.rollback()
        session.close()
        return json.dumps({'success': False}), 500, {'ContentType': 'application/json'}

    session.close()
    return json.dumps({'success': True}), 200, {'ContentType': 'application/json'}
예제 #5
0
def supplier_delete():
    """main drop page"""
    Session = sessionmaker(bind=db.engine)
    session = Session()
    data = json.loads(request.form['sendData'])
    id = data['id']
    key = "supplier_" + str(id)

    try:
        cache.delete(key)
        cache.delete('all_suppliers')
        cache.delete('all_active_parts')
        session.query(Supplier).filter(Supplier.id == id).update({'active': 0})
        session.commit()
    except:
        session.rollback()
        session.close()
        return json.dumps({'success': False}), 500, {
            'ContentType': 'application/json'
        }

    session.close()
    return json.dumps({'success': True}), 200, {
        'ContentType': 'application/json'
    }
예제 #6
0
def update_parts():
    Session = sessionmaker(bind=db.engine)
    session = Session()
    data = json.loads(request.form['sendData'])
    id = data['id']
    key = "part_" + str(id) + "_"

    try:
        cache.delete('all_active_parts')
        cache.delete(key)
        cache.delete('in_service')
        cache.delete("parts_installed_"+str(data['machine']))


        session.execute("INSERT INTO allparts VALUES (default ,:part, :machine, 0, :quant, 1, NOW(), null)",{'part': data['id'], 'machine': data['machine'], 'quant': data['quantity']})
        session.execute("UPDATE parts SET parts.quantity = parts.quantity - :quant where parts.id = :id",{'quant': data['quantity'], 'id': id})
        session.commit()
    except:
        session.rollback()
        session.close()
        return json.dumps({'success': False}), 500, {'ContentType': 'application/json'}

    session.close()
    return json.dumps({'success': True}), 200, {'ContentType': 'application/json'}