Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.76.0
current_version = 0.77.0
commit = True
tag = False
message = chore: Bump version from {current_version} to {new_version}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
run: make python-virtualenv PYTHON_VIRTUALENV_DIR="venv"

- name: Restoring/Saving Cache
uses: actions/cache@v5.0.4
uses: actions/cache@v5.0.5
with:
path: |
.tox
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
check-latest: true

- name: Restoring/Saving Cache
uses: actions/cache@v5.0.4
uses: actions/cache@v5.0.5
with:
path: |
.tox
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:

- name: Store Artifacts
if: ${{ always() }}
uses: actions/upload-artifact@v7.0.0
uses: actions/upload-artifact@v7.0.1
with:
name: test_reports_${{ matrix.python_version }}
path: test-reports/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
check-latest: true

- name: Restoring/Saving Cache
uses: actions/cache@v5.0.4
uses: actions/cache@v5.0.5
with:
path: "venv"
key: py-v1-deps-${{ runner.os }}-${{ steps.set_up_python.outputs.python-version }}-${{ hashFiles('pyproject.toml', 'requirements.txt', 'requirements-dev.txt', 'Makefile', 'make/**.mk') }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: make python-virtualenv PYTHON_VIRTUALENV_DIR="venv"

- name: Restoring/Saving Cache
uses: actions/cache@v5.0.4
uses: actions/cache@v5.0.5
with:
path: "venv"
key: py-v1-deps-${{ runner.os }}-${{ steps.set_up_python.outputs.python-version }}-${{ hashFiles('pyproject.toml', 'requirements.txt', 'requirements-dev.txt', 'Makefile', 'make/**.mk') }}
Expand All @@ -69,7 +69,7 @@ jobs:
make dist

- name: Store Artifacts
uses: actions/upload-artifact@v7.0.0
uses: actions/upload-artifact@v7.0.1
with:
name: release
path: ${{ env.ARTIFACTS_PATH }}/
Expand Down
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# History

## 0.77.0 (2026-05-28)

- (PR #1030, 2026-05-11) chore(deps): Bump the github-actions-production group with 2 updates
- (PR #1036, 2026-05-28) rcv: Enhance parsing and validation for DocumentoReferencias

## 0.76.0 (2026-05-04)

- (PR #1029, 2026-04-29) Drop support for Python 3.9
Expand Down
2 changes: 1 addition & 1 deletion src/cl_sii/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

"""

__version__ = '0.76.0'
__version__ = '0.77.0'
46 changes: 37 additions & 9 deletions src/cl_sii/rcv/data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,45 @@ class OtrosImpuestos(TypedDict):
"""


class DocumentoReferencia(TypedDict):
@pydantic.dataclasses.dataclass(
frozen=True,
)
class DocumentoReferencia:
tipo_documento_referencia: int
"""
Tipo Docto. Referencia
"""

folio_documento_referencia: int
folio_documento_referencia: int | str
"""
Folio Docto. Referencia
"""

@pydantic.field_validator('folio_documento_referencia')
@classmethod
def validate_folio_documento_referencia(cls, v: int | str) -> int | str:
if isinstance(v, int):
try:
cl_sii.dte.data_models.validate_dte_folio(v)
except ValueError:
# If value is numeric but not a valid DTE folio,
# assume that the value represents some other kind of number
# (e.g. a purchase order number) and convert it to a string.
v = str(v)
elif isinstance(v, str):
if v.strip().isdecimal():
numeric_v = int(v)
try:
cl_sii.dte.data_models.validate_dte_folio(numeric_v)
except ValueError:
# If value is numeric but not a valid DTE folio,
# assume that the value represents some other kind of number
# (e.g. a purchase order number) and leave it as a string.
pass
else:
v = numeric_v
return v


@pydantic.dataclasses.dataclass(
frozen=True,
Expand Down Expand Up @@ -513,8 +541,8 @@ def get_documento_referencia_dte_natural_keys(
documento_referencia_natural_keys = []

for documento_referencia in self.documento_referencias:
tipo_documento_referencia = documento_referencia['tipo_documento_referencia']
folio_documento_referencia = documento_referencia['folio_documento_referencia']
tipo_documento_referencia = documento_referencia.tipo_documento_referencia
folio_documento_referencia = documento_referencia.folio_documento_referencia

try:
tipo_documento_referencia = RcvTipoDocto(tipo_documento_referencia)
Expand All @@ -524,16 +552,16 @@ def get_documento_referencia_dte_natural_keys(
tipo_dte_referencia = cl_sii.dte.constants.TipoDte(tipo_documento_referencia)
except ValueError:
# Not a DTE.
return None
continue
else:
try:
tipo_dte_referencia = tipo_documento_referencia.as_tipo_dte()
except ValueError:
# Not a DTE.
return None
continue

if folio_documento_referencia == 0:
return None
if isinstance(folio_documento_referencia, str):
continue

documento_referencia_natural_keys.append(
cl_sii.dte.data_models.DteNaturalKey(
Expand All @@ -543,7 +571,7 @@ def get_documento_referencia_dte_natural_keys(
)
)

return documento_referencia_natural_keys
return documento_referencia_natural_keys or None

###########################################################################
# Validators
Expand Down
8 changes: 3 additions & 5 deletions src/cl_sii/rcv/parse_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ def _parse_rv_documento_referencias(
Document type. Accepts string or integer. Empty values: None, "", "0".
folio_documento_referencia : Optional[str]
Folio number(s). Single folio ("10370") or hyphen-separated multiple
folios ("10370-10371"). Empty values: None, "", "0".
folios ("10370-10371"). Empty values: None, "".

Returns
-------
Expand All @@ -1782,14 +1782,12 @@ def _parse_rv_documento_referencias(
if tipo_documento_referencia in (None, '', '0') and folio_documento_referencia in (
None,
'',
'0',
):
return None

if tipo_documento_referencia in (None, '', '0') or folio_documento_referencia in (
None,
'',
'0',
):
raise ValueError(
f"Both 'tipo_documento_referencia' ({tipo_documento_referencia}) "
Expand All @@ -1803,14 +1801,14 @@ def _parse_rv_documento_referencias(
folios = folio_documento_referencia.split('-')
for folio in folios:
folio = folio.strip()
if not folio.isdigit():
if not folio:
raise ValueError(
f"Invalid 'folio_documento_referencia': ({folio_documento_referencia})."
)
documento_referencias.append(
{
'tipo_documento_referencia': tipo_documento_referencia,
'folio_documento_referencia': int(folio),
'folio_documento_referencia': folio,
}
)
else:
Expand Down
2 changes: 2 additions & 0 deletions src/tests/test_data/sii-rcv/RCV-venta-validation-errors.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ Nro;Tipo Doc;Tipo Venta;Rut cliente;Razon Social;Folio;Fecha Docto;Fecha Recepci
2;33;Del Giro;81859341-4;POLAR S.A.;14395;07/01/2026;07/01/2026 13:18:20;08/01/2026 15:48:09;;0;1646350;312807;1959157;0;0;0;0;0;-;0;0;0;0;52;10489 ;;;0;;0;2;0;0;0;;;;0;;;;;
3;33;Del Giro;81859341-4;POLAR S.A.;14396;07/01/2026;07/01/2026 13:18:20;08/01/2026 15:48:09;;0;1646350;312807;1959157;0;0;0;0;0;-;0;0;0;0;52;;;;0;;0;2;0;0;0;;;;0;;;;;
4;33;Del Giro;81859341-4;POLAR S.A.;14397;07/01/2026;07/01/2026 13:18:20;08/01/2026 15:48:09;;0;1646350;312807;1959157;0;0;0;0;0;-;0;0;0;0;52;1057539-304-SE26;;;0;;0;2;0;0;0;;;;0;;;;;
5;33;Del Giro;81859341-4;POLAR S.A.;10258123456;07/01/2026;07/01/2026 13:18:20;08/01/2026 15:48:09;;0;1646350;312807;1959157;0;0;0;0;0;-;0;0;0;0;52;1057539;;;0;;0;2;0;0;0;;;;0;;;;;
6;33;Del Giro;81859341-4;POLAR S.A.;14398;07/01/2026;07/01/2026 13:18:20;08/01/2026 15:48:09;;0;1646350;312807;1959157;0;0;0;0;0;-;0;0;0;0;52;45000105543;;;0;;0;2;0;0;0;;;;0;;;;;

2 changes: 1 addition & 1 deletion src/tests/test_rcv_data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def test_get_documento_referencia_dte_natural_keys(self) -> None:
)
with self.assertRaisesRegex(ValueError, r'^52 is not a valid RcvTipoDocto$'):
RcvTipoDocto(
rv_detalle_entry_with_non_rcv_doc_ref.documento_referencias[0]['tipo_documento_referencia'] # type: ignore[index] # noqa: E501
rv_detalle_entry_with_non_rcv_doc_ref.documento_referencias[0].tipo_documento_referencia # type: ignore[index] # noqa: E501
)

expected_doc_ref_dte_natural_key = [
Expand Down
Loading
Loading