Last active
August 29, 2017 01:39
-
-
Save xlanor/adce5f27fc50ce9b0b5fc6410f01174d to your computer and use it in GitHub Desktop.
fuck this shit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
else: | |
strippedbinid = binid.strip() | |
if not strippedbinid: #empty bin, filled with space. no_bin | |
cur.execute("""SELECT bin_id, quantity | |
FROM Stockage | |
WHERE sku_id = %s | |
AND user_id = %s | |
AND quantity != %s | |
ORDER BY (expiry_datetime is NULL),(expiry_datetime = '0000-00-00 00:00:00'), expiry_datetime ASC | |
LIMIT 1""", (sku, user_id,0,)) | |
data = cur.fetchone() | |
if cur.rowcount > 0: | |
binqty = data[1] | |
binid = data[0] | |
cur.execute("""SELECT SUM(quantity) | |
AS avaliableqty | |
FROM `Stockage` | |
WHERE `user_id` | |
LIKE %s | |
AND sku_id = %s""",(user_id,sku,)) | |
avalqty = cur.fetchone() | |
LOGGER.error(avalqty) | |
if cur.rowcount > 0: | |
avalquant = avalqty[0] | |
if totalquantity < int(avalquant): | |
if binqty < qty: #if bin qty less than order qty | |
amountleft = int(qty) - int(binqty) #amount left in order = bin qty - order qty | |
LOGGER.error(str(amountleft) + 'amount left') | |
usedbin = [] | |
usedbin.append({'binid': binid,'qty': binqty}) | |
lessthan = 'true' | |
while lessthan == 'true': #begins a while loop, | |
usedbinstring = "" | |
for usedbinid in usedbin: | |
usedbinstring += """ AND bin_id != '""" | |
usedbinstring += usedbinid['binid'] | |
usedbinstring += """' """ | |
LOGGER.error(usedbinstring) | |
cur.execute("""SELECT bin_id, quantity | |
FROM Stockage | |
WHERE sku_id = %s | |
AND user_id = %s | |
AND quantity != %s""" | |
+usedbinstring+ | |
"""ORDER BY (expiry_datetime is NULL),(expiry_datetime = '0000-00- 00 00:00:00'), expiry_datetime ASC | |
LIMIT 1""", (sku, user_id,0,)) | |
data = cur.fetchone() | |
if cur.rowcount > 0: | |
LOGGER.error(data[1]) | |
if int(data[1]) < amountleft: | |
amountleft = amountleft - int(data[1]) | |
usedbin.append({'binid':data[0], 'qty':data[1]}) | |
else: | |
usedbin.append({'binid':data[0], 'qty':amountleft}) | |
lessthan = 'false' | |
LOGGER.error(usedbin) | |
for each in usedbin: | |
itemquant = each['qty'] | |
binid = each['binid'] | |
cur.execute("""INSERT INTO B2BOrderItems VALUES(%s,%s,%s,%s,%s,'','','','')""", (orderid,sku,int(itemquant),binid,listprice,)) | |
else: | |
errortxt = 'Insufficent stockage for' + sku | |
cur.execute("""DELETE FROM B2BOrderPending WHERE order_counter = %s""", (lastrowid,)) | |
else: | |
errortxt = 'Insufficent stockage for' + sku | |
cur.execute("""DELETE FROM B2BOrderPending WHERE order_counter = %s""",(lastrowid,)) | |
else: | |
errortxt = 'Insufficent stockage for' + sku | |
cur.execute("""DELETE FROM B2BOrderPending WHERE order_counter = %s""",(lastrowid,)) | |
return jsonify(message=errortxt), 400 | |
else: #else, if bin selected. | |
cur.execute("""INSERT INTO B2BOrderItems VALUES(%s,%s,%s,%s,%s,'','','','')""",(orderid,sku,qty,binid,listprice,)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment