diff --git a/__init__.py b/__init__.py index a631c82..ccd1772 100644 --- a/__init__.py +++ b/__init__.py @@ -21,6 +21,7 @@ def register(): load_pkcs12.LoadPKCS12Start, aeat.SIIReport, aeat.SIIReportLine, + aeat.SIIReportLineTax, aeat_mapping.IssuedTrytonInvoiceMapper, aeat_mapping.RecievedTrytonInvoiceMapper, module='aeat_sii', type_='model') diff --git a/aeat.py b/aeat.py index 6168a36..37bfcbb 100644 --- a/aeat.py +++ b/aeat.py @@ -5,6 +5,7 @@ __all__ = [ 'SIIReport', 'SIIReportLine', + 'SIIReportLineTax', ] import unicodedata @@ -24,6 +25,10 @@ _logger = getLogger(__name__) _ZERO = Decimal('0.0') +def _decimal(x): + return Decimal(x) if x is not None else None + + COMMUNICATION_TYPE = [ # L0 ('A0', 'New Invoices'), ('A1', 'Modify Invoices'), @@ -543,6 +548,17 @@ class SIIReport(Workflow, ModelSQL, ModelView): reg.DatosFacturaEmitida. ClaveRegimenEspecialOTrascendencia), total_amount=reg.DatosFacturaEmitida.ImporteTotal, + taxes=tuple( + SIIReportLineTax( + base=_decimal(detail.BaseImponible), + rate=_decimal(detail.TipoImpositivo), + amount=_decimal(detail.CuotaRepercutida), + surcharge_rate=_decimal(detail.TipoRecargoEquivalencia), + surcharge_amount=_decimal(detail.CuotaRecargoEquivalencia), + ) + for detail in reg.DatosFacturaEmitida.TipoDesglose. + DesgloseFactura.Sujeta.NoExenta.DesgloseIVA.DetalleIVA + ), counterpart_name=( reg.DatosFacturaEmitida.Contraparte.NombreRazon), counterpart_id=( @@ -617,6 +633,7 @@ class SIIReport(Workflow, ModelSQL, ModelView): pool = Pool() Invoice = pool.get('account.invoice') SIIReportLine = pool.get('aeat.sii.report.lines') + SIIReportLineTax = pool.get('aeat.sii.report.line.tax') headers = mapping.get_headers( name=self.company.party.name, vat=self.company.party.vat_number, @@ -662,6 +679,19 @@ class SIIReport(Workflow, ModelSQL, ModelView): reg.DatosFacturaRecibida. ClaveRegimenEspecialOTrascendencia), total_amount=reg.DatosFacturaRecibida.ImporteTotal, + taxes=tuple( + SIIReportLineTax( + base=_decimal(detail.BaseImponible), + rate=_decimal(detail.TipoImpositivo), + amount=_decimal(detail.CuotaSoportada), + surcharge_rate=_decimal(detail.TipoRecargoEquivalencia), + surcharge_amount=_decimal(detail.CuotaRecargoEquivalencia), + reagyp_rate=_decimal(detail.PorcentCompensacionREAGYP), + reagyp_amount=_decimal(detail.ImporteCompensacionREAGYP), + ) + for detail in reg.DatosFacturaRecibida. + DesgloseFactura.DesgloseIVA.DetalleIVA + ), counterpart_name=( reg.DatosFacturaRecibida.Contraparte.NombreRazon), counterpart_id=( @@ -702,7 +732,8 @@ class SIIReportLine(ModelSQL, ModelView): total_amount = fields.Numeric('Total Amount', readonly=True) counterpart_name = fields.Char('Counterpart Name', readonly=True) counterpart_id = fields.Char('Counterpart ID', readonly=True) - # TODO: tax lines + taxes = fields.One2Many( + 'aeat.sii.report.line.tax', 'line', 'Tax Lines', readonly=True) presenter = fields.Char('Presenter', readonly=True) presentation_date = fields.Char('Presentation Date', readonly=True) csv = fields.Char('CSV', readonly=True) @@ -742,6 +773,7 @@ class SIIReportLine(ModelSQL, ModelView): default['invoice_kind'] = None default['special_key'] = None default['total_amount'] = None + default['taxes'] = None default['counterpart_name'] = None default['counterpart_id'] = None default['presenter'] = None @@ -749,3 +781,21 @@ class SIIReportLine(ModelSQL, ModelView): default['csv'] = None default['balance_state'] = None return super(SIIReportLine, cls).copy(records, default=default) + + +class SIIReportLineTax(ModelSQL, ModelView): + ''' + SII Report Line Tax + ''' + __name__ = 'aeat.sii.report.line.tax' + + line = fields.Many2One( + 'aeat.sii.report.lines', 'Report Line', ondelete='CASCADE') + + base = fields.Numeric('Base', readonly=True) + rate = fields.Numeric('Rate', readonly=True) + amount = fields.Numeric('Amount', readonly=True) + surcharge_rate = fields.Numeric('Surcharge Rate', readonly=True) + surcharge_amount = fields.Numeric('Surcharge Amount', readonly=True) + reagyp_rate = fields.Numeric('REAGYP Rate', readonly=True) + reagyp_amount = fields.Numeric('REAGYP Amount', readonly=True) diff --git a/aeat.xml b/aeat.xml index cdfbbe5..52bc48e 100644 --- a/aeat.xml +++ b/aeat.xml @@ -3,195 +3,205 @@ copyright notices and license terms. --> - - AEAT SII Administration - - - - - - - - - - - aeat.sii.report - form - sii_report_form - - - aeat.sii.report - tree - sii_report_list - - - SII Report - aeat.sii.report - - - - - - - - - - - - - - - - - - - - - - - - - - - + + AEAT SII Administration + + + + + + + + + - - - aeat.sii.report.lines - form - sii_report_lines_form - - - - aeat.sii.report.lines - tree - sii_report_lines_list - - - - AEAT SII Report Lines - aeat.sii.report.lines - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + aeat.sii.report + form + sii_report_form + + + aeat.sii.report + tree + sii_report_list + + + SII Report + aeat.sii.report + + + + + + + + + + + + + + + + + + + + + + + + + + + - - load_invoices - - + + + aeat.sii.report.lines + form + sii_report_lines_form + - - - - + + aeat.sii.report.lines + tree + sii_report_lines_list + + + + AEAT SII Report Lines + aeat.sii.report.lines + + + + + + + + + + + + - + + + + + + + + + + + + + + + - + + aeat.sii.report.line.tax + tree + sii_report_line_tax_list + - - SII Report Issued - aeat.sii.report - - - - - - SII Report Invest - aeat.sii.report - - - - + + + + + + [('company', '=', user.company.id if user.company else None)] + + - - SII Report Received - aeat.sii.report - + + + + + + [('company', '=', user.company.id if user.company else None)] + + - - - - - SII Report Intracommunity - aeat.sii.report - - - - + + load_invoices + + - - SII Report Lines - aeat.sii.report.lines - - - + + + + + + + + + + + + SII Report Issued + aeat.sii.report + [('book', '=', 'E')] + + + + + + SII Report Invest + aeat.sii.report + [('book', '=', 'I')] + + + + + + SII Report Received + aeat.sii.report + [('book', '=', 'R')] + + + + + + SII Report Intracommunity + aeat.sii.report + [('book', '=', 'U')] + + + + + + SII Report Lines + aeat.sii.report.lines + + + + diff --git a/view/sii_report_line_tax_list.xml b/view/sii_report_line_tax_list.xml new file mode 100644 index 0000000..35983fe --- /dev/null +++ b/view/sii_report_line_tax_list.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/view/sii_report_lines_form.xml b/view/sii_report_lines_form.xml index 6635c95..ee6a294 100644 --- a/view/sii_report_lines_form.xml +++ b/view/sii_report_lines_form.xml @@ -2,38 +2,39 @@
-