Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def submit_imei(request):
- if request.session.is_empty():
- return redirect(customer_view.login)
- else:
- sql_1 = "select * from history where history_id = (select max(history_id) from history)"
- sql_2 = "SELECT IMEI FROM TEMP_IMEI"
- sql_3 = "INSERT INTO STOCK(STOCK_PRODUCT_ID, STOCK_IMEI) VALUES(%s, %s)"
- sql_4 = "INSERT INTO PRODUCT_SPECIFICATION(PRODUCT_ID, NAME, DESCRIPTION, PRICE, STOCK, WARRANTY,BUYING_PRICE) " \
- "VALUES(%s, %s, %s, %s, %s, %s, %s)"
- sql_5 = "INSERT INTO PRODUCT_IMEI(IMEI_NO) VALUES(%s)"
- sql_6 = "DELETE FROM TEMP_IMEI"
- cursor = connection.cursor()
- cursor.execute(sql_1)
- result_fetched_1 = cursor.fetchall()
- cursor.close()
- history_id = -1
- product_name = ""
- total_product = -1
- price = 0
- description = ""
- warranty = 0
- buying_price = 0
- for i in result_fetched_1:
- history_id = i[0]
- product_name = i[1]
- description = i[2]
- price = i[3]
- total_product = i[4]
- warranty = i[5]
- #$
- buying_price = i[6]
- cursor = connection.cursor()
- cursor.execute(sql_2)
- result_fetched_2 = cursor.fetchall()
- cursor.close()
- imei_table = []
- for i in result_fetched_2:
- imei_table.append(i[0])
- print(imei_table)
- for data in imei_table:
- print(data)
- cursor = connection.cursor()
- for data in imei_table:
- cursor.execute(sql_5, [data])
- connection.commit()
- #cursor.execute(sql_4, [history_id, product_name, description, price, total_product, warranty])
- cursor.close()
- cursor = connection.cursor()
- sql_product_check = "select * from PRODUCT_SPECIFICATION WHERE NAME=%s AND DESCRIPTION=%s"
- cursor.execute(sql_product_check, [product_name, description])
- product = cursor.fetchall()
- cursor.close()
- # product = [row[0] for row in products]
- if not product:
- print("product list khali . so product spec table e insert hobe new row")
- cursor = connection.cursor()
- cursor.execute(sql_4, [history_id, product_name, description, price, total_product, warranty, buying_price])
- connection.commit()
- cursor.close()
- else:
- print("product list e ase, so spec table e just update hobe")
- print(type(product[0]))
- print("product print hoy")
- print(product[0])
- spec_id = int(product[0][0])
- history_id = spec_id
- stock = int(product[0][4]) + int(total_product)
- cursor = connection.cursor()
- sql_update = "UPDATE PRODUCT_SPECIFICATION SET PRICE = %s, STOCK = %s, WARRANTY = %s, " \
- "BUYING_PRICE = %s WHERE PRODUCT_ID = %s"
- cursor.execute(sql_update, [price, stock, warranty, buying_price, spec_id])
- connection.commit()
- cursor.close()
- employee_id = request.session['employee_id']
- sql = "SELECT BRANCH_ID FROM BRANCH_EMPLOYEE WHERE EMPLOYEE_ID = %s"
- cursor = connection.cursor()
- cursor.execute(sql, [employee_id])
- result = cursor.fetchall()
- branch_id = result[0][0]
- cursor.close()
- cursor = connection.cursor()
- for data in imei_table:
- cursor.callproc('insert_into_stock', [history_id, data])
- # cursor.execute(sql_3, [history_id, data])
- cursor.callproc('insert_into_branch_stock', [branch_id, data])
- # cursor.execute(sql_7, [branch_id, data])
- connection.commit()
- cursor.execute(sql_6)
- connection.close()
- messages.info(request, "Stock added successfully")
- return redirect(load)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement