spei-python 1.0.3__py3-none-any.whl → 1.0.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- from datetime import datetime
1
+ from datetime import date
2
2
  from decimal import Decimal
3
3
  from typing import Optional, Tuple
4
4
 
@@ -19,12 +19,10 @@ class ChecksumGenerator(object):
19
19
  low = amount_as_cents - (tens_of_millons * 10**9)
20
20
  return high, low
21
21
 
22
- def _fecha_to_bytearray(self, fecha_operacion: int) -> bytearray:
23
- fecha_operacion_dt = datetime.strptime(str(fecha_operacion), '%Y%m%d')
24
-
25
- day = int.to_bytes(int(fecha_operacion_dt.day), 1, 'big')
26
- month = int.to_bytes(int(fecha_operacion_dt.month), 1, 'big')
27
- year = int.to_bytes(int(fecha_operacion_dt.year), 2, 'big')
22
+ def _fecha_to_bytearray(self, fecha_operacion: date) -> bytearray:
23
+ day = int.to_bytes(int(fecha_operacion.day), 1, 'big')
24
+ month = int.to_bytes(int(fecha_operacion.month), 1, 'big')
25
+ year = int.to_bytes(int(fecha_operacion.year), 2, 'big')
28
26
 
29
27
  return bytearray(day + month + year)
30
28
 
spei/resources/cda.py CHANGED
@@ -1,3 +1,4 @@
1
+ from datetime import date, datetime
1
2
  from typing import Optional
2
3
 
3
4
  from lxml import etree
@@ -5,6 +6,7 @@ from pydantic import BaseModel, ConfigDict
5
6
 
6
7
  from spei import types
7
8
  from spei.resources.validators import normalize_invalid_chars
9
+ from spei.types.common import InstitutionCode
8
10
  from spei.utils import to_pascal_case, to_snake_case # noqa: WPS347
9
11
 
10
12
  SOAP_NS = 'http://schemas.xmlsoap.org/soap/envelope/'
@@ -17,8 +19,8 @@ class CDA(BaseModel):
17
19
 
18
20
  id: int
19
21
  mensaje_id: int
20
- op_fecha_oper: DateInt
21
- op_fecha_abono: DateInt
22
+ op_fecha_oper: date
23
+ op_fecha_abono: date
22
24
  op_hora_abono: int
23
25
 
24
26
  op_cve_rastreo: str
@@ -81,7 +83,13 @@ class CDA(BaseModel):
81
83
 
82
84
  for element in datos_cta.getchildren():
83
85
  tag = to_snake_case(element.tag)
84
- if tag in cls.model_fields:
86
+
87
+ if tag not in cls.model_fields:
88
+ continue
89
+
90
+ if tag == 'op_fecha_oper':
91
+ cda_data[tag] = datetime.strptime(element.text, '%d%m%Y').date()
92
+ else:
85
93
  cda_data[tag] = element.text
86
94
 
87
95
  return cls(**cda_data)
@@ -91,18 +99,26 @@ class CDA(BaseModel):
91
99
  etree.QName(ENVIO_PRAXIS_NS, 'datosCda'),
92
100
  idCda=str(self.id),
93
101
  idMensaje=str(self.mensaje_id),
102
+ attrib={},
94
103
  nsmap={'env': ENVIO_PRAXIS_NS},
95
104
  )
96
105
 
97
- elements = self.dict(exclude_none=True, exclude={'id', 'mensaje_id'})
106
+ elements = self.model_dump(exclude_none=True, exclude={'id', 'mensaje_id'})
98
107
 
99
108
  for element, value in elements.items(): # noqa: WPS110
100
- if element in self.__fields__:
101
- pascal_case_element = to_pascal_case(element)
102
- subelement = etree.SubElement(
103
- mensaje,
104
- etree.QName(ENVIO_PRAXIS_NS, pascal_case_element),
105
- )
106
- subelement.text = normalize_invalid_chars(value)
109
+ if element not in self.model_fields:
110
+ continue
111
+
112
+ if 'op_fecha' in element:
113
+ value = value.strftime('%d%m%Y')
114
+
115
+ pascal_case_element = to_pascal_case(element)
116
+ subelement = etree.SubElement(
117
+ mensaje,
118
+ etree.QName(ENVIO_PRAXIS_NS, pascal_case_element),
119
+ attrib={},
120
+ nsmap=None,
121
+ )
122
+ subelement.text = normalize_invalid_chars(value)
107
123
 
108
124
  return mensaje
spei/resources/orden.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import re
2
+ from datetime import date, datetime
2
3
  from typing import Any, Dict, Optional
3
4
 
4
5
  from lxml import etree
@@ -7,6 +8,7 @@ from pydantic import BaseModel, ConfigDict, field_validator
7
8
 
8
9
  from spei import types
9
10
  from spei.resources.validators import normalize_invalid_chars
11
+ from spei.types.common import InstitutionCode
10
12
  from spei.utils import to_camel_case, to_pascal_case, to_snake_case # noqa: WPS347
11
13
 
12
14
  SOAP_NS = 'http://schemas.xmlsoap.org/soap/envelope/'
@@ -28,7 +30,7 @@ class Orden(BaseModel):
28
30
 
29
31
  id: int
30
32
  categoria: types.CategoriaOrdenPago
31
- op_fecha_oper: DateInt
33
+ op_fecha_oper: date
32
34
  op_folio: int
33
35
  op_monto: str
34
36
  op_tp_clave: types.TipoPagoOrdenPago
@@ -85,7 +87,7 @@ class Orden(BaseModel):
85
87
  # original info
86
88
  op_folio_ori: Optional[int] = None
87
89
  paq_folio_ori: Optional[int] = None
88
- op_fecha_oper_ori: Optional[DateInt] = None
90
+ op_fecha_oper_ori: Optional[date] = None
89
91
  op_rastreo_ori: Optional[str] = None
90
92
  op_monto_intereses: Optional[float] = None
91
93
  op_monto_ori: Optional[float] = None
@@ -105,7 +107,7 @@ class Orden(BaseModel):
105
107
  op_cert_comer_env: Optional[int] = None
106
108
  op_digito_ver_comer: Optional[int] = None
107
109
  # karpay system info
108
- op_fecha_cap: Optional[DateInt] = None
110
+ op_fecha_cap: Optional[date] = None
109
111
  op_folio_servidor: Optional[int] = None
110
112
  op_usu_autoriza: Optional[str] = None
111
113
  op_err_clave: Optional[types.CodigoError] = None
@@ -149,52 +151,50 @@ class Orden(BaseModel):
149
151
  nsmap=None,
150
152
  )
151
153
 
152
- elements = self.dict(
154
+ elements = self.model_dump(
153
155
  exclude_none=True,
154
156
  exclude={'id', 'categoria', 'op_ins_clave_ord'},
155
157
  )
156
158
 
157
159
  for element, value in elements.items(): # noqa: WPS110
158
- if element in self.model_fields:
159
- if element == 'op_ins_clave_ben':
160
- subelement = etree.SubElement(
161
- ordenpago,
162
- 'OpInsClave',
163
- attrib={},
164
- nsmap=None,
165
- )
166
- subelement.text = str(value)
167
- continue
168
-
169
- if element == 'op_firma_dig': # Lower case o in op
170
- subelement = etree.SubElement(
171
- ordenpago,
172
- 'opFirmaDig',
173
- attrib={},
174
- nsmap=None,
175
- )
176
- subelement.text = str(value)
177
- continue
178
-
179
- text = normalize_invalid_chars(str(value))
180
-
181
- if element in _CAMEL_CASE_FIELDS:
182
- subelement = etree.SubElement(
183
- ordenpago,
184
- to_camel_case(element),
185
- attrib={},
186
- nsmap=None,
187
- )
188
- subelement.text = text
189
- continue
160
+ if element not in self.model_fields:
161
+ continue
190
162
 
163
+ if element == 'op_ins_clave_ben':
191
164
  subelement = etree.SubElement(
192
165
  ordenpago,
193
- to_pascal_case(element),
166
+ 'OpInsClave',
194
167
  attrib={},
195
168
  nsmap=None,
196
169
  )
197
- subelement.text = text
170
+ subelement.text = str(value)
171
+ continue
172
+
173
+ if element == 'op_firma_dig': # Lower case o in op
174
+ subelement = etree.SubElement(
175
+ ordenpago,
176
+ 'opFirmaDig',
177
+ attrib={},
178
+ nsmap=None,
179
+ )
180
+ subelement.text = str(value)
181
+ continue
182
+
183
+ if 'op_fecha' in element:
184
+ value = value.strftime('%Y%m%d')
185
+
186
+ tag = (
187
+ to_camel_case(element)
188
+ if element in _CAMEL_CASE_FIELDS
189
+ else to_pascal_case(element)
190
+ )
191
+ subelement = etree.SubElement(
192
+ ordenpago,
193
+ tag,
194
+ attrib={},
195
+ nsmap=None,
196
+ )
197
+ subelement.text = normalize_invalid_chars(str(value))
198
198
 
199
199
  return ordenpago
200
200
 
@@ -232,5 +232,11 @@ class Orden(BaseModel):
232
232
  orden_data['op_firma_dig'] = stripped
233
233
  return
234
234
 
235
- if tag in cls.__fields__:
236
- orden_data[tag] = stripped
235
+ if tag not in cls.model_fields:
236
+ return
237
+
238
+ if 'op_fecha' in tag:
239
+ orden_data[tag] = datetime.strptime(stripped, '%Y%m%d').date()
240
+ return
241
+
242
+ orden_data[tag] = stripped
@@ -1,10 +1,10 @@
1
1
  # mypy: disable-error-code="override"
2
2
 
3
+ from datetime import date
3
4
  from typing import Optional
4
5
 
5
6
  from spei import types
6
7
  from spei.resources.orden import Orden
7
- from spei.types.common import DateInt
8
8
 
9
9
 
10
10
  class TerceroATercero(Orden):
@@ -326,7 +326,7 @@ class DevolucionExtemporaneaNoAcreditada(Orden):
326
326
  op_folio_ori: Optional[int] = None
327
327
  paq_folio_ori: Optional[int] = None
328
328
 
329
- op_fecha_oper_ori: DateInt
329
+ op_fecha_oper_ori: date
330
330
  op_rastreo_ori: str
331
331
  op_monto_intereses: float
332
332
  op_monto_ori: float
@@ -345,7 +345,7 @@ class DevolucionExtemporaneaAcreditada(Orden):
345
345
  op_folio_ori: Optional[int] = None
346
346
  paq_folio_ori: Optional[int] = None
347
347
 
348
- op_fecha_oper_ori: DateInt
348
+ op_fecha_oper_ori: date
349
349
  op_rastreo_ori: str
350
350
  op_monto_ori: float
351
351
 
@@ -367,7 +367,7 @@ class DevolucionExtemporaneaEspecialAcreditada(Orden):
367
367
  op_folio_ori: Optional[int] = None
368
368
  paq_folio_ori: Optional[int] = None
369
369
 
370
- op_fecha_oper_ori: DateInt
370
+ op_fecha_oper_ori: date
371
371
  op_rastreo_ori: str
372
372
  op_monto_ori: float
373
373
 
@@ -26,13 +26,20 @@ class Respuesta(BaseModel):
26
26
  model_config = ConfigDict(use_enum_values=True)
27
27
 
28
28
  def build_xml(self):
29
- respuesta = etree.Element('respuesta')
29
+ respuesta = etree.Element('respuesta', attrib={}, nsmap=None)
30
30
 
31
31
  for element, value in self.dict(exclude={'categoria'}).items(): # noqa: WPS110
32
- if element in self.__fields__:
33
- pascal_case_element = to_pascal_case(element)
34
- subelement = etree.SubElement(respuesta, pascal_case_element)
35
- subelement.text = str(value)
32
+ if element not in self.model_fields:
33
+ continue
34
+
35
+ pascal_case_element = to_pascal_case(element)
36
+ subelement = etree.SubElement(
37
+ respuesta,
38
+ pascal_case_element,
39
+ attrib={},
40
+ nsmap=None,
41
+ )
42
+ subelement.text = str(value)
36
43
 
37
44
  return respuesta
38
45
 
spei/types/common.py CHANGED
@@ -6,29 +6,6 @@ from pydantic import BeforeValidator
6
6
  from typing_extensions import Annotated
7
7
 
8
8
 
9
- def validate_date_int(value: int) -> int: # noqa: WPS110
10
- """Validates and converts a date value to YYYYMMDD string format."""
11
- value_str = str(value)
12
- if not re.match(r'^\d{8}$', value_str):
13
- raise ValueError('must be 8 digits in YYYYMMDD format')
14
-
15
- # Additional date validation if needed
16
- year = int(value_str[:4])
17
- month = int(value_str[4:6])
18
- day = int(value_str[6:8])
19
-
20
- if year < 1900: # noqa: WPS432
21
- raise ValueError('invalid year')
22
-
23
- if not (1 <= month <= 12 and 1 <= day <= 31): # noqa: WPS432
24
- raise ValueError('invalid date')
25
-
26
- return int(value_str)
27
-
28
-
29
- DateInt = Annotated[int, BeforeValidator(validate_date_int)]
30
-
31
-
32
9
  def validate_institution_code(value: Union[str, int]) -> int:
33
10
  """Validates and converts an institution code to a 3 or 5-digit integer."""
34
11
  value_str = str(value)
@@ -1,13 +1,11 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: spei-python
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Summary:
5
5
  Author: tech
6
6
  Author-email: tech@fondeadora.com
7
- Requires-Python: >=3.8.1,<4.0
7
+ Requires-Python: >=3.11,<4.0
8
8
  Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.9
10
- Classifier: Programming Language :: Python :: 3.10
11
9
  Classifier: Programming Language :: Python :: 3.11
12
10
  Classifier: Programming Language :: Python :: 3.12
13
11
  Classifier: Programming Language :: Python :: 3.13
@@ -3,7 +3,7 @@ spei/__init__.py,sha256=T8DMjAToKpTIuUcnzfGpOEgEzAZ8LuRWABeJoClc2zg,149
3
3
  spei/cep_generator.py,sha256=NH96gb6j1DQM5dZKgTGY2bVAOV4tj5tZ2CVFS4lawpc,2808
4
4
  spei/checksum/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  spei/checksum/factory.py,sha256=wDZGjHYlcyQhsRSwYp87rNc7bL9eUNjRJu3-XvNhD2s,2092
6
- spei/checksum/generator.py,sha256=LWD-5DyBrx5K7n6Sqsj3DGc5TCm85uoXyzuagZZHsdk,7921
6
+ spei/checksum/generator.py,sha256=Z1i2qPigdBsQg59HIpgQvzgPReEaAGyDmwqi1Fieg-o,7829
7
7
  spei/checksum/types.py,sha256=7pvxGCB3IBHe9-bE_UnJQF1TfLtTDHchU4leLui32qI,1912
8
8
  spei/client.py,sha256=nbbLGQiLYSBbSmJDHkZedpUzzvQyFQVaA7gtnI3m7Q0,3245
9
9
  spei/errors/__init__.py,sha256=NwsojpHB6dvHlwfBe_UaI0LciojLERLyPAoe25DNTB4,153
@@ -18,12 +18,12 @@ spei/requests/orden.py,sha256=TIkTDr1pVvJ4TOX6hUXQhUparOOAVAJY_zv_bxPrxvU,1602
18
18
  spei/requests/respuesta.py,sha256=oH0EU4qJ7cPmYjMg5v_UBbZMf6ZdrXA7sZY7fOMtzs8,1724
19
19
  spei/resources/__init__.py,sha256=cJL9KI0ZBKHcDN5me8yuvschQMW1HH_bpLS7TnLXZw4,487
20
20
  spei/resources/acuse.py,sha256=JfX05461ryOUbFwU3Jps2AoiC4yFKv3p2GouVTyEHS8,5566
21
- spei/resources/cda.py,sha256=EyGZjY7udqVpmHpZU-D6D88PZNRg-Fq5QX_uWFLhazI,3345
21
+ spei/resources/cda.py,sha256=8VDV0CgfLOqhoRFqdc9NSyzk9TGIfDcS5rI2AtbQ_7M,3770
22
22
  spei/resources/ensesion.py,sha256=0kxyW-lFHilELYv-9PSVjkG1mp-gOSSC206501KlwSE,1587
23
23
  spei/resources/mensaje.py,sha256=5vb_kD2l_QILTAPmlG1u33H3nJLD5KDpPw0_PRfY6GM,1783
24
- spei/resources/orden.py,sha256=H45mY-weaug1NHRxnHspKU9VDwxBGDRK3LW5mnT3ItE,8246
25
- spei/resources/payments.py,sha256=0m9o9A3TQkO8KPNPQWcaje_6yQWcPqTk4b7-MzQhVh4,8930
26
- spei/resources/respuesta.py,sha256=_9RHKNHAKRnbzxIoI5Prymgxt2KOg6mkoYIyBU41gao,1636
24
+ spei/resources/orden.py,sha256=b3k7huxqAucS_tdaQ0XItkia1XuoW18eMiD9T6XiFmw,8258
25
+ spei/resources/payments.py,sha256=-6fWn-hbwQapLgsnZ-C41za4YskiC3OVnp8sq8fdLaM,8909
26
+ spei/resources/respuesta.py,sha256=b_BtIZs52Ki-0YWinVHNWUAfVaFxq8be1iiYFg1VN5I,1781
27
27
  spei/resources/validators.py,sha256=jvX8lfCaHQg0WBoKSnig7_t8tX--Ab5GaiCbg3IvBs8,2925
28
28
  spei/responses/__init__.py,sha256=WxHb0KJ1sI5m6iLfxtf3h8MnqubQlxdtiaarXJvZdkM,247
29
29
  spei/responses/acuse.py,sha256=ZGfP45XYvDSDbgfSKWeraDpFApDc0oks05_tQH-bwzM,650
@@ -31,10 +31,10 @@ spei/responses/orden.py,sha256=a-GE62-OBWVNpW2RuVKgNqWnY2cNy88shUDLQAL21dU,1068
31
31
  spei/responses/respuesta.py,sha256=cKK-46AimKEdqmMLOO1syGUWuBldnWFdAVNcsubpn6I,2162
32
32
  spei/sice.py,sha256=liqzUZ4ClIgFefi8M-7uoyOcoKZvhPpUWHH88T9xwlc,1667
33
33
  spei/types/__init__.py,sha256=U_4HiFBZ5rsaV5UkD60YArQhaENj_sh1HBGAeuI7ytA,686
34
- spei/types/common.py,sha256=4nn_ITxSUelAcryk9s68cMv40IXdyJ3HezQwTdF6nGg,1231
34
+ spei/types/common.py,sha256=TfqIOXH1UbNA0nplji521LFiWR76l2quv-RaUj542OY,551
35
35
  spei/types/sice.py,sha256=xFSoiLklRNWXoWwZXpSN8-SdkliNK23_MZbhcOc7a9s,222
36
36
  spei/types/spei.py,sha256=GX3jbGe9B_1_TYNguYfA0TkPLQiwTOB-91SR0lQisJ0,4678
37
37
  spei/utils.py,sha256=DtJAWf3tUvjRFC2G-L3ylm7ogBGwugNaBZtJI52jDME,455
38
- spei_python-1.0.3.dist-info/METADATA,sha256=I1uEtd5qSZAnlH4RUVim2GizMNFOC6nZ1PNovyeUaaI,3953
39
- spei_python-1.0.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
40
- spei_python-1.0.3.dist-info/RECORD,,
38
+ spei_python-1.0.4.dist-info/METADATA,sha256=A9F7kjfboqVOwIbDgC8OhJnPrbsuU_12XrF_o8dhGqY,3851
39
+ spei_python-1.0.4.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
40
+ spei_python-1.0.4.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.1
2
+ Generator: poetry-core 2.1.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any