diff --git a/aeat.py b/aeat.py
index b8845e0..7d24b24 100644
--- a/aeat.py
+++ b/aeat.py
@@ -266,6 +266,19 @@ class SIIReport(Workflow, ModelSQL, ModelView):
'readonly': ((Eval('state') != 'draft')
| (Eval('lines', [0]) & Eval('period'))),
}, depends=['state', 'fiscalyear'])
+ load_date = fields.Date('Load Date',
+ domain=['OR', [
+ ('load_date', '=', None),
+ ], [
+ ('load_date', '>=', Eval('load_date_start')),
+ ('load_date', '<=', Eval('load_date_end')),
+ ]
+ ], depends=['load_date_start', 'load_date_end'],
+ help='Filter invoices to the date whitin the period.')
+ load_date_start = fields.Function(fields.Date('Load Date Start'),
+ 'on_change_with_load_date_start')
+ load_date_end = fields.Function(fields.Date('Load Date End'),
+ 'on_change_with_load_date_end')
operation_type = fields.Selection(COMMUNICATION_TYPE, 'Operation Type',
required=True,
states={
@@ -348,11 +361,6 @@ class SIIReport(Workflow, ModelSQL, ModelView):
def default_company():
return Transaction().context.get('company')
- @fields.depends('company')
- def on_change_with_currency(self, name=None):
- if self.company:
- return self.company.currency.id
-
@staticmethod
def default_fiscalyear():
FiscalYear = Pool().get('account.fiscalyear')
@@ -367,11 +375,29 @@ class SIIReport(Workflow, ModelSQL, ModelView):
def default_version():
return '1.1'
+ @fields.depends('period')
+ def on_change_period(self):
+ if not self.period:
+ self.load_date = None
+
@fields.depends('company')
def on_change_with_company_vat(self):
if self.company:
return self.company.party.sii_vat_code
+ @fields.depends('company')
+ def on_change_with_currency(self, name=None):
+ if self.company:
+ return self.company.currency.id
+
+ @fields.depends('period')
+ def on_change_with_load_date_start(self, name=None):
+ return self.period.start_date if self.period else None
+
+ @fields.depends('period')
+ def on_change_with_load_date_end(self, name=None):
+ return self.period.end_date if self.period else None
+
@classmethod
def copy(cls, records, default=None):
if default is None:
@@ -452,22 +478,29 @@ class SIIReport(Workflow, ModelSQL, ModelView):
('sii_book_key', '=', report.book),
('move.period', '=', report.period.id),
('state', 'in', ['posted', 'paid']),
- ]
+ ]
if report.operation_type == 'A0':
domain.append(('sii_state', 'in', [None, 'Incorrecto']))
-
elif report.operation_type in ('A1', 'A4'):
domain.append(('sii_state', 'in', [
'AceptadoConErrores', 'AceptadaConErrores']))
+ if report.load_date:
+ domain.append(['OR', [
+ ('invoice_date', '<=', report.load_date),
+ ('accounting_date', '=', None),
+ ], [
+ ('accounting_date', '<=', report.load_date),
+ ]])
+
_logger.debug('Searching invoices for SII report: %s', domain)
for invoice in Invoice.search(domain):
to_create.append({
'report': report,
'invoice': invoice,
- })
+ })
if to_create:
ReportLine.create(to_create)
diff --git a/locale/ca.po b/locale/ca.po
index 0cf62b8..9f48a5e 100644
--- a/locale/ca.po
+++ b/locale/ca.po
@@ -170,6 +170,18 @@ msgctxt "field:aeat.sii.report,lines:"
msgid "Lines"
msgstr "Líneas"
+msgctxt "field:aeat.sii.report,load_date:"
+msgid "Load Date"
+msgstr "Data límit"
+
+msgctxt "field:aeat.sii.report,load_date_end:"
+msgid "Load Date End"
+msgstr "Fins data límit"
+
+msgctxt "field:aeat.sii.report,load_date_start:"
+msgid "Load Date Start"
+msgstr "Desde data límit"
+
msgctxt "field:aeat.sii.report,operation_type:"
msgid "Operation Type"
msgstr "Tipo de operación"
@@ -398,6 +410,10 @@ msgctxt "field:party.party,sii_vat_country:"
msgid "SII VAT Country"
msgstr "País NIF SII"
+msgctxt "help:aeat.sii.report,load_date:"
+msgid "Filter invoices to the date whitin the period."
+msgstr "Filtra les factures fins la data dins del període."
+
msgctxt "model:aeat.sii.issued.invoice.mapper,name:"
msgid "Tryton Issued Invoice to AEAT mapper"
msgstr "Correspondencia Tryton - Aeat facturas emitidas"
diff --git a/locale/es.po b/locale/es.po
index 20338ce..fb87336 100644
--- a/locale/es.po
+++ b/locale/es.po
@@ -170,6 +170,18 @@ msgctxt "field:aeat.sii.report,lines:"
msgid "Lines"
msgstr "Líneas"
+msgctxt "field:aeat.sii.report,load_date:"
+msgid "Load Date"
+msgstr "Fecha límite"
+
+msgctxt "field:aeat.sii.report,load_date_end:"
+msgid "Load Date End"
+msgstr "Hasta fecha límite"
+
+msgctxt "field:aeat.sii.report,load_date_start:"
+msgid "Load Date Start"
+msgstr "Desde fecha límite"
+
msgctxt "field:aeat.sii.report,operation_type:"
msgid "Operation Type"
msgstr "Tipo de operación"
@@ -398,6 +410,10 @@ msgctxt "field:party.party,sii_vat_country:"
msgid "SII VAT Country"
msgstr "País NIF SII"
+msgctxt "help:aeat.sii.report,load_date:"
+msgid "Filter invoices to the date whitin the period."
+msgstr "Filtra las facturas hasta la fecha dentro del período."
+
msgctxt "model:aeat.sii.issued.invoice.mapper,name:"
msgid "Tryton Issued Invoice to AEAT mapper"
msgstr "Correspondencia Tryton - Aeat facturas emitidas"
diff --git a/view/sii_report_form.xml b/view/sii_report_form.xml
index 4287098..4a485c1 100644
--- a/view/sii_report_form.xml
+++ b/view/sii_report_form.xml
@@ -18,6 +18,8 @@
+
+