mirror of
https://github.com/Noettore/fattureCCSR.git
synced 2025-10-14 19:26:39 +02:00
traf2000Converter: added initial support to Note di Credito
Signed-off-by: Ettore Dreucci <ettore.dreucci@gmail.com>
This commit is contained in:
@@ -18,12 +18,16 @@ def import_csv(csv_file_path):
|
||||
if len(linea) == 0:
|
||||
break
|
||||
num_fattura = linea[1]
|
||||
# TODO: if Nota di Credito set correct sign
|
||||
importo = int(linea[15].replace("€", "").replace(",", "").replace(".", "").replace("(", "").replace(")", ""))
|
||||
tipo_fattura = linea[8]
|
||||
importo = linea[15]
|
||||
segno = 1
|
||||
if tipo_fattura == "Nota di credito" and '(' not in importo:
|
||||
segno = -1
|
||||
importo = int(linea[15].replace("€", "").replace(",", "").replace(".", "").replace("(", "").replace(")", "")) * segno
|
||||
if num_fattura not in fatture:
|
||||
fattura = {
|
||||
"numFattura": num_fattura,
|
||||
"tipoFattura": linea[8],
|
||||
"tipoFattura": tipo_fattura,
|
||||
"rifFattura": linea[4],
|
||||
"dataFattura": linea[2].replace("/", ""),
|
||||
"ragioneSociale": unidecode.unidecode(linea[6] + " " + " ".join(linea[5].split(" ")[0:2])),
|
||||
@@ -53,19 +57,16 @@ def import_xml(xml_file_path):
|
||||
for fattura in root.iter('{STAT_FATTURATO_CTERZI}Dettagli'):
|
||||
righe = dict()
|
||||
num_fattura = fattura.get('protocollo_fatturatestata')
|
||||
rif_fattura = fattura.get('protocollo_fatturatestata1')
|
||||
data_fattura = datetime.datetime.fromisoformat(fattura.get('data_fatturatestata')).strftime("%d%m%Y")
|
||||
tipo_fattura = fattura.get('fat_ndc')
|
||||
ragione_sociale = unidecode.unidecode(fattura.get('cognome_cliente') + ' ' + ' '.join(fattura.get('nome_cliente').split(' ')[0:2]))
|
||||
pos_divide = str(len(fattura.get('cognome_cliente')) + 1)
|
||||
cf_piva = fattura.get('cf_piva_cliente')
|
||||
importo_totale = 0
|
||||
ritenuta_acconto = 0
|
||||
|
||||
for riga in fattura.iter('{STAT_FATTURATO_CTERZI}Dettagli2'):
|
||||
desc = riga.get('descrizione_fatturariga1')
|
||||
# TODO: if Nota di Credito set correct sign
|
||||
importo = int(format(round(float(riga.get('prezzounitario_fatturariga1')), 2), '.2f').replace('.', '').replace('-', ''))
|
||||
segno = 1
|
||||
if tipo_fattura == 'Nota di credito' and '-' not in riga.get('prezzounitario_fatturariga1'):
|
||||
segno = -1
|
||||
importo = int(format(round(float(riga.get('prezzounitario_fatturariga1')), 2), '.2f').replace('.', '').replace('-', '')) * segno
|
||||
if desc == "Ritenuta d'acconto":
|
||||
ritenuta_acconto = importo
|
||||
else:
|
||||
@@ -75,11 +76,11 @@ def import_xml(xml_file_path):
|
||||
fattura_elem = {
|
||||
"numFattura": num_fattura,
|
||||
"tipoFattura": tipo_fattura,
|
||||
"rifFattura": rif_fattura,
|
||||
"dataFattura": data_fattura,
|
||||
"ragioneSociale": ragione_sociale,
|
||||
"posDivide": pos_divide,
|
||||
"cf": cf_piva,
|
||||
"rifFattura": fattura.get('protocollo_fatturatestata1'),
|
||||
"dataFattura": datetime.datetime.fromisoformat(fattura.get('data_fatturatestata')).strftime("%d%m%Y"),
|
||||
"ragioneSociale": unidecode.unidecode(fattura.get('cognome_cliente') + ' ' + ' '.join(fattura.get('nome_cliente').split(' ')[0:2])),
|
||||
"posDivide": str(len(fattura.get('cognome_cliente')) + 1),
|
||||
"cf": fattura.get('cf_piva_cliente'),
|
||||
"importoTotale": importo_totale,
|
||||
"ritenutaAcconto": ritenuta_acconto,
|
||||
"righe": righe,
|
||||
|
@@ -14,10 +14,10 @@ def convert(fatture, out_file_path):
|
||||
print("Errore: il documento " + fattura["numFattura"] + " non ha cf/piva")
|
||||
continue
|
||||
|
||||
if fattura["tipoFattura"] == "Nota di credito":
|
||||
""" if fattura["tipoFattura"] == "Nota di credito":
|
||||
# As for now this script doesn't handle "Note di credito"
|
||||
print(fattura["numFattura"])
|
||||
continue
|
||||
continue """
|
||||
|
||||
linea = ["04103", "3", "0", "00000"] # TRF-DITTA + TRF-VERSIONE + TRF-TARC + TRF-COD-CLIFOR
|
||||
linea.append(fattura["ragioneSociale"][:32]+' '*(32-len(fattura["ragioneSociale"]))) # TRF-RASO
|
||||
@@ -59,7 +59,11 @@ def convert(fatture, out_file_path):
|
||||
for desc, imponibile in fattura["righe"].items():
|
||||
conta += 1
|
||||
imponibile = str(imponibile)
|
||||
imponibile = '0'*(11-len(imponibile)) + imponibile + "+"
|
||||
if '-' in imponibile:
|
||||
imponibile.replace('-', '')
|
||||
imponibile = '0'*(11-len(imponibile)) + imponibile + "-"
|
||||
else:
|
||||
imponibile = '0'*(11-len(imponibile)) + imponibile + "+"
|
||||
linea.append(imponibile) # TRF-IMPONIB
|
||||
if desc != "Bollo":
|
||||
linea.append('308') # TRF-ALIQ
|
||||
@@ -71,14 +75,22 @@ def convert(fatture, out_file_path):
|
||||
linea.append('0'*31)
|
||||
|
||||
totale = str(fattura["importoTotale"])
|
||||
totale = '0'*(11-len(totale)) + totale + "+"
|
||||
if '-' in totale:
|
||||
totale.replace('-', '')
|
||||
totale = '0'*(11-len(totale)) + totale + "-"
|
||||
else:
|
||||
totale = '0'*(11-len(totale)) + totale + "+"
|
||||
linea.append(totale) # TRF-TOT-FAT
|
||||
|
||||
conta = 0
|
||||
for desc, imponibile in fattura["righe"].items():
|
||||
conta += 1
|
||||
imponibile = str(imponibile)
|
||||
imponibile = '0'*(11-len(imponibile)) + imponibile + "+"
|
||||
if '-' in imponibile:
|
||||
imponibile.replace('-', '')
|
||||
imponibile = '0'*(11-len(imponibile)) + imponibile + "-"
|
||||
else:
|
||||
imponibile = '0'*(11-len(imponibile)) + imponibile + "+"
|
||||
if desc != "Bollo":
|
||||
linea.append('4004300') # TRF-CONTO-RIC
|
||||
else:
|
||||
@@ -151,8 +163,11 @@ def convert(fatture, out_file_path):
|
||||
linea.append('0'*8 + 'N' + '000' + totale + '0'*14 + '0'*8 + ' '*40) # TRF-A21CO-DATA + TRF-A21CO-FLAG + TRF-A21CO-ALQ + TRF-A21CO-IMPORTO + TRF-A21CO-IMPOSTA + TRF-A21CO-NDOC + TRF-A21CO-CONTRATTO
|
||||
linea.append(('0'*6 + ' '*16 + '0'*8 + ' ' + '000' + '0'*14 + '0'*14 + '0'*8 + ' '*40)*49) # TRF-A21CO-DATA + TRF-A21CO-FLAG + TRF-A21CO-ALQ + TRF-A21CO-IMPORTO + TRF-A21CO-IMPOSTA + TRF-A21CO-NDOC + TRF-A21CO-CONTRATTO
|
||||
|
||||
# TODO: if Nota di Credito append ref. invoice no and date
|
||||
linea.append('0'*16) # TRF-RIF-FATT-NDOC + TRF-RIF-FATT-DDOC
|
||||
if fattura["tipoFattura"] == "Nota di credito":
|
||||
linea.append('000' + fattura["rifFattura"][4:9]) # TRF-RIF-FATT-NDOC
|
||||
linea.append('0'*8) # TRF-RIF-FATT-DDOC
|
||||
else:
|
||||
linea.append('0'*16) # TRF-RIF-FATT-NDOC + TRF-RIF-FATT-DDOC
|
||||
linea.append(' ' + 'SR' + '2') # TRF-A21CO-TIPO + TRF-A21CO-TIPO-SPESA + TRF-A21CO-FLAG-SPESA
|
||||
linea.append((' ' + ' ' + ' ')*49) # TRF-A21CO-TIPO + TRF-A21CO-TIPO-SPESA + TRF-A21CO-FLAG-SPESA
|
||||
linea.append(' '*78) # TRF-SPESE-FUNEBRI + FILLER + FILLER
|
||||
|
Reference in New Issue
Block a user