add write excel/insert
This commit is contained in:
87
update.py
87
update.py
@ -0,0 +1,87 @@
|
||||
import mysql.connector
|
||||
from mysql.connector import Error
|
||||
import pandas as pd
|
||||
import math
|
||||
|
||||
value_update = []
|
||||
|
||||
def update_records(connection,codice,prezzo,sc1,sc2,listino,ricarica,codice_barre,codice_alternativo):
|
||||
|
||||
try:
|
||||
result = []
|
||||
cursor = connection.cursor()
|
||||
|
||||
if sc1 is not None :
|
||||
query_lsa = "UPDATE lsa SET TSM_CODICE = %s WHERE ART_CODICE = %s AND TLA_CODICE = '1'"
|
||||
cursor.execute(query_lsa, (sc1, codice))
|
||||
count = cursor.rowcount
|
||||
result.append(count)
|
||||
|
||||
if sc2 is not None:
|
||||
query_lsv_tsm = "UPDATE lsv SET TSM_CODICE = %s WHERE ART_CODICE = %s AND TLV_CODICE = %s"
|
||||
cursor.execute(query_lsv_tsm, (sc2, codice,listino))
|
||||
count = cursor.rowcount
|
||||
result.append(count)
|
||||
|
||||
if prezzo is not None and not math.isnan(prezzo):
|
||||
query_lsa = "UPDATE lsa SET PREZZO = %s WHERE ART_CODICE = %s AND TLA_CODICE = '1'"
|
||||
cursor.execute(query_lsa, (prezzo,codice))
|
||||
count = cursor.rowcount
|
||||
result.append(count)
|
||||
|
||||
if ricarica is not None and not math.isnan(ricarica):
|
||||
query_lsv = "UPDATE lsv SET TRL_CODICE = %s WHERE ART_CODICE = %s AND TLV_CODICE = %s"
|
||||
cursor.execute(query_lsv, (ricarica, codice,listino))
|
||||
count = cursor.rowcount
|
||||
result.append(count)
|
||||
|
||||
if codice_barre is not None:
|
||||
query_bar = "UPDATE bar SET CODICE_BARRE = %s WHERE ART_CODICE = %s"
|
||||
cursor.execute(query_bar, (codice_barre, codice))
|
||||
count = cursor.rowcount
|
||||
result.append(count)
|
||||
|
||||
if not pd.isna(codice_alternativo):
|
||||
query_alt = "UPDATE art SET CODICE_ALTERNATIVO = %s WHERE codice = %s"
|
||||
cursor.execute(query_alt, (codice_alternativo, codice))
|
||||
count = cursor.rowcount
|
||||
result.append(count)
|
||||
|
||||
connection.commit()
|
||||
|
||||
if all(value == 0 for value in result):
|
||||
print(f"Record non aggiornati per ART_CODICE: {codice}")
|
||||
|
||||
if math.isnan(prezzo):
|
||||
prezzo = 0
|
||||
|
||||
if math.isnan(listino):
|
||||
listino = 0
|
||||
|
||||
if math.isnan(sc1):
|
||||
sc1 = 0
|
||||
|
||||
if math.isnan(sc2):
|
||||
sc2 = 0
|
||||
|
||||
if math.isnan(ricarica):
|
||||
ricarica = 0
|
||||
|
||||
|
||||
if math.isnan(codice_barre):
|
||||
codice_barre = 0
|
||||
|
||||
if pd.isna(codice_alternativo):
|
||||
codice_alternativo = 0;
|
||||
|
||||
row = [codice,prezzo,listino,sc1,ricarica,codice_barre,codice_alternativo,sc2]
|
||||
value_update.append(row)
|
||||
return value_update
|
||||
|
||||
else:
|
||||
print(f"Record aggiornati per ART_CODICE: {codice}")
|
||||
|
||||
except Error as e:
|
||||
print(f"Errore durante l'aggiornamento: {e}")
|
||||
finally:
|
||||
cursor.close()
|
||||
Reference in New Issue
Block a user