fix value nan/add view
This commit is contained in:
@ -1 +0,0 @@
|
||||
,pc-sviluppo1,pcsviluppo1,10.12.2024 10:17,file:///home/pc-sviluppo1/.config/libreoffice/4;
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -15,11 +15,13 @@ tla = 1
|
||||
value_insert = []
|
||||
def insert_records(connection,codice,descrizione,um,costo,sc1,sc2,ricarica,listino,codice_alternativo,codice_barre,art,tsa_codice):
|
||||
try:
|
||||
print('tipo tsa_codice')
|
||||
|
||||
result = []
|
||||
cursor = connection.cursor()
|
||||
if art == False:
|
||||
query_art = "INSERT INTO art (codice,DESCRIZIONE1,TUM_CODICE,codice_alternativo,TSA_CODICE,TUB_CODICE,TCM_CODICE,TGM_CODICE,TIV_CODICE_VENDITE,TIV_CODICE_ACQUISTI,TCA_CODICE,TAQ_CODICE,TS3_CODICE,TP2_CODICE,TIN_CODICE,TAA_CODICE) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
|
||||
cursor.execute(query_art,(codice,descrizione,um,codice_alternativo,tsa_codice,'0','0','0','22','22','0','0','0','0','0','0'))
|
||||
query_art = "INSERT INTO art (codice,DESCRIZIONE1,TUM_CODICE,codice_alternativo,TSA_CODICE,TUB_CODICE,TCM_CODICE,TGM_CODICE,TIV_CODICE_VENDITE,TIV_CODICE_ACQUISTI,TCA_CODICE,TAQ_CODICE,TS3_CODICE,TP2_CODICE,TIN_CODICE,TAA_CODICE,TNI_CODICE) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
|
||||
cursor.execute(query_art,(codice,descrizione,um,codice_alternativo,tsa_codice,'0','0','0','22','22','0','0','0','0','0','0','0'))
|
||||
count = cursor.rowcount
|
||||
result.append(count)
|
||||
|
||||
@ -29,7 +31,6 @@ def insert_records(connection,codice,descrizione,um,costo,sc1,sc2,ricarica,listi
|
||||
result.append(count)
|
||||
|
||||
if listino == 1:
|
||||
print('listino è uno')
|
||||
query_lsv = "INSERT INTO lsv (ART_CODICE,DATA_FINE,DATA_INIZIO,PREZZO,TSM_CODICE,TRL_CODICE,TLV_CODICE) VALUES (%s,%s,%s,%s,%s,%s,%s)"
|
||||
cursor.execute(query_lsv,(codice,data_fine,formatted_date,costo,sc2,ricarica,listino))
|
||||
count = cursor.rowcount
|
||||
|
||||
17
main.py
17
main.py
@ -13,6 +13,7 @@ from update import update_records
|
||||
from insert import insert_records
|
||||
from write import write_excel
|
||||
from write_excel_insert import write_excel_insert
|
||||
from upload import upload_excel
|
||||
|
||||
|
||||
host = "62.86.98.170"
|
||||
@ -24,7 +25,8 @@ port = 3307
|
||||
#creo la connessione al database
|
||||
conn = create_connection(host, user, password, database, port)
|
||||
#leggo il file excel
|
||||
df = pd.read_excel('TEST.xlsx', usecols='A:N')
|
||||
file_input = upload_excel()
|
||||
df = pd.read_excel(file_input, usecols='A:N')
|
||||
|
||||
#leggo le colonne del file excel
|
||||
for index, row in df.iterrows():
|
||||
@ -33,6 +35,7 @@ for index, row in df.iterrows():
|
||||
um = row['UN']
|
||||
costo = row['COSTO']
|
||||
|
||||
|
||||
if math.isnan(row['SC1']):
|
||||
sc1 = row['SC1']
|
||||
else:
|
||||
@ -68,11 +71,13 @@ for index, row in df.iterrows():
|
||||
codice_alternativo = str(row['CODICE ALTERNATIVO'])
|
||||
prezzo = float(row['COSTO'])
|
||||
|
||||
|
||||
if math.isnan(row['TSA_CODICE']):
|
||||
tsa_codice = row['TSA_CODICE']
|
||||
else:
|
||||
tsa_codice = int(row['TSA_CODICE'])
|
||||
|
||||
|
||||
if conn :
|
||||
if ricarica1 is not None and not math.isnan(ricarica1):
|
||||
listino = 1
|
||||
@ -95,7 +100,7 @@ for index, row in df.iterrows():
|
||||
if value_update is not None:
|
||||
write_excel(value_update)
|
||||
else: ## se non esiste o non esiste con quel listino effettuo l'inserimento
|
||||
costo = 0.00
|
||||
##costo = 0.00
|
||||
if descrizione is None :
|
||||
descrizione = ' '
|
||||
if um is None:
|
||||
@ -106,12 +111,12 @@ for index, row in df.iterrows():
|
||||
sc2 = ' '
|
||||
if math.isnan(ricarica):
|
||||
ricarica = ' '
|
||||
if codice_alternativo is None:
|
||||
if not pd.isna(codice_alternativo):
|
||||
codice_alternativo = ' '
|
||||
if codice_barre is None:
|
||||
codice_barre = ' '
|
||||
if not pd.isna(codice_barre):
|
||||
codice_barre = '0000000000000'
|
||||
if math.isnan(tsa_codice):
|
||||
tsa_codice = ' '
|
||||
tsa_codice = '0'
|
||||
|
||||
value_insert = insert_records(conn,codice,descrizione,um,costo,sc1,sc2,ricarica,listino,codice_alternativo,codice_barre,art,tsa_codice)
|
||||
write_excel_insert(value_insert)
|
||||
|
||||
@ -73,7 +73,6 @@ def update_records(connection,codice,prezzo,sc1,sc2,listino,ricarica,codice_barr
|
||||
if math.isnan(ricarica):
|
||||
ricarica = 0
|
||||
|
||||
|
||||
if math.isnan(codice_barre):
|
||||
codice_barre = 0
|
||||
|
||||
|
||||
17
upload.py
Normal file
17
upload.py
Normal file
@ -0,0 +1,17 @@
|
||||
import pandas as pd
|
||||
import mysql.connector
|
||||
import math
|
||||
import xlsxwriter
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog,messagebox
|
||||
from datetime import datetime
|
||||
from mysql.connector import Error
|
||||
|
||||
def upload_excel():
|
||||
# Crea una finestra di dialogo per selezionare il file
|
||||
root = tk.Tk()
|
||||
root.withdraw() # Nasconde la finestra principale
|
||||
file_path = filedialog.askopenfilename(title="Seleziona un file Excel",
|
||||
filetypes=[("Tutti i file","*.*")])
|
||||
excel_filename = r"{}".format(file_path)
|
||||
return excel_filename
|
||||
2
write.py
2
write.py
@ -26,8 +26,10 @@ def write_excel(value_update):
|
||||
for col_index, value in enumerate(row_data):
|
||||
worksheet.write(row_index + 1, col_index, value)
|
||||
|
||||
|
||||
root = tk.Tk()
|
||||
loading_label = tk.Label(root, text="")
|
||||
loading_label.pack(pady=20)
|
||||
loading_label.config(text="Aggiornamento in corso... Attendere...")
|
||||
|
||||
workbook.close()
|
||||
Reference in New Issue
Block a user