-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathejemplos-factura-impuestos-locales-valores.py
More file actions
350 lines (320 loc) · 14.5 KB
/
ejemplos-factura-impuestos-locales-valores.py
File metadata and controls
350 lines (320 loc) · 14.5 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
"""
Ejemplos de Factura con Impuestos Locales usando el SDK de FiscalAPI para Python.
Este archivo contiene ejemplos de facturas con impuestos locales (por valores):
1. Impuestos Locales CEDULAR + ISH (ambos)
2. Impuestos Locales solo CEDULAR
3. Impuestos Locales solo ISH
Modo de operacion: Por Valores (todos los datos inline)
"""
from datetime import datetime
from decimal import Decimal
from fiscalapi.models.common_models import FiscalApiSettings
from fiscalapi.models.fiscalapi_models import (
Invoice,
InvoiceItem,
InvoiceIssuer,
InvoiceRecipient,
InvoiceComplement,
ItemTax,
TaxCredential,
LocalTax,
LocalTaxesComplement
)
from fiscalapi.services.fiscalapi_client import FiscalApiClient
# ============================================================================
# CONFIGURACION
# ============================================================================
# Configuracion del cliente
settings = FiscalApiSettings(
# api_url="https://test.fiscalapi.com",
# api_key="<API_KEY>",
# tenant="<TENANT_KEY>"
)
client = FiscalApiClient(settings=settings)
# Certificados en base64 para ESCUELA KEMPER URGATE
escuela_kemper_urgate_base64_cer = "MIIFsDCCA5igAwIBAgIUMzAwMDEwMDAwMDA1MDAwMDM0MTYwDQYJKoZIhvcNAQELBQAwggErMQ8wDQYDVQQDDAZBQyBVQVQxLjAsBgNVBAoMJVNFUlZJQ0lPIERFIEFETUlOSVNUUkFDSU9OIFRSSUJVVEFSSUExGjAYBgNVBAsMEVNBVC1JRVMgQXV0aG9yaXR5MSgwJgYJKoZIhvcNAQkBFhlvc2Nhci5tYXJ0aW5lekBzYXQuZ29iLm14MR0wGwYDVQQJDBQzcmEgY2VycmFkYSBkZSBjYWxpejEOMAwGA1UEEQwFMDYzNzAxCzAJBgNVBAYTAk1YMRkwFwYDVQQIDBBDSVVEQUQgREUgTUVYSUNPMREwDwYDVQQHDAhDT1lPQUNBTjERMA8GA1UELRMIMi41LjQuNDUxJTAjBgkqhkiG9w0BCQITFnJlc3BvbnNhYmxlOiBBQ0RNQS1TQVQwHhcNMjMwNTE4MTE0MzUxWhcNMjcwNTE4MTE0MzUxWjCB1zEnMCUGA1UEAxMeRVNDVUVMQSBLRU1QRVIgVVJHQVRFIFNBIERFIENWMScwJQYDVQQpEx5FU0NVRUxBIEtFTVBFUiBVUkdBVEUgU0EgREUgQ1YxJzAlBgNVBAoTHkVTQ1VFTEEgS0VNUEVSIFVSR0FURSBTQSBERSBDVjElMCMGA1UELRMcRUtVOTAwMzE3M0M5IC8gVkFEQTgwMDkyN0RKM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dn8oDsHKZkWh3pPC2J/nVl0k/yF1KDVowVtMDXE47k6TGVcBoqe8PDXCG9+vjRpzIidqNo5qebaUZu6riWMWzldz8x3Z/jLWXuDiM7/Yscn0Z2GIlfoeyz+GwP2eTdOw9EUedHjEQuJY32bq8LICimJ4Ht+zMJKUyhwVQyAER8byzQBwTYmYP5U0wdsyIFitphw+/IH8+v08Ia1iBLPQAeAvRfTTIFLCs8foyUrj5Zv2B/wTYIZy6ioUM+qADeXyo45uBLLqkN90Rf6kiTqDld78NxwsfyR5MxtJLVDFkmf2IMMJHTqSfhbi+7QJaC11OOUJTD0v9wo0X/oO5GvZhe0ZaGHnm9zqTopALuFEAxcaQlc4R81wjC4wrIrqWnbcl2dxiBtD73KW+wcC9ymsLf4I8BEmiN25lx/OUc1IHNyXZJYSFkEfaxCEZWKcnbiyf5sqFSSlEqZLc4lUPJFAoP6s1FHVcyO0odWqdadhRZLZC9RCzQgPlMRtji/OXy5phh7diOBZv5UYp5nb+MZ2NAB/eFXm2JLguxjvEstuvTDmZDUb6Uqv++RdhO5gvKf/AcwU38ifaHQ9uvRuDocYwVxZS2nr9rOwZ8nAh+P2o4e0tEXjxFKQGhxXYkn75H3hhfnFYjik/2qunHBBZfcdG148MaNP6DjX33M238T9Zw/GyGx00JMogr2pdP4JAErv9a5yt4YR41KGf8guSOUbOXVARw6+ybh7+meb7w4BeTlj3aZkv8tVGdfIt3lrwVnlbzhLjeQY6PplKp3/a5Kr5yM0T4wJoKQQ6v3vSNmrhpbuAtKxpMILe8CQoo="
password = "12345678a"
def get_invoice_items():
"""
Retorna los items de ejemplo para las facturas con impuestos locales.
"""
return [
InvoiceItem(
item_code="01010101",
quantity=Decimal("9.5"),
unit_of_measurement_code="E48",
unit_of_measurement="Unidad de servicio",
description="Invoicing software as a service",
unit_price=Decimal("3587.75"),
tax_object_code="02",
item_sku="7506022301697",
discount=Decimal("255.85"),
item_taxes=[
ItemTax(
tax_code="002",
tax_type_code="Tasa",
tax_rate=Decimal("0.160000"),
tax_flag_code="T"
)
]
),
InvoiceItem(
item_code="01010101",
quantity=Decimal("8"),
unit_of_measurement_code="E48",
unit_of_measurement="Unidad de servicio2",
description="Software Consultant",
unit_price=Decimal("250.85"),
tax_object_code="02",
item_sku="7506022301698",
discount=Decimal("255.85"),
item_taxes=[
ItemTax(
tax_code="002",
tax_type_code="Tasa",
tax_rate=Decimal("0.160000"),
tax_flag_code="T"
)
]
),
InvoiceItem(
item_code="01010101",
quantity=Decimal("6"),
unit_of_measurement_code="E48",
unit_of_measurement="Unidad de servicio3",
description="Computer software",
unit_price=Decimal("1250.75"),
tax_object_code="02",
item_sku="7506022301699",
item_taxes=[
ItemTax(
tax_code="002",
tax_type_code="Tasa",
tax_rate=Decimal("0.160000"),
tax_flag_code="T"
),
ItemTax(
tax_code="002",
tax_type_code="Tasa",
tax_rate=Decimal("0.106666"),
tax_flag_code="R"
)
]
)
]
# ============================================================================
# 1. IMPUESTOS LOCALES CEDULAR + ISH (Por Valores)
# ============================================================================
def create_impuestos_locales_cedular_ish_valores():
"""
Crea una factura con impuestos locales CEDULAR e ISH por valores.
Incluye todos los datos del emisor, receptor y certificados inline.
"""
print("\n" + "="*60)
print("1. IMPUESTOS LOCALES CEDULAR + ISH (Por Valores)")
print("="*60)
invoice = Invoice(
version_code="4.0",
series="F",
date=datetime.now().strftime("%Y-%m-%dT%H:%M:%S"),
payment_form_code="01",
currency_code="MXN",
type_code="I",
expedition_zip_code="42501",
payment_method_code="PUE",
exchange_rate=1,
export_code="01",
issuer=InvoiceIssuer(
tin="EKU9003173C9",
legal_name="ESCUELA KEMPER URGATE",
tax_regime_code="601",
tax_credentials=[
TaxCredential(
base64_file=escuela_kemper_urgate_base64_cer,
file_type=0,
password=password
),
TaxCredential(
base64_file=escuela_kemper_urgate_base64_key,
file_type=1,
password=password
)
]
),
recipient=InvoiceRecipient(
tin="EKU9003173C9",
legal_name="ESCUELA KEMPER URGATE",
zip_code="42501",
tax_regime_code="601",
cfdi_use_code="G01",
email="someone@somewhere.com"
),
items=get_invoice_items(),
complement=InvoiceComplement(
local_taxes=LocalTaxesComplement(
taxes=[
LocalTax(
tax_name="CEDULAR",
tax_rate=Decimal("3.00"),
tax_amount=Decimal("6.00"),
tax_flag_code="R"
),
LocalTax(
tax_name="ISH",
tax_rate=Decimal("8.00"),
tax_amount=Decimal("16.00"),
tax_flag_code="R"
)
]
)
)
)
api_response = client.invoices.create(invoice)
print(f"Response: {api_response}")
return api_response
# ============================================================================
# 2. IMPUESTOS LOCALES SOLO CEDULAR (Por Valores)
# ============================================================================
def create_impuestos_locales_cedular_valores():
"""
Crea una factura con impuesto local CEDULAR por valores.
Incluye todos los datos del emisor, receptor y certificados inline.
"""
print("\n" + "="*60)
print("2. IMPUESTOS LOCALES SOLO CEDULAR (Por Valores)")
print("="*60)
invoice = Invoice(
version_code="4.0",
series="F",
date=datetime.now().strftime("%Y-%m-%dT%H:%M:%S"),
payment_form_code="01",
currency_code="MXN",
type_code="I",
expedition_zip_code="42501",
payment_method_code="PUE",
exchange_rate=1,
export_code="01",
issuer=InvoiceIssuer(
tin="EKU9003173C9",
legal_name="ESCUELA KEMPER URGATE",
tax_regime_code="601",
tax_credentials=[
TaxCredential(
base64_file=escuela_kemper_urgate_base64_cer,
file_type=0,
password=password
),
TaxCredential(
base64_file=escuela_kemper_urgate_base64_key,
file_type=1,
password=password
)
]
),
recipient=InvoiceRecipient(
tin="EKU9003173C9",
legal_name="ESCUELA KEMPER URGATE",
zip_code="42501",
tax_regime_code="601",
cfdi_use_code="G01",
email="someone@somewhere.com"
),
items=get_invoice_items(),
complement=InvoiceComplement(
local_taxes=LocalTaxesComplement(
taxes=[
LocalTax(
tax_name="CEDULAR",
tax_rate=Decimal("3.00"),
tax_amount=Decimal("6.00"),
tax_flag_code="R"
)
]
)
)
)
api_response = client.invoices.create(invoice)
print(f"Response: {api_response}")
return api_response
# ============================================================================
# 3. IMPUESTOS LOCALES SOLO ISH (Por Valores)
# ============================================================================
def create_impuestos_locales_ish_valores():
"""
Crea una factura con impuesto local ISH por valores.
Incluye todos los datos del emisor, receptor y certificados inline.
"""
print("\n" + "="*60)
print("3. IMPUESTOS LOCALES SOLO ISH (Por Valores)")
print("="*60)
invoice = Invoice(
version_code="4.0",
series="F",
date=datetime.now().strftime("%Y-%m-%dT%H:%M:%S"),
payment_form_code="01",
currency_code="MXN",
type_code="I",
expedition_zip_code="42501",
payment_method_code="PUE",
exchange_rate=1,
export_code="01",
issuer=InvoiceIssuer(
tin="EKU9003173C9",
legal_name="ESCUELA KEMPER URGATE",
tax_regime_code="601",
tax_credentials=[
TaxCredential(
base64_file=escuela_kemper_urgate_base64_cer,
file_type=0,
password=password
),
TaxCredential(
base64_file=escuela_kemper_urgate_base64_key,
file_type=1,
password=password
)
]
),
recipient=InvoiceRecipient(
tin="EKU9003173C9",
legal_name="ESCUELA KEMPER URGATE",
zip_code="42501",
tax_regime_code="601",
cfdi_use_code="G01",
email="someone@somewhere.com"
),
items=get_invoice_items(),
complement=InvoiceComplement(
local_taxes=LocalTaxesComplement(
taxes=[
LocalTax(
tax_name="ISH",
tax_rate=Decimal("8.00"),
tax_amount=Decimal("16.00"),
tax_flag_code="R"
)
]
)
)
)
api_response = client.invoices.create(invoice)
print(f"Response: {api_response}")
return api_response
# ============================================================================
# FUNCION PRINCIPAL
# ============================================================================
def main():
"""
Funcion principal que ejecuta los ejemplos de factura con impuestos locales por valores.
Descomenta las funciones que desees ejecutar.
"""
# 1. Impuestos locales CEDULAR + ISH
# create_impuestos_locales_cedular_ish_valores()
# 2. Impuestos locales solo CEDULAR
# create_impuestos_locales_cedular_valores()
# 3. Impuestos locales solo ISH
# create_impuestos_locales_ish_valores()
pass
if __name__ == "__main__":
main()