-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_read_xml.py
137 lines (123 loc) · 4.64 KB
/
simple_read_xml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from xml.dom import minidom
def get_comprobante(doc):
nodoComprobante = doc.getElementsByTagName("cfdi:Comprobante")
element = {
"lugarExpedicion": nodoComprobante[0].getAttribute("LugarExpedicion"),
"total": nodoComprobante[0].getAttribute("total"),
"descuento": nodoComprobante[0].getAttribute("descuento"),
"noCertificado": nodoComprobante[0].getAttribute("noCertificado"),
"fecha": nodoComprobante[0].getAttribute("fecha"),
"folio": nodoComprobante[0].getAttribute("folio"),
"serie": nodoComprobante[0].getAttribute("serie"),
}
return element
def get_emisor(doc):
nodoEmisor = doc.getElementsByTagName("cfdi:Emisor")
nodoDomicilioFiscal = doc.getElementsByTagName("cfdi:DomicilioFiscal")
element = {
"rfc": nodoEmisor[0].getAttribute("rfc"),
"nombre": nodoEmisor[0].getAttribute("nombre"),
"calle" : nodoDomicilioFiscal[0].getAttribute("calle"),
"noExterior": nodoDomicilioFiscal[0].getAttribute("noExterior"),
"noInterior": nodoDomicilioFiscal[0].getAttribute("noInterior"),
"colonia": nodoDomicilioFiscal[0].getAttribute("colonia"),
"municipio": nodoDomicilioFiscal[0].getAttribute("municipio"),
"estado": nodoDomicilioFiscal[0].getAttribute("estado"),
"pais": nodoDomicilioFiscal[0].getAttribute("pais"),
"codigoPostal": nodoDomicilioFiscal[0].getAttribute("codigoPostal"),
}
return element
def get_receptor(doc):
nodoReceptor = doc.getElementsByTagName("cfdi:Receptor")
element = {
"rfc": nodoReceptor[0].getAttribute("rfc"),
"nombre": nodoReceptor[0].getAttribute("nombre"),
}
return element
def get_nomina(doc):
nodoNomina = doc.getElementsByTagName("nomina:Nomina")
element = {
"salarioBaseCotApor": nodoNomina[0].getAttribute("SalarioBaseCotApor"),
"periodicidadPago": nodoNomina[0].getAttribute("PeriodicidadPago"),
"tipoJornada": nodoNomina[0].getAttribute("TipoJornada"),
"puesto": nodoNomina[0].getAttribute("Puesto"),
"antiguedad": nodoNomina[0].getAttribute("Antiguedad"),
"fechaInicioRelLaboral": nodoNomina[0].getAttribute("FechaInicioRelLaboral"),
"departamento": nodoNomina[0].getAttribute("Departamento"),
"numDiasPagados": nodoNomina[0].getAttribute("NumDiasPagados"),
"fechaFinalPago": nodoNomina[0].getAttribute("FechaFinalPago"),
"fechaInicialPago": nodoNomina[0].getAttribute("FechaInicialPago"),
"fechaPago": nodoNomina[0].getAttribute("FechaPago"),
"numSeguridadSocial": nodoNomina[0].getAttribute("NumSeguridadSocial"),
"curp": nodoNomina[0].getAttribute("CURP"),
"numEmpleado": nodoNomina[0].getAttribute("NumEmpleado"),
}
return element
def get_percepciones(doc):
nodoPercepciones = doc.getElementsByTagName("nomina:Percepciones")
element = {
"totalGravado": nodoPercepciones[0].getAttribute("TotalGravado"),
"totalExento": nodoPercepciones[0].getAttribute("TotalExento"),
}
return element
def get_percepcion(doc):
nodos = doc.getElementsByTagName("nomina:Percepcion")
lisPer = []
for nodo in nodos:
element = {
"clave": nodo.getAttribute("Clave"),
"tipoPercepcion": nodo.getAttribute("TipoPercepcion"),
"concepto": nodo.getAttribute("Concepto"),
"importeGravado": nodo.getAttribute("ImporteGravado"),
"importeExento": nodo.getAttribute("ImporteExento"),
}
lisPer.append(element)
return lisPer
def get_deducciones(doc):
nodoDeducciones = doc.getElementsByTagName("nomina:Deducciones")
element = {
"totalGravado": nodoDeducciones[0].getAttribute("TotalGravado"),
"totalExento": nodoDeducciones[0].getAttribute("TotalExento"),
}
return element
def get_deduccion(doc):
nodos = doc.getElementsByTagName("nomina:Deduccion")
lisDed = []
for nodo in nodos:
element = {
"clave": nodo.getAttribute("Clave"),
"tipoPercepcion": nodo.getAttribute("TipoDeduccion"),
"concepto": nodo.getAttribute("Concepto"),
"importeGravado": nodo.getAttribute("ImporteGravado"),
"importeExento": nodo.getAttribute("ImporteExento"),
}
lisDed.append(element)
return lisDed
def get_horas_extra(doc):
nodos = doc.getElementsByTagName("nomina:HorasExtra")
lisHrs = []
for nodo in nodos:
element = {
"dias": nodo.getAttribute("Dias"),
"tipoHoras": nodo.getAttribute("TipoHoras"),
"horasExtra": nodo.getAttribute("HorasExtra"),
"importePagado": nodo.getAttribute("ImportePagado"),
}
lisHrs.append(lisHrs)
return lisHrs
def get_xml_data(path=None):
doc = minidom.parse(path)
data = {
"comprobante": get_comprobante(doc),
"emisor": get_emisor(doc),
"receptor": get_receptor(doc),
"nomina": get_nomina(doc),
"percepciones": get_percepciones(doc),
"percepcion": get_percepcion(doc),
"deduciones": get_deducciones(doc),
"deducion": get_deduccion(doc),
"horasExtra": get_horas_extra(doc),
}
return data
#call funtion
print(get_xml_data("CFDI_v11.xml"))