Skip to content

Commit

Permalink
Merge pull request #115 from fyntex/develop
Browse files Browse the repository at this point in the history
Release v0.10.0.a3
  • Loading branch information
glarrain committed Apr 14, 2020
2 parents 1b70e3e + e9c7680 commit d84d127
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 144 deletions.
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.10.0.a2
current_version = 0.10.0.a3
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion cl_sii/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"""


__version__ = '0.10.0.a2'
__version__ = '0.10.0.a3'
66 changes: 11 additions & 55 deletions cl_sii/rcv/parse_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
from typing import Callable, Dict, Iterable, Optional, Sequence, Tuple

import marshmallow
import marshmallow.fields
import marshmallow.validate

import cl_sii.dte.data_models
from cl_sii.base.constants import SII_OFFICIAL_TZ
from cl_sii.extras import mm_fields
from cl_sii.libs import csv_utils
Expand All @@ -34,7 +31,7 @@


RcvCsvFileParserType = Callable[
[Rut, str, str, int, Optional[int]],
[Rut, str, int, Optional[int]],
Iterable[
Tuple[
Optional[RcvDetalleEntry],
Expand Down Expand Up @@ -89,7 +86,6 @@ def get_rcv_csv_file_parser(

def parse_rcv_venta_csv_file(
rut: Rut,
razon_social: str,
input_file_path: str,
n_rows_offset: int = 0,
max_n_rows: int = None,
Expand All @@ -99,13 +95,9 @@ def parse_rcv_venta_csv_file(
"""
# warning: this looks like it would be executed before the iteration begins but it is not.
if not isinstance(razon_social, str):
raise TypeError("Inappropriate type of 'razon_social'.")
cl_sii.dte.data_models.validate_contribuyente_razon_social(razon_social)

schema_context = dict(
emisor_rut=rut,
emisor_razon_social=razon_social,
)
input_csv_row_schema = RcvVentaCsvRowSchema(context=schema_context)

Expand Down Expand Up @@ -206,7 +198,6 @@ def parse_rcv_venta_csv_file(

def parse_rcv_compra_registro_csv_file(
rut: Rut,
razon_social: str,
input_file_path: str,
n_rows_offset: int = 0,
max_n_rows: int = None,
Expand All @@ -216,13 +207,9 @@ def parse_rcv_compra_registro_csv_file(
"""
# warning: this looks like it would be executed before the iteration begins but it is not.
if not isinstance(razon_social, str):
raise TypeError("Inappropriate type of 'razon_social'.")
cl_sii.dte.data_models.validate_contribuyente_razon_social(razon_social)

schema_context = dict(
receptor_rut=rut,
receptor_razon_social=razon_social,
)
input_csv_row_schema = RcvCompraRegistroCsvRowSchema(context=schema_context)

Expand Down Expand Up @@ -292,7 +279,6 @@ def parse_rcv_compra_registro_csv_file(

def parse_rcv_compra_no_incluir_csv_file(
rut: Rut,
razon_social: str,
input_file_path: str,
n_rows_offset: int = 0,
max_n_rows: int = None,
Expand All @@ -302,13 +288,9 @@ def parse_rcv_compra_no_incluir_csv_file(
"""
# warning: this looks like it would be executed before the iteration begins but it is not.
if not isinstance(razon_social, str):
raise TypeError("Inappropriate type of 'razon_social'.")
cl_sii.dte.data_models.validate_contribuyente_razon_social(razon_social)

schema_context = dict(
receptor_rut=rut,
receptor_razon_social=razon_social,
)
input_csv_row_schema = RcvCompraNoIncluirCsvRowSchema(context=schema_context)

Expand Down Expand Up @@ -372,7 +354,6 @@ def parse_rcv_compra_no_incluir_csv_file(

def parse_rcv_compra_reclamado_csv_file(
rut: Rut,
razon_social: str,
input_file_path: str,
n_rows_offset: int = 0,
max_n_rows: int = None,
Expand All @@ -382,13 +363,9 @@ def parse_rcv_compra_reclamado_csv_file(
"""
# warning: this looks like it would be executed before the iteration begins but it is not.
if not isinstance(razon_social, str):
raise TypeError("Inappropriate type of 'razon_social'.")
cl_sii.dte.data_models.validate_contribuyente_razon_social(razon_social)

schema_context = dict(
receptor_rut=rut,
receptor_razon_social=razon_social,
)
input_csv_row_schema = RcvCompraReclamadoCsvRowSchema(context=schema_context)

Expand Down Expand Up @@ -452,7 +429,6 @@ def parse_rcv_compra_reclamado_csv_file(

def parse_rcv_compra_pendiente_csv_file(
rut: Rut,
razon_social: str,
input_file_path: str,
n_rows_offset: int = 0,
max_n_rows: int = None,
Expand All @@ -462,13 +438,9 @@ def parse_rcv_compra_pendiente_csv_file(
"""
# warning: this looks like it would be executed before the iteration begins but it is not.
if not isinstance(razon_social, str):
raise TypeError("Inappropriate type of 'razon_social'.")
cl_sii.dte.data_models.validate_contribuyente_razon_social(razon_social)

schema_context = dict(
receptor_rut=rut,
receptor_razon_social=razon_social,
)
input_csv_row_schema = RcvCompraPendienteCsvRowSchema(context=schema_context)

Expand Down Expand Up @@ -593,9 +565,6 @@ class Meta:
emisor_rut = mm_fields.RutField(
required=True,
)
emisor_razon_social = marshmallow.fields.String(
required=True,
)

###########################################################################
# extra fields: not included in the returned struct
Expand Down Expand Up @@ -626,7 +595,6 @@ def preprocess(self, in_data: dict) -> dict:

# Set field value only if it was not in the input data.
in_data.setdefault('emisor_rut', self.context['emisor_rut'])
in_data.setdefault('emisor_razon_social', self.context['emisor_razon_social'])

# Fix missing/default values.
if 'Fecha Acuse Recibo' in in_data:
Expand Down Expand Up @@ -672,7 +640,6 @@ def to_detalle_entry(self, data: dict) -> RvDetalleEntry:
fecha_emision_date: date = data['fecha_emision_date'] # type: ignore
receptor_rut: Rut = data['receptor_rut'] # type: ignore
monto_total: int = data['monto_total'] # type: ignore
emisor_razon_social: str = data['emisor_razon_social'] # type: ignore
receptor_razon_social: str = data['receptor_razon_social'] # type: ignore
fecha_recepcion_dt: datetime = data['fecha_recepcion_dt'] # type: ignore
fecha_acuse_dt: Optional[datetime] = data['fecha_acuse_dt'] # type: ignore
Expand All @@ -688,8 +655,9 @@ def to_detalle_entry(self, data: dict) -> RvDetalleEntry:
fecha_emision_date=fecha_emision_date,
receptor_rut=receptor_rut,
monto_total=monto_total,
emisor_razon_social=emisor_razon_social,
receptor_razon_social=receptor_razon_social,
# FIXME: remove after field 'emisor_razon_social' is removed from the dataclass
emisor_razon_social=None,
fecha_recepcion_dt=fecha_recepcion_dt,
fecha_acuse_dt=fecha_acuse_dt,
fecha_reclamo_dt=fecha_reclamo_dt,
Expand Down Expand Up @@ -745,9 +713,6 @@ class Meta:
receptor_rut = mm_fields.RutField(
required=True,
)
receptor_razon_social = marshmallow.fields.String(
required=True,
)

###########################################################################
# extra fields: not included in the returned struct
Expand All @@ -772,7 +737,6 @@ def preprocess(self, in_data: dict) -> dict:

# Set field value only if it was not in the input data.
in_data.setdefault('receptor_rut', self.context['receptor_rut'])
in_data.setdefault('receptor_razon_social', self.context['receptor_razon_social'])

# Fix missing/default values.
if 'Fecha Acuse' in in_data:
Expand Down Expand Up @@ -813,7 +777,6 @@ def to_detalle_entry(self, data: dict) -> RcRegistroDetalleEntry:
receptor_rut: Rut = data['receptor_rut'] # type: ignore
monto_total: int = data['monto_total'] # type: ignore
emisor_razon_social: str = data['emisor_razon_social'] # type: ignore
receptor_razon_social: str = data['receptor_razon_social'] # type: ignore
fecha_recepcion_dt: datetime = data['fecha_recepcion_dt'] # type: ignore
fecha_acuse_dt: Optional[datetime] = data['fecha_acuse_dt'] # type: ignore
except KeyError as exc:
Expand All @@ -828,7 +791,8 @@ def to_detalle_entry(self, data: dict) -> RcRegistroDetalleEntry:
receptor_rut=receptor_rut,
monto_total=monto_total,
emisor_razon_social=emisor_razon_social,
receptor_razon_social=receptor_razon_social,
# FIXME: remove after field 'receptor_razon_social' is removed from the dataclass
receptor_razon_social=None,
fecha_recepcion_dt=fecha_recepcion_dt,
fecha_acuse_dt=fecha_acuse_dt,
)
Expand All @@ -849,7 +813,6 @@ def to_detalle_entry(self, data: dict) -> RcNoIncluirDetalleEntry:
receptor_rut: Rut = data['receptor_rut'] # type: ignore
monto_total: int = data['monto_total'] # type: ignore
emisor_razon_social: str = data['emisor_razon_social'] # type: ignore
receptor_razon_social: str = data['receptor_razon_social'] # type: ignore
fecha_recepcion_dt: datetime = data['fecha_recepcion_dt'] # type: ignore
fecha_acuse_dt: Optional[datetime] = data['fecha_acuse_dt'] # type: ignore
except KeyError as exc:
Expand All @@ -864,7 +827,8 @@ def to_detalle_entry(self, data: dict) -> RcNoIncluirDetalleEntry:
receptor_rut=receptor_rut,
monto_total=monto_total,
emisor_razon_social=emisor_razon_social,
receptor_razon_social=receptor_razon_social,
# FIXME: remove after field 'receptor_razon_social' is removed from the dataclass
receptor_razon_social=None,
fecha_recepcion_dt=fecha_recepcion_dt,
fecha_acuse_dt=fecha_acuse_dt,
)
Expand Down Expand Up @@ -919,9 +883,6 @@ class Meta:
receptor_rut = mm_fields.RutField(
required=True,
)
receptor_razon_social = marshmallow.fields.String(
required=True,
)

###########################################################################
# extra fields: not included in the returned struct
Expand Down Expand Up @@ -949,7 +910,6 @@ def preprocess(self, in_data: dict) -> dict:

# Set field value only if it was not in the input data.
in_data.setdefault('receptor_rut', self.context['receptor_rut'])
in_data.setdefault('receptor_razon_social', self.context['receptor_razon_social'])

# Fix missing/default values.
# note: for some reason the rows with 'tipo_docto' equal to
Expand Down Expand Up @@ -993,7 +953,6 @@ def to_detalle_entry(self, data: dict) -> RcReclamadoDetalleEntry:
receptor_rut: Rut = data['receptor_rut'] # type: ignore
monto_total: int = data['monto_total'] # type: ignore
emisor_razon_social: str = data['emisor_razon_social'] # type: ignore
receptor_razon_social: str = data['receptor_razon_social'] # type: ignore
fecha_recepcion_dt: datetime = data['fecha_recepcion_dt'] # type: ignore
fecha_reclamo_dt: Optional[datetime] = data['fecha_reclamo_dt'] # type: ignore
except KeyError as exc:
Expand All @@ -1008,7 +967,8 @@ def to_detalle_entry(self, data: dict) -> RcReclamadoDetalleEntry:
receptor_rut=receptor_rut,
monto_total=monto_total,
emisor_razon_social=emisor_razon_social,
receptor_razon_social=receptor_razon_social,
# FIXME: remove after field 'receptor_razon_social' is removed from the dataclass
receptor_razon_social=None,
fecha_recepcion_dt=fecha_recepcion_dt,
fecha_reclamo_dt=fecha_reclamo_dt,
)
Expand Down Expand Up @@ -1063,9 +1023,6 @@ class Meta:
receptor_rut = mm_fields.RutField(
required=True,
)
receptor_razon_social = marshmallow.fields.String(
required=True,
)

###########################################################################
# extra fields: not included in the returned struct
Expand All @@ -1084,7 +1041,6 @@ def preprocess(self, in_data: dict) -> dict:

# Set field value only if it was not in the input data.
in_data.setdefault('receptor_rut', self.context['receptor_rut'])
in_data.setdefault('receptor_razon_social', self.context['receptor_razon_social'])

# Fix missing/default values.
if 'Fecha Acuse' in in_data:
Expand Down Expand Up @@ -1121,7 +1077,6 @@ def to_detalle_entry(self, data: dict) -> RcPendienteDetalleEntry:
receptor_rut: Rut = data['receptor_rut'] # type: ignore
monto_total: int = data['monto_total'] # type: ignore
emisor_razon_social: str = data['emisor_razon_social'] # type: ignore
receptor_razon_social: str = data['receptor_razon_social'] # type: ignore
fecha_recepcion_dt: datetime = data['fecha_recepcion_dt'] # type: ignore
except KeyError as exc:
raise ValueError("Programming error: a referenced field is missing.") from exc
Expand All @@ -1135,7 +1090,8 @@ def to_detalle_entry(self, data: dict) -> RcPendienteDetalleEntry:
receptor_rut=receptor_rut,
monto_total=monto_total,
emisor_razon_social=emisor_razon_social,
receptor_razon_social=receptor_razon_social,
# FIXME: remove after field 'receptor_razon_social' is removed from the dataclass
receptor_razon_social=None,
fecha_recepcion_dt=fecha_recepcion_dt,
)
except (TypeError, ValueError):
Expand Down

0 comments on commit d84d127

Please sign in to comment.