Further refactor query services
This commit is contained in:
parent
bacc6235d4
commit
7adf39194d
|
@ -1,6 +1,7 @@
|
|||
|
||||
__all__ = [
|
||||
'get_headers',
|
||||
'build_query_filter',
|
||||
'IssuedInvoiceMapper',
|
||||
'RecievedInvoiceMapper',
|
||||
]
|
||||
|
@ -8,6 +9,22 @@ __all__ = [
|
|||
_DATE_FMT = '%d-%m-%Y'
|
||||
|
||||
|
||||
def _format_period(period):
|
||||
return str(period).zfill(2)
|
||||
|
||||
|
||||
def build_query_filter(year=None, period=None):
|
||||
return {
|
||||
'PeriodoImpositivo': {
|
||||
'Ejercicio': year,
|
||||
'Periodo': _format_period(period),
|
||||
}
|
||||
# TODO: IDFactura, Contraparte,
|
||||
# FechaPresentacion, FacturaModificada,
|
||||
# EstadoCuadre, ClavePaginacion
|
||||
}
|
||||
|
||||
|
||||
def get_headers(name=None, vat=None, comm_kind=None, version='0.7'):
|
||||
return {
|
||||
'IDVersionSii': version,
|
||||
|
@ -39,7 +56,7 @@ class IssuedInvoiceMapper(object):
|
|||
def build_period(cls, invoice):
|
||||
return {
|
||||
'Ejercicio': cls.year(invoice),
|
||||
'Periodo': str(cls.period(invoice)).zfill(2),
|
||||
'Periodo': _format_period(cls.period(invoice)),
|
||||
}
|
||||
|
||||
@classmethod
|
||||
|
@ -181,7 +198,7 @@ class RecievedInvoiceMapper(object):
|
|||
def build_period(cls, invoice):
|
||||
return {
|
||||
'Ejercicio': cls.year(invoice),
|
||||
'Periodo': str(cls.period(invoice)).zfill(2),
|
||||
'Periodo': _format_period(cls.period(invoice)),
|
||||
}
|
||||
|
||||
@classmethod
|
||||
|
@ -213,11 +230,7 @@ class RecievedInvoiceMapper(object):
|
|||
def build_invoice(cls, invoice):
|
||||
ret = {
|
||||
'TipoFactura': cls.invoice_kind(invoice),
|
||||
# TODO: TipoRectificativa
|
||||
# TODO: FacturasAgrupadas: {IDFacturaAgrupada: [{Num, Fecha}]}
|
||||
# TODO: FacturasRectificadas:{IDFacturaRectificada:[{Num, Fecha}]}
|
||||
# TODO: ImporteRectificacion: {
|
||||
# BaseRectificada, CuotaRectificada, CuotaRecargoRectificado }
|
||||
# TODO: FechaOperacion
|
||||
'ClaveRegimenEspecialOTrascendencia':
|
||||
cls.specialkey_or_trascendence(invoice),
|
||||
|
@ -241,8 +254,17 @@ class RecievedInvoiceMapper(object):
|
|||
'FechaRegContable': cls.move_date(invoice).strftime(_DATE_FMT),
|
||||
'CuotaDeducible': cls.deductible_amount(invoice),
|
||||
}
|
||||
cls._update_rectified_invoice(ret, invoice)
|
||||
return ret
|
||||
|
||||
@classmethod
|
||||
def _update_rectified_invoice(cls, ret, invoice):
|
||||
if ret['TipoFactura'] in {'R1', 'R2', 'R3', 'R4', 'R5'}:
|
||||
ret['TipoRectificativa'] = cls.rectified_invoice_kind(invoice)
|
||||
# TODO: FacturasRectificadas:{IDFacturaRectificada:[{Num, Fecha}]}
|
||||
# TODO: ImporteRectificacion: {
|
||||
# BaseRectificada, CuotaRectificada, CuotaRecargoRectificado }
|
||||
|
||||
@classmethod
|
||||
def build_counterpart(cls, invoice):
|
||||
return {
|
||||
|
|
|
@ -25,3 +25,6 @@ class LoggingPlugin(Plugin):
|
|||
_logger.debug('envelope: %s', etree.tostring(
|
||||
envelope, pretty_print=True))
|
||||
return envelope, http_headers
|
||||
|
||||
|
||||
# TODO: JSESSIONID Plugin
|
||||
|
|
|
@ -12,6 +12,7 @@ from zeep.transports import Transport
|
|||
from zeep.plugins import HistoryPlugin
|
||||
|
||||
from .plugins import LoggingPlugin
|
||||
from .mapping import build_query_filter
|
||||
|
||||
_logger = getLogger(__name__)
|
||||
|
||||
|
@ -92,15 +93,7 @@ class _IssuedInvoiceService(object):
|
|||
return response_
|
||||
|
||||
def query(self, headers, year=None, period=None):
|
||||
filter_ = {
|
||||
'PeriodoImpositivo': {
|
||||
'Ejercicio': year,
|
||||
'Periodo': str(period).zfill(2),
|
||||
}
|
||||
# TODO: IDFactura, Contraparte,
|
||||
# FechaPresentacion, FacturaModificada,
|
||||
# EstadoCuadre, ClavePaginacion
|
||||
}
|
||||
filter_ = build_query_filter(year=year, period=period)
|
||||
_logger.debug(filter_)
|
||||
response_ = self.service.ConsultaLRFacturasEmitidas(
|
||||
headers, filter_)
|
||||
|
@ -137,15 +130,7 @@ class _RecievedInvoiceService(object):
|
|||
return response_
|
||||
|
||||
def query(self, headers, year=None, period=None):
|
||||
filter_ = {
|
||||
'PeriodoImpositivo': {
|
||||
'Ejercicio': year,
|
||||
'Periodo': str(period).zfill(2),
|
||||
}
|
||||
# TODO: IDFactura,
|
||||
# FechaPresentacion, FacturaModificada,
|
||||
# EstadoCuadre, ClavePaginacion
|
||||
}
|
||||
filter_ = build_query_filter(year=year, period=period)
|
||||
_logger.debug(filter_)
|
||||
response_ = self.service.ConsultaLRFacturasRecibidas(
|
||||
headers, filter_)
|
||||
|
|
Loading…
Reference in New Issue