Check if duplicated invoices on SII report

This commit is contained in:
Sergio Morillo 2021-10-22 18:26:12 +02:00
parent 3f625b30ba
commit c8e053d997
3 changed files with 19 additions and 1 deletions

12
aeat.py
View File

@ -405,6 +405,7 @@ class SIIReport(Workflow, ModelSQL, ModelView):
def confirm(cls, reports):
for report in reports:
report.check_invoice_state()
report.check_duplicate_invoices()
@classmethod
@ModelView.button
@ -1129,6 +1130,17 @@ class SIIReport(Workflow, ModelSQL, ModelView):
cls.confirm(received_reports)
cls.send(received_reports)
def check_duplicate_invoices(self):
if self.operation_type in ('A0', 'D0'):
invoices = set()
for line in self.lines:
if line.invoice in invoices:
raise UserError(gettext(
'aeat_sii.msg_report_duplicated_invoice',
invoice=line.invoice.rec_name,
report=self.rec_name))
invoices.add(line.invoice)
class SIIReportLine(ModelSQL, ModelView):
'''

View File

@ -1789,4 +1789,8 @@ msgstr "Forzar borrador factura enviada a SII"
msgctxt "model:ir.message,text:msg_report_wrong_invoice_state"
msgid "Invoice \"%(invoice)s\" must be posted or paid."
msgstr "La factura \"%(invoice)s\" debe estar contabilizada o pagada."
msgstr "La factura \"%(invoice)s\" debe estar contabilizada o pagada."
msgctxt "model:ir.message,text:msg_report_duplicated_invoice"
msgid "Invoice \"%(invoice)s\" is duplicated on SII Report \"%(report)s\"."
msgstr "La factura \"%(invoice)s\" se ha incluído varias veces en el Libro SII \"%(report)s\"."

View File

@ -48,6 +48,8 @@ If you edit them take care if you need to update again to SII</field>
<field name="text">Cannot modify "%(fields)s" on invoice "%(invoice)s" because its SII state is "%(sii_state)s". Please first include the invoice in a Delete Invoice SII Book and send to AEAT.</field>
<record model="ir.message" id="msg_report_wrong_invoice_state">
<field name="text">Invoice "%(invoice)s" must be posted or paid.</field>
<record model="ir.message" id="msg_report_duplicated_invoice">
<field name="text">Invoice "%(invoice)s" is duplicated on SII Report "%(report)s".</field>
</record>
</data>
</tryton>