示例#1
0
def remove_one_from_cart(customer_id, product_id):
    if in_cart(customer_id, product_id):
        cart_item = CartItem.query.filter(customer_id == customer_id,
                                          product_id == product_id).first()
        existing_qty = cart_item.qty
        if existing_qty == 1:
            db_session.delete(cart_item)
            db_session.commit()
        else:
            cart_item.qty = cart_item.qty - 1
            db_session.commit()
示例#2
0
def add_one_to_cart(customer_id, product_id):
    if in_cart(customer_id, product_id):
        cart_item = CartItem.query.filter(product_id == product_id,
                                          customer_id == customer_id).first()
        cart_item.qty = cart_item.qty + 1
        db_session.commit()
    else:
        cart_item = CartItem(product_id=product_id,
                             customer_id=customer_id,
                             qty=1)
        db_session.add(cart_item)
        db_session.commit()
示例#3
0
def post_tap_transaction(rfid_tag):
    tap = Tap(rfid_tag=rfid_tag)
    db_session.add(tap)
    db_session.commit()
示例#4
0
def remove_one_from_inventory(product_id):
    product = Product.query.filter(id=product_id).first()
    product.stock_qty = product.stock_qty - 1
    db_session.commit()
示例#5
0
def add_one_to_inventory(product_id):
    product = Product.query.filter(id=product_id).first()
    product.stock_qty = product.stock_qty + 1
    db_session.commit()
示例#6
0
def invalidate_all_customer_tokens():
    db_session.query(Customer).update({Customer.token: None})
    db_session.commit()
示例#7
0
def invalidate_customer_token(username):
    db_session.query(Customer).filter(Customer.username == username).update(
        {Customer.token: None})
    db_session.commit()
示例#8
0
def generate_customer_token(username):
    token = uuid.uuid4().hex
    db_session.query(Customer).filter(Customer.username == username).update(
        {Customer.token: token})
    db_session.commit()
    return token
示例#9
0
def create_customer(username, password, rfid_tag):
    c = Customer(username=username, password=password, rfid_tag=rfid_tag)
    db_session.add(c)
    db_session.commit()