Advertisement
abrar1

Untitled

Dec 11th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.93 KB | None | 0 0
  1.  
  2. def submit_imei(request):
  3.     if request.session.is_empty():
  4.         return redirect(customer_view.login)
  5.     else:
  6.  
  7.         sql_1 = "select * from history where history_id = (select max(history_id) from history)"
  8.         sql_2 = "SELECT IMEI FROM TEMP_IMEI"
  9.         sql_3 = "INSERT INTO STOCK(STOCK_PRODUCT_ID, STOCK_IMEI) VALUES(%s, %s)"
  10.         sql_4 = "INSERT INTO PRODUCT_SPECIFICATION(PRODUCT_ID, NAME, DESCRIPTION, PRICE, STOCK, WARRANTY,BUYING_PRICE) " \
  11.                 "VALUES(%s, %s, %s, %s, %s, %s, %s)"
  12.         sql_5 = "INSERT INTO PRODUCT_IMEI(IMEI_NO) VALUES(%s)"
  13.         sql_6 = "DELETE FROM TEMP_IMEI"
  14.  
  15.         cursor = connection.cursor()
  16.         cursor.execute(sql_1)
  17.         result_fetched_1 = cursor.fetchall()
  18.         cursor.close()
  19.         history_id = -1
  20.         product_name = ""
  21.         total_product = -1
  22.         price = 0
  23.         description = ""
  24.         warranty = 0
  25.         buying_price = 0
  26.         for i in result_fetched_1:
  27.             history_id = i[0]
  28.             product_name = i[1]
  29.             description = i[2]
  30.             price = i[3]
  31.             total_product = i[4]
  32.             warranty = i[5]
  33.             #$
  34.             buying_price = i[6]
  35.  
  36.         cursor = connection.cursor()
  37.         cursor.execute(sql_2)
  38.         result_fetched_2 = cursor.fetchall()
  39.         cursor.close()
  40.  
  41.         imei_table = []
  42.         for i in result_fetched_2:
  43.             imei_table.append(i[0])
  44.  
  45.         print(imei_table)
  46.         for data in imei_table:
  47.             print(data)
  48.         cursor = connection.cursor()
  49.  
  50.         for data in imei_table:
  51.             cursor.execute(sql_5, [data])
  52.             connection.commit()
  53.  
  54.         #cursor.execute(sql_4, [history_id, product_name, description, price, total_product, warranty])
  55.         cursor.close()
  56.  
  57.         cursor = connection.cursor()
  58.         sql_product_check = "select * from PRODUCT_SPECIFICATION WHERE NAME=%s AND DESCRIPTION=%s"
  59.         cursor.execute(sql_product_check, [product_name, description])
  60.         product = cursor.fetchall()
  61.         cursor.close()
  62.  
  63.         # product = [row[0] for row in products]
  64.  
  65.         if not product:
  66.             print("product list khali . so product spec table e insert hobe new row")
  67.             cursor = connection.cursor()
  68.             cursor.execute(sql_4, [history_id, product_name, description, price, total_product, warranty, buying_price])
  69.             connection.commit()
  70.             cursor.close()
  71.  
  72.         else:
  73.             print("product list e ase, so spec table e just update hobe")
  74.             print(type(product[0]))
  75.             print("product print hoy")
  76.             print(product[0])
  77.             spec_id = int(product[0][0])
  78.             history_id = spec_id
  79.             stock = int(product[0][4]) + int(total_product)
  80.             cursor = connection.cursor()
  81.             sql_update = "UPDATE PRODUCT_SPECIFICATION SET PRICE = %s, STOCK = %s, WARRANTY = %s, " \
  82.                          "BUYING_PRICE = %s WHERE PRODUCT_ID = %s"
  83.             cursor.execute(sql_update, [price, stock, warranty, buying_price, spec_id])
  84.             connection.commit()
  85.             cursor.close()
  86.  
  87.         employee_id = request.session['employee_id']
  88.  
  89.         sql = "SELECT BRANCH_ID FROM BRANCH_EMPLOYEE WHERE EMPLOYEE_ID = %s"
  90.         cursor = connection.cursor()
  91.         cursor.execute(sql, [employee_id])
  92.         result = cursor.fetchall()
  93.         branch_id = result[0][0]
  94.         cursor.close()
  95.         cursor = connection.cursor()
  96.  
  97.         for data in imei_table:
  98.             cursor.callproc('insert_into_stock', [history_id, data])
  99.             # cursor.execute(sql_3, [history_id, data])
  100.             cursor.callproc('insert_into_branch_stock', [branch_id, data])
  101.  
  102.             # cursor.execute(sql_7, [branch_id, data])
  103.             connection.commit()
  104.  
  105.         cursor.execute(sql_6)
  106.         connection.close()
  107.         messages.info(request, "Stock added successfully")
  108.         return redirect(load)
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement