Refactor invoice query services.

This commit is contained in:
Daniel Möller 2017-05-25 15:45:25 +02:00
parent e0fd5d1a26
commit bacc6235d4
3 changed files with 55 additions and 24 deletions

32
aeat.py
View File

@ -471,20 +471,14 @@ class SIIReport(Workflow, ModelSQL, ModelView):
name=self.company.party.name,
vat=self.company.party.vat_number,
comm_kind=self.operation_type)
filter_ = {
'PeriodoImpositivo': {
'Ejercicio': self.fiscalyear.name,
'Periodo': str(
self.period.start_date.month).zfill(2),
}
# TODO: IDFactura, Contraparte,
# FechaPresentacion, FacturaModificada,
# EstadoCuadre, ClavePaginacion
}
with self.company.tmp_ssl_credentials() as (crt, key):
srv = service.bind_issued_invoices_service(
crt, key, test=True)
res = srv.query(headers, filter_)
res = srv.query(
headers,
year=self.fiscalyear.name,
period=self.period.start_date.month)
registers = \
res.RegistroRespuestaConsultaLRFacturasEmitidas
@ -579,20 +573,14 @@ class SIIReport(Workflow, ModelSQL, ModelView):
name=self.company.party.name,
vat=self.company.party.vat_number,
comm_kind=self.operation_type)
filter_ = {
'PeriodoImpositivo': {
'Ejercicio': self.fiscalyear.name,
'Periodo': str(
self.period.start_date.month).zfill(2),
}
# TODO: IDFactura,
# FechaPresentacion, FacturaModificada,
# EstadoCuadre, ClavePaginacion
}
with self.company.tmp_ssl_credentials() as (crt, key):
srv = service.bind_recieved_invoices_service(
crt, key, test=True)
res = srv.query(headers, filter_)
res = srv.query(
headers,
year=self.fiscalyear.name,
period=self.period.start_date.month)
_logger.debug(res)
registers = \

View File

@ -91,7 +91,16 @@ class _IssuedInvoiceService(object):
_logger.debug(response_)
return response_
def query(self, headers, filter_):
def query(self, headers, year=None, period=None):
filter_ = {
'PeriodoImpositivo': {
'Ejercicio': year,
'Periodo': str(period).zfill(2),
}
# TODO: IDFactura, Contraparte,
# FechaPresentacion, FacturaModificada,
# EstadoCuadre, ClavePaginacion
}
_logger.debug(filter_)
response_ = self.service.ConsultaLRFacturasEmitidas(
headers, filter_)
@ -127,7 +136,16 @@ class _RecievedInvoiceService(object):
_logger.debug(response_)
return response_
def query(self, headers, filter_):
def query(self, headers, year=None, period=None):
filter_ = {
'PeriodoImpositivo': {
'Ejercicio': year,
'Periodo': str(period).zfill(2),
}
# TODO: IDFactura,
# FechaPresentacion, FacturaModificada,
# EstadoCuadre, ClavePaginacion
}
_logger.debug(filter_)
response_ = self.service.ConsultaLRFacturasRecibidas(
headers, filter_)

View File

@ -29,6 +29,29 @@ class IssuedTestInvoiceMapper(mapping.IssuedInvoiceMapper):
tax_amount = methodcaller('get', 'tax_amount')
class RecievedTestInvoiceMapper(mapping.RecievedInvoiceMapper):
year = methodcaller('get', 'year')
period = methodcaller('get', 'period')
nif = methodcaller('get', 'nif')
serial_number = methodcaller('get', 'serial_number')
issue_date = methodcaller('get', 'issue_date')
invoice_kind = methodcaller('get', 'invoice_kind')
rectified_invoice_kind = methodcaller('get', 'rectified_invoice_kind')
rectified_base = methodcaller('get', 'rectified_base')
rectified_amount = methodcaller('get', 'rectified_amount')
total_amount = methodcaller('get', 'total_amount')
specialkey_or_trascendence = methodcaller('get', 'specialkey_or_trascendence')
description = methodcaller('get', 'description')
not_exempt_kind = methodcaller('get', 'not_exempt_kind')
counterpart_name = methodcaller('get', 'counterpart_name')
counterpart_nif = methodcaller('get', 'counterpart_nif')
counterpart_id_type = methodcaller('get', 'counterpart_id_type')
counterpart_country = methodcaller('get', 'counterpart_country')
taxes = methodcaller('get', 'taxes')
tax_rate = methodcaller('get', 'tax_rate')
tax_base = methodcaller('get', 'tax_base')
tax_amount = methodcaller('get', 'tax_amount')
def test_issued_invoice_mapping():
invoice = {
@ -102,6 +125,7 @@ def test_rectified_issued_invoice_mapping():
assert request_['FacturaExpedida']['ImporteRectificacion']['BaseRectificada'] == 100
assert request_['FacturaExpedida']['ImporteRectificacion']['CuotaRectificada'] == 200
def test_rectified_by_difference_issued_invoice_mapping():
invoice = {
'year': 2017,
@ -134,6 +158,7 @@ def test_rectified_by_difference_issued_invoice_mapping():
assert request_['FacturaExpedida']['TipoRectificativa'] == 'I'
assert 'ImporteRectificacion' not in request_['FacturaExpedida']
def test_rectified_simplified_issued_invoice_with_1_line_mapping():
invoice = {
'year': 2017,