Esempio n. 1
0
    def need_ingredients(self):

        missing_list = []

        bottle_type_list = []
        
	for i in self.ingredients:
	    for item in db._bottle_types_db:
		if  i[0] == item[2]:
		    bottle_type_list.append(item)


        amounts_list = []

	for i in bottle_type_list:
	    if db.check_inventory(i[0], i[1]):
		amount = (i[0], i[2], db.get_liquor_amount(i[0], i[1]))
		amounts_list.append(amount)        
                
        for i in self.ingredients:
            amount = 0.0
            for item in amounts_list: 
                if i[0]==item[1]:
                    if amount < float(item[2]): 
                        amount = float(item[2])
            ing_amount = convert.convert_ml(i[1])            
            if float(amount) < float(ing_amount):
                needed = float(ing_amount)-float(amount)
                needed_tup = (i[0], needed)
                missing_list.append(needed_tup)


	return missing_list
Esempio n. 2
0
    def need_ingredients(self):

        missing_list = []

        # PUT ALL THE LIQUOR TYPES NEEDED IN A LIST(see if they exist) ===========

        bottle_type_list = []
        
	for i in self.ingredients:
	    for item in db._bottle_types_db:
		if  i[0] == item[2]:
		    bottle_type_list.append(item)

        #print bottle_type_list, "bottle_type_list"

        #=========================================================================


        # CHECK INVENTORY FOR THOSE LIQUORS(put them in a list of tuples)=========

        amounts_list = []

	for i in bottle_type_list:
	    if db.check_inventory(i[0], i[1]):
		amount = (i[0], i[2], db.get_liquor_amount(i[0], i[1]))
		amounts_list.append(amount)


        #print amounts_list, "amounts_list"
            
        
        #=========================================================================

        # CREATE THE MISSING LIST=================================================

        
                
        for i in self.ingredients:
            amount = 0.0
            for item in amounts_list: #replace smaller amount with larger
                if i[0]==item[1]:
                    if amount < float(item[2]): 
                        amount = float(item[2])
            ing_amount = convert.convert_ml(i[1])#convert the ingredient to ml
            
            if float(amount) < float(ing_amount):#compare the amount with ing
                needed = float(ing_amount)-float(amount)
                needed_tup = (i[0], needed)
                missing_list.append(needed_tup)#add to missing list


	return missing_list
Esempio n. 3
0
    def recv(self, environ, start_response):
        formdata = environ['QUERY_STRING']
        results = urlparse.parse_qs(formdata)

        amount = results['amount'][0]

        amount_ml = convert.convert_ml(amount)

        content_type = 'text/html'
        data = "Amount in ml: %d <a href='/'>return to index</a>" % (amount_ml)

        start_response('200 OK', list(html_headers))
        return [data]
Esempio n. 4
0
def get_liquor_amount(mfg, liquor):
    "Retrieve the total amount of any given liquor currently in inventory."
    amounts = []
    for key in _inventory_db:
        if mfg == key[0] and liquor == key[1]:
           amounts.append(_inventory_db[key])
            
    total_ml = 0.0

    for i in amounts:
        total_ml += float(convert.convert_ml(i))    

    return total_ml 
Esempio n. 5
0
def add_to_inventory(mfg, liquor, amount):
    "Add the given liquor/amount to inventory."
    if not _check_bottle_type_exists(mfg, liquor):
        err = "Missing liquor: manufacturer '%s', name '%s'" % (mfg, liquor)
        raise LiquorMissing(err)

    if check_inventory(mfg, liquor):
	
        new_amount = convert.convert_ml(amount)
        old_amount = get_liquor_amount(mfg, liquor)
        new_total = float(old_amount) + float(new_amount)
        _inventory_db[(mfg, liquor)] = str(new_total)+' ml'


    else:    
        _inventory_db[(mfg, liquor)] =  amount
Esempio n. 6
0
def add_to_inventory(mfg, liquor, amount):
    "Add the given liquor/amount to inventory."
    if not _check_bottle_type_exists(mfg, liquor):
        err = "Missing liquor: manufacturer '%s', name '%s'" % (mfg, liquor)
        raise LiquorMissing(err)

    # SINCE INVENTORY IS A DICT, CHECK INVENTORY FOR LIQUOR
    # AND ADD INVENTORY AMOUNT WITH NEW AMOUNT  

    if check_inventory(mfg, liquor):
	
        new_amount = convert.convert_ml(amount)#FLOAT AMOUNT
        old_amount = get_liquor_amount(mfg, liquor)
        new_total = float(old_amount) + float(new_amount)
        _inventory_db[(mfg, liquor)] = str(new_total)+' ml'


    else:    
    # ADD/UPDATE INVENTORY ITEM
        _inventory_db[(mfg, liquor)] =  amount
Esempio n. 7
0
 def rpc_convert_units_to_ml(self, amount):
     amt = convert.convert_ml(amount)
     return amt