mirror of
https://github.com/Noettore/fattureCCSR.git
synced 2025-10-15 11:46: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:
|
if len(linea) == 0:
|
||||||
break
|
break
|
||||||
num_fattura = linea[1]
|
num_fattura = linea[1]
|
||||||
# TODO: if Nota di Credito set correct sign
|
tipo_fattura = linea[8]
|
||||||
importo = int(linea[15].replace("€", "").replace(",", "").replace(".", "").replace("(", "").replace(")", ""))
|
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:
|
if num_fattura not in fatture:
|
||||||
fattura = {
|
fattura = {
|
||||||
"numFattura": num_fattura,
|
"numFattura": num_fattura,
|
||||||
"tipoFattura": linea[8],
|
"tipoFattura": tipo_fattura,
|
||||||
"rifFattura": linea[4],
|
"rifFattura": linea[4],
|
||||||
"dataFattura": linea[2].replace("/", ""),
|
"dataFattura": linea[2].replace("/", ""),
|
||||||
"ragioneSociale": unidecode.unidecode(linea[6] + " " + " ".join(linea[5].split(" ")[0:2])),
|
"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'):
|
for fattura in root.iter('{STAT_FATTURATO_CTERZI}Dettagli'):
|
||||||
righe = dict()
|
righe = dict()
|
||||||
num_fattura = fattura.get('protocollo_fatturatestata')
|
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')
|
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
|
importo_totale = 0
|
||||||
ritenuta_acconto = 0
|
ritenuta_acconto = 0
|
||||||
|
|
||||||
for riga in fattura.iter('{STAT_FATTURATO_CTERZI}Dettagli2'):
|
for riga in fattura.iter('{STAT_FATTURATO_CTERZI}Dettagli2'):
|
||||||
desc = riga.get('descrizione_fatturariga1')
|
desc = riga.get('descrizione_fatturariga1')
|
||||||
# TODO: if Nota di Credito set correct sign
|
segno = 1
|
||||||
importo = int(format(round(float(riga.get('prezzounitario_fatturariga1')), 2), '.2f').replace('.', '').replace('-', ''))
|
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":
|
if desc == "Ritenuta d'acconto":
|
||||||
ritenuta_acconto = importo
|
ritenuta_acconto = importo
|
||||||
else:
|
else:
|
||||||
@@ -75,11 +76,11 @@ def import_xml(xml_file_path):
|
|||||||
fattura_elem = {
|
fattura_elem = {
|
||||||
"numFattura": num_fattura,
|
"numFattura": num_fattura,
|
||||||
"tipoFattura": tipo_fattura,
|
"tipoFattura": tipo_fattura,
|
||||||
"rifFattura": rif_fattura,
|
"rifFattura": fattura.get('protocollo_fatturatestata1'),
|
||||||
"dataFattura": data_fattura,
|
"dataFattura": datetime.datetime.fromisoformat(fattura.get('data_fatturatestata')).strftime("%d%m%Y"),
|
||||||
"ragioneSociale": ragione_sociale,
|
"ragioneSociale": unidecode.unidecode(fattura.get('cognome_cliente') + ' ' + ' '.join(fattura.get('nome_cliente').split(' ')[0:2])),
|
||||||
"posDivide": pos_divide,
|
"posDivide": str(len(fattura.get('cognome_cliente')) + 1),
|
||||||
"cf": cf_piva,
|
"cf": fattura.get('cf_piva_cliente'),
|
||||||
"importoTotale": importo_totale,
|
"importoTotale": importo_totale,
|
||||||
"ritenutaAcconto": ritenuta_acconto,
|
"ritenutaAcconto": ritenuta_acconto,
|
||||||
"righe": righe,
|
"righe": righe,
|
||||||
|
@@ -14,10 +14,10 @@ def convert(fatture, out_file_path):
|
|||||||
print("Errore: il documento " + fattura["numFattura"] + " non ha cf/piva")
|
print("Errore: il documento " + fattura["numFattura"] + " non ha cf/piva")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if fattura["tipoFattura"] == "Nota di credito":
|
""" if fattura["tipoFattura"] == "Nota di credito":
|
||||||
# As for now this script doesn't handle "Note di credito"
|
# As for now this script doesn't handle "Note di credito"
|
||||||
print(fattura["numFattura"])
|
print(fattura["numFattura"])
|
||||||
continue
|
continue """
|
||||||
|
|
||||||
linea = ["04103", "3", "0", "00000"] # TRF-DITTA + TRF-VERSIONE + TRF-TARC + TRF-COD-CLIFOR
|
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
|
linea.append(fattura["ragioneSociale"][:32]+' '*(32-len(fattura["ragioneSociale"]))) # TRF-RASO
|
||||||
@@ -59,6 +59,10 @@ def convert(fatture, out_file_path):
|
|||||||
for desc, imponibile in fattura["righe"].items():
|
for desc, imponibile in fattura["righe"].items():
|
||||||
conta += 1
|
conta += 1
|
||||||
imponibile = str(imponibile)
|
imponibile = str(imponibile)
|
||||||
|
if '-' in imponibile:
|
||||||
|
imponibile.replace('-', '')
|
||||||
|
imponibile = '0'*(11-len(imponibile)) + imponibile + "-"
|
||||||
|
else:
|
||||||
imponibile = '0'*(11-len(imponibile)) + imponibile + "+"
|
imponibile = '0'*(11-len(imponibile)) + imponibile + "+"
|
||||||
linea.append(imponibile) # TRF-IMPONIB
|
linea.append(imponibile) # TRF-IMPONIB
|
||||||
if desc != "Bollo":
|
if desc != "Bollo":
|
||||||
@@ -71,6 +75,10 @@ def convert(fatture, out_file_path):
|
|||||||
linea.append('0'*31)
|
linea.append('0'*31)
|
||||||
|
|
||||||
totale = str(fattura["importoTotale"])
|
totale = str(fattura["importoTotale"])
|
||||||
|
if '-' in totale:
|
||||||
|
totale.replace('-', '')
|
||||||
|
totale = '0'*(11-len(totale)) + totale + "-"
|
||||||
|
else:
|
||||||
totale = '0'*(11-len(totale)) + totale + "+"
|
totale = '0'*(11-len(totale)) + totale + "+"
|
||||||
linea.append(totale) # TRF-TOT-FAT
|
linea.append(totale) # TRF-TOT-FAT
|
||||||
|
|
||||||
@@ -78,6 +86,10 @@ def convert(fatture, out_file_path):
|
|||||||
for desc, imponibile in fattura["righe"].items():
|
for desc, imponibile in fattura["righe"].items():
|
||||||
conta += 1
|
conta += 1
|
||||||
imponibile = str(imponibile)
|
imponibile = str(imponibile)
|
||||||
|
if '-' in imponibile:
|
||||||
|
imponibile.replace('-', '')
|
||||||
|
imponibile = '0'*(11-len(imponibile)) + imponibile + "-"
|
||||||
|
else:
|
||||||
imponibile = '0'*(11-len(imponibile)) + imponibile + "+"
|
imponibile = '0'*(11-len(imponibile)) + imponibile + "+"
|
||||||
if desc != "Bollo":
|
if desc != "Bollo":
|
||||||
linea.append('4004300') # TRF-CONTO-RIC
|
linea.append('4004300') # TRF-CONTO-RIC
|
||||||
@@ -151,7 +163,10 @@ 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'*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
|
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
|
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('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(' ' + '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((' ' + ' ' + ' ')*49) # TRF-A21CO-TIPO + TRF-A21CO-TIPO-SPESA + TRF-A21CO-FLAG-SPESA
|
||||||
|
Reference in New Issue
Block a user