-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathejemplos-facturas-de-complemento-pago.py
More file actions
252 lines (230 loc) · 11.9 KB
/
ejemplos-facturas-de-complemento-pago.py
File metadata and controls
252 lines (230 loc) · 11.9 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
"""
Ejemplos de Factura de Complemento de Pago usando el SDK de FiscalAPI para Python.
Este archivo contiene ejemplos de diferentes tipos de facturas de complemento de pago:
1. Complemento de Pago por Valores (todos los datos inline)
2. Complemento de Pago por Referencias (usando IDs de emisor y receptor)
"""
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,
PaymentComplement,
PaidInvoice,
PaidInvoiceTax,
TaxCredential
)
from fiscalapi.services.fiscalapi_client import FiscalApiClient
# Configuracion del cliente
settings = FiscalApiSettings(
# api_url="https://test.fiscalapi.com",
# api_key="<API_KEY>",
# tenant="<TENANT_KEY>",
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pSz7/g5Jwp8+y8Ck5YP7AX0R/dVA0t37DO7nAbQT5XVSYpMVh/yvpYJ9WR+tb8Yg1h2lERLR2fbuhQRcwmisZR2W3Sr2b7hX9MCMkMQw8y2fDJrzLrqKqkHcjvnI/TdzZW2MzeQDoBBb3fmgvjYg07l4kThS73wGX992w2Y+a1A2iirSmrYEm9dSh16JmXa8boGQAONQzQkHh7vpw0IBs9cnvqO1QLB1GtbBztUBXonA4TxMKLYZkVrrd2RhrYWMsDp7MpC4M0p/DA3E/qscYwq1OpwriewNdx6XXqMZbdUNqMP2viBY2VSGmNdHtVfbN/rnaeJetFGX7XgTVYD7wDq8TW9yseCK944jcT+y/o0YiT9j3OLQ2Ts0LDTQskpJSxRmXEQGy3NBDOYFTvRkcGJEQJItuol8NivJN1H9LoLIUAlAHBZxfHpUYx66YnP4PdTdMIWH+nxyekKPFfAT7olQ="
password = "12345678a"
# ============================================================================
# 1. COMPLEMENTO DE PAGO POR VALORES
# ============================================================================
def create_complemento_pago_valores():
"""
Crea una factura de complemento de pago (factura de pago) por valores.
Incluye todos los datos del emisor, receptor y certificados inline.
"""
print("\n" + "="*60)
print("1. COMPLEMENTO DE PAGO POR VALORES")
print("="*60)
payment_invoice = Invoice(
version_code="4.0",
series="CP",
date=datetime.now().strftime("%Y-%m-%dT%H:%M:%S"),
currency_code="XXX",
type_code="P",
expedition_zip_code="01160",
exchange_rate=1,
export_code="01",
issuer=InvoiceIssuer(
tin="FUNK671228PH6",
legal_name="KARLA FUENTE NOLASCO",
tax_regime_code="621",
tax_credentials=[
TaxCredential(
base64_file=karla_fuente_nolasco_base64_cer,
file_type=0,
password=password
),
TaxCredential(
base64_file=karla_fuente_nolasco_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="CP01",
email="mail@domain.com",
),
items=[
InvoiceItem(
item_code="84111506",
quantity=1,
unit_of_measurement_code="ACT",
description="Pago",
unit_price=0,
tax_object_code="01"
)
],
complement=InvoiceComplement(
payment=PaymentComplement(
payment_date=datetime.now().strftime("%Y-%m-%dT%H:%M:%S"),
payment_form_code="28",
currency_code="MXN",
exchange_rate=Decimal("1"),
amount=Decimal("11600.00"),
source_bank_tin="BSM970519DU8",
source_bank_account="1234567891012131",
target_bank_tin="BBA830831LJ2",
target_bank_account="1234567890",
paid_invoices=[
PaidInvoice(
uuid="5C7B0622-01B4-4EB8-96D0-E0DEBD89FF0F",
series="F",
number="123",
currency_code="MXN",
partiality_number=1,
sub_total=Decimal("10000.00"),
previous_balance=Decimal("11600.00"),
payment_amount=Decimal("11600.00"),
remaining_balance=Decimal("0"),
tax_object_code="02",
paid_invoice_taxes=[
PaidInvoiceTax(
tax_code="002",
tax_type_code="Tasa",
tax_rate=Decimal("0.160000"),
tax_flag_code="T"
)
]
)
]
)
)
)
api_response = client.invoices.create(payment_invoice)
print(f"Response: {api_response}")
return api_response
# ============================================================================
# 2. COMPLEMENTO DE PAGO POR REFERENCIAS
# ============================================================================
def create_complemento_pago_referencias():
"""
Crea una factura de complemento de pago (factura de pago) por referencias.
Usa IDs de emisor y receptor previamente creados en el sistema.
No incluye conceptos (items) ya que no son necesarios en este modo.
"""
print("\n" + "="*60)
print("2. COMPLEMENTO DE PAGO POR REFERENCIAS")
print("="*60)
payment_invoice = Invoice(
version_code="4.0",
series="CP",
date=datetime.now().strftime("%Y-%m-%dT%H:%M:%S"),
currency_code="XXX",
type_code="P",
expedition_zip_code="01160",
exchange_rate=1,
export_code="01",
issuer=InvoiceIssuer(
id="109f4d94-63ea-4a21-ab15-20c8b87d8ee9"
),
recipient=InvoiceRecipient(
id="2e7b988f-3a2a-4f67-86e9-3f931dd48581"
),
complement=InvoiceComplement(
payment=PaymentComplement(
payment_date=datetime.now().strftime("%Y-%m-%dT%H:%M:%S"),
payment_form_code="28",
currency_code="MXN",
exchange_rate=Decimal("1"),
amount=Decimal("11600.00"),
source_bank_tin="BSM970519DU8",
source_bank_account="1234567891012131",
target_bank_tin="BBA830831LJ2",
target_bank_account="1234567890",
paid_invoices=[
PaidInvoice(
uuid="5C7B0622-01B4-4EB8-96D0-E0DEBD89FF0F",
series="F",
number="123",
currency_code="MXN",
partiality_number=1,
sub_total=Decimal("10000.00"),
previous_balance=Decimal("11600.00"),
payment_amount=Decimal("11600.00"),
remaining_balance=Decimal("0"),
tax_object_code="02",
paid_invoice_taxes=[
PaidInvoiceTax(
tax_code="002",
tax_type_code="Tasa",
tax_rate=Decimal("0.160000"),
tax_flag_code="T"
)
]
)
]
)
)
)
api_response = client.invoices.create(payment_invoice)
print(f"Response: {api_response}")
return api_response
# ============================================================================
# FUNCION PRINCIPAL
# ============================================================================
def main():
"""
Funcion principal que ejecuta todos los ejemplos de factura de complemento de pago.
Descomenta las funciones que desees ejecutar.
"""
print("="*60)
print("EJEMPLOS DE FACTURA DE COMPLEMENTO DE PAGO - FISCALAPI PYTHON SDK")
print("="*60)
# Ejecutar todos los ejemplos uno por uno
examples = [
create_complemento_pago_valores,
create_complemento_pago_referencias,
]
results = []
for example in examples:
try:
response = example()
success = response.succeeded if response else False
results.append((example.__name__, success, None))
except Exception as e:
results.append((example.__name__, False, str(e)))
# Resumen de resultados
print("\n" + "="*60)
print("RESUMEN DE RESULTADOS")
print("="*60)
for name, success, error in results:
status = "OK" if success else "FAILED"
print(f"{name}: {status}")
if error:
print(f" Error: {error}")
print("\n" + "="*60)
print("FIN DE LOS EJEMPLOS")
print("="*60)
if __name__ == "__main__":
main()