def inventory_item(order_event):
    inventory = Inventory(
        order_id=order_event['order_id'],
        order_items=order_event['items']
    )
    inventory = create_transaction(inventory, "RESERVED")
    return inventory
Esempio n. 2
0
def add_inventory():
    """ Adds purchased ingredients to inventory."""

    inventory = request.form.get("data")
    inventory_dict = json.loads(inventory)
    shopping_list_id = int(request.form.get("listId"))

    # Add each ingredient to inventory list
    for ingredient_id in inventory_dict:
        check_inventory = Inventory.query.filter(
            Inventory.user_id == session['user_id'],
            Inventory.ingredient_id == ingredient_id).first()
        if not check_inventory:
            new_inventory = Inventory(
                user_id=session['user_id'],
                ingredient_id=int(ingredient_id),
                current_quantity=round(
                    float(inventory_dict[ingredient_id]['ingredientQty']), 2),
            )
            db.session.add(new_inventory)
        else:
            check_inventory.current_quantity += round(
                float(inventory_dict[ingredient_id]['ingredientQty']), 2)

    # Change status of shopping list since list has been used by user
    shopping_list = ShoppingList.query.filter(
        ShoppingList.list_id == shopping_list_id).one()
    shopping_list.has_shopped = True

    db.session.commit()

    return jsonify({'success': True})
Esempio n. 3
0
def load_inventories():
    # from mixer.backend.flask import mixer
    # mixer.init_app(app)
    """
    Load small sample of inventories into database.

    >>> import random
    >>> random.choice
    <bound method Random.choice of <random.Random object at 0x1236350>>

    """

    print "Inventories are filling up. Waiting in 1PP lines really pays off."

    for i in range(0, 20):
        #create 20 random inventory items
        beer_code_list = [
            "4Vmwih", "oQR5YM", "Qg6dpg", "9wNKio", "0DVz81", "YP4dCI",
            "Eyr9Kg", "jT5vQ0", "4Vmwih", "kQ42vv"
        ]
        user_id = random.randint(1, 100)
        beer_code = random.choice(beer_code_list)

        # inventories = mixer.cycle(100).blend(Inventory, user=user, beer=beer)
        inventories = Inventory(beer_code=beer_code, user_id=user_id)
        # inventories = mixer.blend(Inventory, user=user, beer=beer)

        db.session.add(inventories)
        db.session.commit()
def release_item(inventory):
    logger.info('release_item: {}'.format(vars(inventory)))

    inventory = Inventory(order_id=inventory.order_id,
                          order_items=inventory.order_items)
    inventory = create_transaction(inventory, 'RELEASED')
    return inventory
Esempio n. 5
0
def create_inventory(image_id, quantity, price):
    """create an inventory record"""

    image_inventory = Inventory(image_id=image_id,
                                quantity=quantity,
                                price=price)
    db.session.add(image_inventory)
    db.session.commit()

    return image_inventory
Esempio n. 6
0
def update_inventory(ingredient, bought, use_this_week, in_stock, quantity):
    """update inventory when ingredient bought or used"""

    inventory = Inventory(ingredient_r=ingredient,
                          bought=bought,
                          use_this_week=use_this_week,
                          in_stock=in_stock,
                          quantity=quantity)

    db.session.add(inventory)
    db.session.commit()

    return inventory
def load_inventory():
    """method to open the inventory ods spreadsheet and create inventory
    objects from each row
    """
    path = "inventory.ods"

    # # load a sheet based on its index (1 based)
    # sheet_idx = 1
    # df = read_ods(path, sheet_idx)

    # # load a sheet based on its name
    # sheet_name = "Sheet1"
    # df = read_ods(path, sheet_name)

    # # load a file that does not contain a header row
    # # if no columns are provided, they will be numbered
    # df = read_ods(path, 1, headers=False)

    # load a file and provide custom column names
    # if headers is True (the default), the header row will be overwritten
    df = read_ods(path,
                  1,
                  columns=[
                      "user_id", "inv_id", "inv_name", "inv_type",
                      "description", "manufacturer", "price",
                      "count_per_package", "size", "picture_path", "keywords"
                  ])

    #print(len(df))
    i = 1
    while i < len(df):

        #pdb.set_trace()
        inventory_item = Inventory(
            inv_id=df.loc[i].inv_id,
            user_id=int(df.loc[i].user_id),
            inv_name=df.loc[i].inv_name,
            inv_type=df.loc[i].inv_type,
            description=df.loc[i].description,
            price=df.loc[i].price,
            count_per_package=df.loc[i].count_per_package,
            manufacturer=df.loc[i].manufacturer,
            size=df.loc[i].size,
            picture_path=df.loc[i].picture_path,
            keywords=df.loc[i].keywords)
        i += 1
        print(inventory_item)
        # Add the User object to the session so it will be stored.
        db.session.add(inventory_item)

    db.session.commit()
Esempio n. 8
0
def inventorydelivery():
    req = request.data.decode("utf-8").replace("'", '"')
    data = json.loads(req)
    user_id = data['user_id']
    adj_amount = data['adj_amount']
    product_id = data['product_id']
    create_by = data['create_by']
    order_source = data['order_source']
    shipping_first_name = data['shipping_first_name']
    shipping_last_name = data['shipping_last_name']
    shipping_company = data['shipping_company']
    shipping_address_1 = data['shipping_address_1']
    shipping_city = data['shipping_city']
    shipping_state = data['shipping_state']
    shipping_postcode = data['shipping_postcode']
    shipping_country = data['shipping_country']
    shipping_phone = data['shipping_phone']
    remark = data['remark']
    # 判斷配送的數量是否超過現有庫存
    Inventory_now = getEndInvertory(user_id, product_id)
    if Inventory_now < adj_amount * -1:
        return jsonify({'message': 'Quantities is not enough'})
    # 產生配送單
    delivery = Delivery(user_id, create_by, order_source, shipping_first_name,
                        shipping_last_name, shipping_company,
                        shipping_address_1, shipping_city, shipping_state,
                        shipping_postcode, shipping_country, shipping_phone)
    db.session.add(delivery)
    db.session.commit()
    # 獲取最新的庫存
    beging_inventory, ending_inventory = getInvertoryNow(
        user_id, product_id, adj_amount)
    inventory = Inventory(user_id, beging_inventory, ending_inventory,
                          adj_amount, 0, product_id, create_by, order_source,
                          shipping_first_name, shipping_last_name,
                          shipping_company, shipping_address_1, shipping_city,
                          shipping_postcode, shipping_country, shipping_phone,
                          remark, delivery.id)
    db.session.add(inventory)
    db.session.commit()
    token = 'M5g5yVHMV2gc6iRvs1xu5Bsb9OEj0Wux8pQcKknldMo'
    msg = '用戶已指派寄送,請登入平台,輸入物流單號 https://storeapi.pyrarc.com/backend/inventorylist?mid=' + str(
        inventory.id)
    lineNotifyMessage(token, msg)
    return jsonify({
        'success': True,
        'msg': 'inventory is added now ',
        'data': data
    })
Esempio n. 9
0
def create_inventory(user_id, title):
    """Create and return a new inventory."""

    user = User.query.get(user_id)
    inventory = Inventory(user_id=user_id,
                          title=title,
                          date_added=datetime.datetime.now(),
                          last_updated_on=datetime.datetime.now())

    user.inventories.append(inventory)

    db.session.add(inventory)
    db.session.commit()

    return inventory
Esempio n. 10
0
def create_inv():
    """ Display the form for the user to enter the required info for an 
    inventory item """

    # get the user info saved in session
    user_id = session['user_id']

    #get the info from the form
    inv_name = request.form['inv_name']
    inv_type = request.form['inv_type']
    description = request.form['description']
    price = request.form['price']
    count_per_package = request.form['count_per_package']
    manufacturer = request.form['manufacturer']
    size = request.form['size']

    # Not using picture path yet - just initializing it as a blank
    picture_path=""
    # do we need to process keywords into a python list?
    keywords = request.form['keywords']

    
    #create the inv item
    new_inv = Inventory(user_id=user_id,
                        inv_name=inv_name,
                        inv_type=inv_type,
                        description=description,
                        price=price,
                        count_per_package=count_per_package,
                        manufacturer=manufacturer,
                        size=size,
                        picture_path=picture_path,
                        keywords=keywords)

    

    

    #add to session & commit
    # db.session.add(new_inv)
    # db.session.commit()
    new_inf.save()

    flash(f"Inventory Item: {inv_name} added.")

    return redirect('/inventory')
Esempio n. 11
0
def inventoryadd():
    req = request.data.decode("utf-8").replace("'", '"')
    data = json.loads(req)
    user_id = data['user_id']
    adj_amount = data['adj_amount']
    order_id = data['order_id']
    product_id = data['product_id']
    create_by = data['create_by']
    order_source = data['order_source']
    # 獲取最新的庫存
    beging_inventory, ending_inventory = getInvertoryNow(
        user_id, product_id, adj_amount)
    inventory = Inventory(user_id, beging_inventory, ending_inventory,
                          adj_amount, order_id, product_id, create_by,
                          order_source, '', '', '', '', '', '', '', '', '', 0)
    db.session.add(inventory)
    db.session.commit()
    return jsonify({
        'success': True,
        'msg': 'inventory is added now ',
        'data': data
    })
# if no columns are provided, they will be numbered
df = read_ods(path, 1, headers=False)

# load a file and provide custom column names
# if headers is True (the default), the header row will be overwritten
df = read_ods(path,
              1,
              columns=[
                  "user_id", "inv_id", "name", "inv_type", "description",
                  "manufacturer", "price", "count_per_package", "size",
                  "picture_path", "keywords"
              ])

print(len(df))
i = 1
while i < len(df):
    #print(df.loc[i])
    #print(df.loc[i].inv_type)
    inventory_item = Inventory(inv_id=df.loc[i].inv_id,
                               user_id=df.loc[i].user_id,
                               name=df.loc[i].name,
                               inv_type=df.loc[i].inv_type,
                               description=df.loc[i].description,
                               manufacturer=df.loc[i].manufacturer,
                               price=df.loc[i].price,
                               count_per_package=df.loc[i].count_per_package,
                               size=df.loc[i].size,
                               picture_path=df.loc[i].picture_path,
                               keywords=df.loc[i].keywords)
    i = i + 1
Esempio n. 13
0
def inventorydeliveries():
    req = request.data.decode("utf-8").replace("'", '"')
    data = json.loads(req)
    #正式環境請開通由form來
    #data = request.form
    user_id = data['user_id']
    adj_amount_set = data['adj_amount']
    create_by = data['create_by']
    order_source = data['order_source']
    shipping_first_name = data['shipping_first_name']
    shipping_last_name = data['shipping_last_name']
    shipping_company = data['shipping_company']
    shipping_address_1 = data['shipping_address_1']
    shipping_city = data['shipping_city']
    shipping_state = data['shipping_state']
    shipping_postcode = data['shipping_postcode']
    shipping_country = data['shipping_country']
    shipping_phone = data['shipping_phone']
    remark = data['remark']

    #先檢查庫存是否夠
    adj_amount_infos = adj_amount_set.split(';')
    for adj_amount_info in adj_amount_infos:
        if adj_amount_info:
            adj_amount_detial = adj_amount_info.split(',')
            product_id = int(adj_amount_detial[0])
            adj_amount = int(adj_amount_detial[2])
            Inventory_now = getEndInvertory(user_id, product_id)
            if Inventory_now is not None:
                if Inventory_now < adj_amount:
                    return jsonify({
                        'success':
                        'false',
                        'msg':
                        str(product_id) + ' Quantities is not enough'
                    })
            else:
                return jsonify({
                    'success': 'false',
                    'msg': 'Quantities is not exist'
                })

    # 產生配送單
    delivery = Delivery(user_id, create_by, order_source, shipping_first_name,
                        shipping_last_name, shipping_company,
                        shipping_address_1, shipping_city, shipping_state,
                        shipping_postcode, shipping_country, shipping_phone)
    db.session.add(delivery)
    db.session.commit()
    # 配送單上鏈
    delivery_bc_info = insertBlockChainDelivery(delivery)
    print(delivery_bc_info)
    if int(delivery_bc_info[0]) == 200:
        delivery_tx_id = delivery_bc_info[1].decode("utf-8").replace("'", '"')
    else:
        delivery_tx_id = delivery_bc_info[0]
    #   更新tx
    delivery_info_tx = Delivery.query.filter_by(id=delivery.id).one()
    if delivery_tx_id:
        delivery_info_tx.tx_id = delivery_tx_id
    db.session.commit()

    # 獲取最新的庫存
    for adj_amount_info in adj_amount_infos:
        if adj_amount_info:
            adj_amount_detial = adj_amount_info.split(',')
            product_id = int(adj_amount_detial[0])
            adj_amount = int(adj_amount_detial[2])
            #多物件指派時,扣除數量需修正為負數
            beging_inventory, ending_inventory = getInvertoryNow(
                user_id, product_id, adj_amount * -1)
            inventory = Inventory(user_id, beging_inventory, ending_inventory,
                                  adj_amount * -1, 0, product_id, create_by,
                                  order_source, shipping_first_name,
                                  shipping_last_name, shipping_company,
                                  shipping_address_1, shipping_city,
                                  shipping_postcode, shipping_country,
                                  shipping_phone, remark, delivery.id)
            db.session.add(inventory)
            db.session.commit()
            #庫存上鏈
            inventory_bc_info = insertBlockChainInventory(inventory)
            print('inventory_discount:' + str(product_id))
            print(inventory_bc_info)
            if int(inventory_bc_info[0]) == 200:
                inventory_tx_id = inventory_bc_info[1].decode("utf-8").replace(
                    "'", '"')
            else:
                inventory_tx_id = inventory_bc_info[0]
            #   更新tx
            inventory_info_tx = Inventory.query.filter_by(
                id=inventory.id).one()
            if inventory_tx_id:
                inventory_info_tx.tx_id = inventory_tx_id
            db.session.commit()

    # line通知
    token = 'M5g5yVHMV2gc6iRvs1xu5Bsb9OEj0Wux8pQcKknldMo'
    msg = '用戶已指派寄送,請登入平台,輸入物流單號 https://storeapi.pyrarc.com/backend/deliverylist?mid=' + str(
        delivery.id)
    lineNotifyMessage(token, msg)
    return jsonify({'success': 'true', 'msg': 'delivery is added now '})