Update query function to take more than 10.000 registar from SII

This commit is contained in:
Bernat Brunet Torruella 2018-10-19 09:57:07 +02:00
parent 835fe2595a
commit 54120286ff
3 changed files with 28 additions and 4 deletions

29
aeat.py
View File

@ -550,9 +550,10 @@ class SIIReport(Workflow, ModelSQL, ModelView):
self._save_response(res)
def query_issued_invoices(self):
def query_issued_invoices(self, last_invoice=None):
pool = Pool()
Invoice = pool.get('account.invoice')
mapper = pool.get('aeat.sii.issued.invoice.mapper')(pool=pool)
headers = mapping.get_headers(
name=tools.unaccent(self.company.party.name),
@ -566,7 +567,9 @@ class SIIReport(Workflow, ModelSQL, ModelView):
res = srv.query(
headers,
year=self.fiscalyear.name,
period=self.period.start_date.month)
period=self.period.start_date.month,
mapper=mapper,
last_invoice=last_invoice)
registers = \
res.RegistroRespuestaConsultaLRFacturasEmitidas
@ -581,10 +584,14 @@ class SIIReport(Workflow, ModelSQL, ModelView):
invoice.number: invoice.id
for invoice in invoices_list
}
pagination = res.IndicadorPaginacion
last_invoice = invoices_list[-1]
self.lines = tuple(
SIIReportLine(
invoice=invoices_ids.get(reg.IDFactura.NumSerieFacturaEmisor),
state=reg.EstadoFactura.EstadoRegistro,
last_modify_date=_datetime(
reg.EstadoFactura.TimestampUltimaModificacion),
communication_code=reg.EstadoFactura.CodigoErrorRegistro,
communication_msg=reg.EstadoFactura.DescripcionErrorRegistro,
issuer_vat_number=(
@ -631,6 +638,9 @@ class SIIReport(Workflow, ModelSQL, ModelView):
)
self.save()
if pagination == 'S':
self.query_issued_invoices(last_invoice=last_invoice)
def submit_recieved_invoices(self):
pool = Pool()
mapper = pool.get('aeat.sii.recieved.invoice.mapper')(pool=pool)
@ -688,9 +698,10 @@ class SIIReport(Workflow, ModelSQL, ModelView):
self.csv = response.CSV
self.save()
def query_recieved_invoices(self):
def query_recieved_invoices(self, last_invoice=None):
pool = Pool()
Invoice = pool.get('account.invoice')
mapper = pool.get('aeat.sii.recieved.invoice.mapper')(pool=pool)
SIIReportLine = pool.get('aeat.sii.report.lines')
SIIReportLineTax = pool.get('aeat.sii.report.line.tax')
@ -706,10 +717,13 @@ class SIIReport(Workflow, ModelSQL, ModelView):
res = srv.query(
headers,
year=self.fiscalyear.name,
period=self.period.start_date.month)
period=self.period.start_date.month,
mapper=mapper,
last_invoice=last_invoice)
_logger.debug(res)
registers = res.RegistroRespuestaConsultaLRFacturasRecibidas
pagination = res.IndicadorPaginacion
# FIXME: the reference is not forced to be unique
lines_to_create = []
@ -737,6 +751,8 @@ class SIIReport(Workflow, ModelSQL, ModelView):
sii_report_line = {
'report': self.id,
'state': reg.EstadoFactura.EstadoRegistro,
'last_modify_date': _datetime(
reg.EstadoFactura.TimestampUltimaModificacion),
'communication_code': (
reg.EstadoFactura.CodigoErrorRegistro),
'communication_msg': (
@ -798,9 +814,13 @@ class SIIReport(Workflow, ModelSQL, ModelView):
break
if invoices:
sii_report_line['invoice'] = invoices[0].id
last_invoice = invoices[0]
lines_to_create.append(sii_report_line)
SIIReportLine.create(lines_to_create)
if pagination == 'S':
self.query_recieved_invoices(last_invoice=last_invoice)
class SIIReportLine(ModelSQL, ModelView):
'''
@ -816,6 +836,7 @@ class SIIReportLine(ModelSQL, ModelView):
'operation_type') != 'C0',
})
state = fields.Selection(AEAT_INVOICE_STATE, 'State')
last_modify_date = fields.Char('Last Modification Date', readonly=True)
communication_code = fields.Integer(
'Communication Code', readonly=True)
communication_msg = fields.Char(

View File

@ -8,6 +8,8 @@
<field name="invoice"/>
<label name="state"/>
<field name="state"/>
<label name="last_modify_date"/>
<field name="last_modify_date"/>
<label name="communication_msg"/>
<field name="communication_msg"/>
<label name="issuer_vat_number"/>

View File

@ -8,6 +8,7 @@
<field name="vat_code"/>
<field name="identifier_type"/>
<field name="state"/>
<field name="last_modify_date"/>
<field name="communication_code"/>
<field name="communication_msg"/>
<field name="issuer_vat_number"/>