changeset 317fa22aef46 in modules/account_es_sii:default
details:
https://hg.tryton.org/modules/account_es_sii?cmd=changeset&node=317fa22aef46
description:
Replace test setuptools command by unittest discover
issue9215
review389851002
diffstat:
setup.py | 6 +-
tests/__init__.py | 8 -
tests/test_account_es_sii.py | 536 -------------------------------------------
tests/test_module.py | 529 ++++++++++++++++++++++++++++++++++++++++++
tox.ini | 3 +-
5 files changed, 534 insertions(+), 548 deletions(-)
diffs (1121 lines):
diff -r 1bf5b52c83a5 -r 317fa22aef46 setup.py
--- a/setup.py Sat Apr 16 17:10:59 2022 +0200
+++ b/setup.py Sat Apr 16 18:30:16 2022 +0200
@@ -143,13 +143,13 @@
license='GPL-3',
python_requires='>=3.7',
install_requires=requires,
+ extras_require={
+ 'test': tests_require,
+ },
dependency_links=dependency_links,
zip_safe=False,
entry_points="""
[trytond.modules]
account_es_sii = trytond.modules.account_es_sii
""",
- test_suite='tests',
- test_loader='trytond.test_loader:Loader',
- tests_require=tests_require,
)
diff -r 1bf5b52c83a5 -r 317fa22aef46 tests/__init__.py
--- a/tests/__init__.py Sat Apr 16 17:10:59 2022 +0200
+++ b/tests/__init__.py Sat Apr 16 18:30:16 2022 +0200
@@ -1,10 +1,2 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
-
-try:
- from trytond.modules.account_es_sii.tests.test_account_es_sii import \
- suite # noqa: E501
-except ImportError:
- from .test_account_es_sii import suite
-
-__all__ = ['suite']
diff -r 1bf5b52c83a5 -r 317fa22aef46 tests/test_account_es_sii.py
--- a/tests/test_account_es_sii.py Sat Apr 16 17:10:59 2022 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,536 +0,0 @@
-# This file is part of Tryton. The COPYRIGHT file at the top level of
-# this repository contains the full copyright notices and license terms.
-import datetime
-import unittest
-from decimal import Decimal
-
-from trytond.modules.account.tests import create_chart, get_fiscalyear
-from trytond.modules.account_invoice.tests import set_invoice_sequences
-from trytond.modules.company.tests import create_company, set_company
-from trytond.modules.currency.tests import add_currency_rate, create_currency
-from trytond.pool import Pool
-from trytond.tests.test_tryton import ModuleTestCase
-from trytond.tests.test_tryton import suite as test_suite
-from trytond.tests.test_tryton import with_transaction
-
-today = datetime.date.today()
-
-
-def create_party(name, identifier_type, identifier_code):
- pool = Pool()
- Party = pool.get('party.party')
- party, = Party.create([{
- 'name': name,
- 'addresses': [('create', [{}])],
- 'identifiers':
- [('create', [{
- 'type': identifier_type,
- 'code': identifier_code,
- }])]}])
- return party
-
-
-def create_invoice(type_, company, party, taxes, currency=None, quantity=1):
- pool = Pool()
- Account = pool.get('account.account')
- Journal = pool.get('account.journal')
- Invoice = pool.get('account.invoice')
- InvoiceSII = pool.get('account.invoice.sii')
-
- if type_ == 'out':
- kind = 'revenue'
- invoice_account = party.account_receivable_used
- else:
- kind = 'expense'
- invoice_account = party.account_payable_used
- journal, = Journal.search([
- ('type', '=', kind),
- ], limit=1)
- line_account, = Account.search([
- ('type.%s' % kind, '=', True),
- ], limit=1)
- if currency is None:
- currency = company.currency
- invoice, = Invoice.create([{
- 'type': type_,
- 'company': company.id,
- 'currency': currency.id,
- 'party': party.id,
- 'invoice_address': party.addresses[0].id,
- 'journal': journal.id,
- 'account': invoice_account.id,
- 'invoice_date': today,
- 'lines': [
- ('create', [{
- 'currency': currency.id,
- 'account': line_account.id,
- 'quantity': quantity,
- 'unit_price': Decimal('50'),
- 'taxes': [('add', [t.id for t in taxes])],
- }]),
- ],
- }])
- Invoice.post([invoice])
- sii_invoices = InvoiceSII.search([('invoice', '=', invoice.id)])
- if sii_invoices:
- sii_invoice, = sii_invoices
- return sii_invoice
- return sii_invoices
-
-
-class AccountEsSiiTestCase(ModuleTestCase):
- "Test Account Es Sii module"
- module = 'account_es_sii'
-
- @with_transaction()
- def test_party_identifier_sii_values(self):
- "Test party identifier sii values"
-
- for type_, code, value in [
- ('eu_vat', 'ES00000000T', {'NIF': '00000000T'}),
- ('es_nif', '00000000T', {'NIF': '00000000T'}),
- ('eu_vat', 'BE0897290877', {
- 'IDOtro': {
- 'ID': 'BE0897290877',
- 'IDType': '02',
- 'CodigoPais': 'BE',
- },
- }),
- ('eu_vat', 'EL094259216', {
- 'IDOtro': {
- 'ID': 'GR094259216',
- 'IDType': '02',
- 'CodigoPais': 'GR',
- }
- }),
- ('ad_nrt', 'L709604E', {
- 'IDOtro': {
- 'ID': 'ADL709604E',
- 'IDType': '06',
- 'CodigoPais': 'AD',
- }
- }),
- ]:
-
- party = create_party('Customer', type_, code)
- self.assertDictEqual(party.tax_identifier.es_sii_values(), value)
-
- @with_transaction()
- def test_fiscalyear_sii_send_invoices(self):
- "Test Fiscalyear SII send invoices"
- pool = Pool()
- FiscalYear = pool.get('account.fiscalyear')
- company = create_company()
- with set_company(company):
- create_chart(company, chart='account_es.pgc_0_pyme')
- fiscalyear = set_invoice_sequences(get_fiscalyear(company))
- fiscalyear.save()
- FiscalYear.create_period([fiscalyear])
-
- self.assertFalse(fiscalyear.es_sii_send_invoices)
-
- fiscalyear.es_sii_send_invoices = True
- fiscalyear.save()
- self.assertTrue(fiscalyear.es_sii_send_invoices)
-
- period = fiscalyear.periods[0]
- period.es_sii_send_invoices = False
- period.save()
-
- fiscalyear = FiscalYear(fiscalyear.id)
- self.assertIsNone(fiscalyear.es_sii_send_invoices)
-
- @with_transaction()
- def test_customer_invoice_sii_payload(self):
- "Test Customer Invoice SII Payload"
- pool = Pool()
- FiscalYear = pool.get('account.fiscalyear')
- Tax = pool.get('account.tax')
- company = create_company()
- with set_company(company):
- create_chart(company, chart='account_es.pgc_0_pyme')
- fiscalyear = set_invoice_sequences(get_fiscalyear(company))
- fiscalyear.save()
- FiscalYear.create_period([fiscalyear])
- fiscalyear.es_sii_send_invoices = True
- fiscalyear.save()
- fiscalyear.es_sii_send_invoices = True
-
- party = create_party('Customer', 'eu_vat', 'ES00000000T')
- tax, = Tax.search([
- ('company', '=', company.id),
- ('name', '=', 'IVA 21% (bienes)'),
- ('group.kind', '=', 'sale'),
- ])
- sii_invoice = create_invoice('out', company, party, [tax])
-
- payload = sii_invoice.get_payload()
-
- self.assertListEqual(
- list(payload.keys()),
- ['PeriodoLiquidacion', 'IDFactura', 'FacturaExpedida'])
- self.assertEqual(
- payload['FacturaExpedida']['TipoFactura'], 'F1')
- self.assertEqual(
- payload['FacturaExpedida']['ImporteTotal'], '60.50')
- invoice_detail = {
- 'DesgloseFactura': {
- 'Sujeta': [{
- 'NoExenta': {
- 'TipoNoExenta': 'S1',
- 'DesgloseIVA': {
- 'DetalleIVA': [{
- 'BaseImponible': Decimal('50.00'),
- 'TipoImpositivo': '21.00',
- 'CuotaRepercutida': (
- Decimal('10.50')),
- }],
- },
- },
- }]
- },
- }
- self.assertDictEqual(
- payload['FacturaExpedida']['TipoDesglose'], invoice_detail)
-
- @with_transaction()
- def test_customer_invoice_excempt_sii_payload(self):
- "Test Customer Invoice Excempt SII Payload"
- pool = Pool()
- FiscalYear = pool.get('account.fiscalyear')
- Tax = pool.get('account.tax')
- company = create_company()
- with set_company(company):
- create_chart(company, chart='account_es.pgc_0_pyme')
- fiscalyear = set_invoice_sequences(get_fiscalyear(company))
- fiscalyear.save()
- FiscalYear.create_period([fiscalyear])
- fiscalyear.es_sii_send_invoices = True
- fiscalyear.save()
-
- party = create_party('Customer', 'es_nif', '00000000T')
- tax, = Tax.search([
- ('company', '=', company.id),
- ('name', '=', 'IVA Exento (bienes)'),
- ('group.kind', '=', 'sale'),
- ])
- sii_invoice = create_invoice('out', company, party, [tax])
-
- payload = sii_invoice.get_payload()
-
- invoice_detail = {
- 'DesgloseFactura': {
- 'Sujeta': [{
- 'Exenta': {
- 'DetalleExenta': {
- 'CausaExencion': 'E1',
- 'BaseImponible': Decimal('50.00'),
- },
- },
- }],
- },
- }
- self.assertDictEqual(
- payload['FacturaExpedida']['TipoDesglose'], invoice_detail)
-
- @with_transaction()
- def test_customer_surcharge_tax_invoice_sii_payload(self):
- "Test Customer Surcharge Tax Invoice SII Payload"
- pool = Pool()
- FiscalYear = pool.get('account.fiscalyear')
- Tax = pool.get('account.tax')
- company = create_company()
- with set_company(company):
- create_chart(company, chart='account_es.pgc_0_pyme')
- fiscalyear = set_invoice_sequences(get_fiscalyear(company))
- fiscalyear.save()
- FiscalYear.create_period([fiscalyear])
- fiscalyear.es_sii_send_invoices = True
- fiscalyear.save()
-
- party = create_party('Customer', 'eu_vat', 'ES00000000T')
- tax, = Tax.search([
- ('company', '=', company.id),
- ('name', '=', 'Recargo Equivalencia 1.4%'),
- ('group.kind', '=', 'sale'),
- ])
- sii_invoice = create_invoice(
- 'out', company, party, [tax.es_reported_with, tax])
-
- payload = sii_invoice.get_payload()
-
- self.assertEqual(
- payload['FacturaExpedida']['ImporteTotal'], '55.70')
- tax_detail = {
- 'DetalleIVA': [{
- 'BaseImponible': Decimal('50.00'),
- 'TipoImpositivo': '10.0',
- 'CuotaRepercutida': (
- Decimal('5.00')),
- 'TipoRecargoEquivalencia': '1.4',
- 'CuotaRecargoEquivalencia': (
- Decimal('0.70')),
- },
- ],
- }
- self.assertDictEqual(
- payload['FacturaExpedida']['TipoDesglose']['DesgloseFactura'][
- 'Sujeta'][0]['NoExenta']['DesgloseIVA'], tax_detail)
-
- @with_transaction()
- def test_customer_intracomunitary_invoice_sii_payload(self):
- "Test Customer Intracomunitary Invoice Excempt SII Payload"
- pool = Pool()
- FiscalYear = pool.get('account.fiscalyear')
- Tax = pool.get('account.tax')
- company = create_company()
- with set_company(company):
- create_chart(company, chart='account_es.pgc_0_pyme')
- fiscalyear = set_invoice_sequences(get_fiscalyear(company))
- fiscalyear.save()
- FiscalYear.create_period([fiscalyear])
- fiscalyear.es_sii_send_invoices = True
- fiscalyear.save()
-
- party = create_party('Customer', 'eu_vat', 'BE0897290877')
- tax, = Tax.search([
- ('company', '=', company.id),
- ('name', '=', 'IVA Intracomunitario (bienes)'),
- ('group.kind', '=', 'sale'),
- ])
- sii_invoice = create_invoice('out', company, party, [tax])
-
- payload = sii_invoice.get_payload()
-
- invoice_detail = {
- 'Entrega': {
- 'Sujeta': [{
- 'Exenta': {
- 'DetalleExenta': {
- 'CausaExencion': 'E5',
- 'BaseImponible': Decimal('50.00'),
- },
- },
- }],
- },
- }
- self.assertDictEqual(
- payload['FacturaExpedida']['TipoDesglose'][
- 'DesgloseTipoOperacion'], invoice_detail)
-
- @with_transaction()
- def test_customer_invoice_alternate_currency_sii_payload(self):
- "Test Customer Invoice Alternate Currency SII Payload"
- pool = Pool()
- FiscalYear = pool.get('account.fiscalyear')
- Tax = pool.get('account.tax')
- company = create_company()
- with set_company(company):
- create_chart(company, chart='account_es.pgc_0_pyme')
- fiscalyear = set_invoice_sequences(get_fiscalyear(company))
- fiscalyear.save()
- FiscalYear.create_period([fiscalyear])
- fiscalyear.es_sii_send_invoices = True
- fiscalyear.save()
-
- currency = create_currency('gbp')
- add_currency_rate(currency, 2)
-
- party = create_party('Customer', 'eu_vat', 'ES00000000T')
- tax, = Tax.search([
- ('company', '=', company.id),
- ('name', '=', 'IVA 21% (bienes)'),
- ('group.kind', '=', 'sale'),
- ])
- sii_invoice = create_invoice(
- 'out', company, party, [tax], currency=currency)
-
- payload = sii_invoice.get_payload()
-
- self.assertEqual(
- payload['FacturaExpedida']['ImporteTotal'], '30.25')
- tax_detail = {
- 'DetalleIVA': [{
- 'BaseImponible': Decimal('25.00'),
- 'TipoImpositivo': '21.00',
- 'CuotaRepercutida': (
- Decimal('5.25')),
- },
- ],
- }
- self.assertDictEqual(
- payload['FacturaExpedida']['TipoDesglose']['DesgloseFactura'][
- 'Sujeta'][0]['NoExenta']['DesgloseIVA'], tax_detail)
-
- @with_transaction()
- def test_customer_credit_note_sii_payload(self):
- "Test Customer Credit Note SII Payload"
- pool = Pool()
- FiscalYear = pool.get('account.fiscalyear')
- Tax = pool.get('account.tax')
- company = create_company()
- with set_company(company):
- create_chart(company, chart='account_es.pgc_0_pyme')
- fiscalyear = set_invoice_sequences(get_fiscalyear(company))
- fiscalyear.save()
- FiscalYear.create_period([fiscalyear])
- fiscalyear.es_sii_send_invoices = True
- fiscalyear.save()
-
- party = create_party('Customer', 'eu_vat', 'ES00000000T')
- tax, = Tax.search([
- ('company', '=', company.id),
- ('name', '=', 'IVA 21% (bienes)'),
- ('group.kind', '=', 'sale'),
- ])
- sii_invoice = create_invoice(
- 'out', company, party, [tax], quantity=-1)
-
- payload = sii_invoice.get_payload()
-
- self.assertEqual(
- payload['FacturaExpedida']['ImporteTotal'], '-60.50')
- self.assertEqual(
- payload['FacturaExpedida']['TipoFactura'], 'R1')
- self.assertEqual(
- payload['FacturaExpedida']['TipoRectificativa'], 'I')
- tax_detail = {
- 'DetalleIVA': [{
- 'BaseImponible': Decimal('-50.00'),
- 'TipoImpositivo': '21.00',
- 'CuotaRepercutida': (
- Decimal('-10.50')),
- },
- ],
- }
- self.assertDictEqual(
- payload['FacturaExpedida']['TipoDesglose']['DesgloseFactura'][
- 'Sujeta'][0]['NoExenta']['DesgloseIVA'], tax_detail)
-
- @with_transaction()
- def test_supplier_invoice_sii_payload(self):
- "Test Supplier Invoice SII Payload"
- pool = Pool()
- FiscalYear = pool.get('account.fiscalyear')
- Tax = pool.get('account.tax')
- company = create_company()
- with set_company(company):
- create_chart(company, chart='account_es.pgc_0_pyme')
- fiscalyear = set_invoice_sequences(get_fiscalyear(company))
- fiscalyear.save()
- FiscalYear.create_period([fiscalyear])
- fiscalyear.es_sii_send_invoices = True
- fiscalyear.save()
-
- party = create_party('Supplier', 'eu_vat', 'ES00000000T')
- tax, = Tax.search([
- ('company', '=', company.id),
- ('name', '=', 'IVA 10% (bienes)'),
- ('group.kind', '=', 'purchase'),
- ])
- sii_invoice = create_invoice('in', company, party, [tax])
-
- payload = sii_invoice.get_payload()
-
- self.assertListEqual(
- list(payload.keys()),
- ['PeriodoLiquidacion', 'IDFactura', 'FacturaRecibida'])
- self.assertEqual(
- payload['FacturaRecibida']['TipoFactura'], 'F1')
- self.assertEqual(
- payload['FacturaRecibida'][
- 'ClaveRegimenEspecialOTrascendencia'], '01')
- self.assertEqual(
- payload['FacturaRecibida']['ImporteTotal'], '55.00')
- self.assertEqual(
- payload['FacturaRecibida']['CuotaDeducible'], '5.00')
-
- invoice_detail = {
- 'DesgloseIVA': {
- 'DetalleIVA': [{
- 'BaseImponible': Decimal('50.00'),
- 'TipoImpositivo': '10.0',
- 'CuotaSoportada': Decimal('5.00')}]}}
- self.assertDictEqual(
- payload['FacturaRecibida']['DesgloseFactura'], invoice_detail)
-
- @with_transaction()
- def test_supplier_intracomunitary_invoice_sii_payload(self):
- "Test Supplier Intracomunitary Invoice SII Payload"
- pool = Pool()
- FiscalYear = pool.get('account.fiscalyear')
- Tax = pool.get('account.tax')
- company = create_company()
- with set_company(company):
- create_chart(company, chart='account_es.pgc_0_pyme')
- fiscalyear = set_invoice_sequences(get_fiscalyear(company))
- fiscalyear.save()
- FiscalYear.create_period([fiscalyear])
- fiscalyear.es_sii_send_invoices = True
- fiscalyear.save()
-
- party = create_party('Supplier', 'eu_vat', 'BE0897290877')
- tax, = Tax.search([
- ('company', '=', company.id),
- ('name', '=', 'IVA Intracomunitario 21% (bienes)'),
- ('group.kind', '=', 'purchase'),
- ])
- sii_invoice = create_invoice('in', company, party, [tax])
-
- payload = sii_invoice.get_payload()
-
- self.assertListEqual(
- list(payload.keys()),
- ['PeriodoLiquidacion', 'IDFactura', 'FacturaRecibida'])
- self.assertEqual(
- payload['FacturaRecibida']['TipoFactura'], 'F1')
- self.assertEqual(
- payload['FacturaRecibida'][
- 'ClaveRegimenEspecialOTrascendencia'], '09')
- self.assertEqual(
- payload['FacturaRecibida']['ImporteTotal'], '60.50')
- self.assertEqual(
- payload['FacturaRecibida']['CuotaDeducible'], '10.50')
-
- invoice_detail = {
- 'DesgloseIVA': {
- 'DetalleIVA': [{
- 'BaseImponible': Decimal('50.00'),
- 'TipoImpositivo': '21.00',
- 'CuotaSoportada': Decimal('10.50')}]}}
- self.assertDictEqual(
- payload['FacturaRecibida']['DesgloseFactura'], invoice_detail)
-
- @with_transaction()
- def test_taxes_excluded_from_sii_taxes(self):
- "Test Taxes excluded from SII"
- pool = Pool()
- FiscalYear = pool.get('account.fiscalyear')
- Tax = pool.get('account.tax')
- company = create_company()
- with set_company(company):
- create_chart(company, chart='account_es.pgc_0_pyme')
- fiscalyear = set_invoice_sequences(get_fiscalyear(company))
- fiscalyear.save()
- FiscalYear.create_period([fiscalyear])
- fiscalyear.es_sii_send_invoices = True
- fiscalyear.save()
-
- party = create_party('Supplier', 'eu_vat', 'BE0897290877')
- tax, = Tax.search([
- ('company', '=', company.id),
- ('name', '=', 'IVA Importaciones (bienes)'),
- ('group.kind', '=', 'purchase'),
- ])
- self.assertTrue(tax.es_exclude_from_sii)
-
- sii_invoice = create_invoice('in', company, party, [tax])
-
- self.assertEqual(sii_invoice, [])
-
-
-def suite():
- suite = test_suite()
- suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
- AccountEsSiiTestCase))
- return suite
diff -r 1bf5b52c83a5 -r 317fa22aef46 tests/test_module.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_module.py Sat Apr 16 18:30:16 2022 +0200
@@ -0,0 +1,529 @@
+# This file is part of Tryton. The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+import datetime
+from decimal import Decimal
+
+from trytond.modules.account.tests import create_chart, get_fiscalyear
+from trytond.modules.account_invoice.tests import set_invoice_sequences
+from trytond.modules.company.tests import create_company, set_company
+from trytond.modules.currency.tests import add_currency_rate, create_currency
+from trytond.pool import Pool
+from trytond.tests.test_tryton import ModuleTestCase, with_transaction
+
+today = datetime.date.today()
+
+
+def create_party(name, identifier_type, identifier_code):
+ pool = Pool()
+ Party = pool.get('party.party')
+ party, = Party.create([{
+ 'name': name,
+ 'addresses': [('create', [{}])],
+ 'identifiers':
+ [('create', [{
+ 'type': identifier_type,
+ 'code': identifier_code,
+ }])]}])
+ return party
+
+
+def create_invoice(type_, company, party, taxes, currency=None, quantity=1):
+ pool = Pool()
+ Account = pool.get('account.account')
+ Journal = pool.get('account.journal')
+ Invoice = pool.get('account.invoice')
+ InvoiceSII = pool.get('account.invoice.sii')
+
+ if type_ == 'out':
+ kind = 'revenue'
+ invoice_account = party.account_receivable_used
+ else:
+ kind = 'expense'
+ invoice_account = party.account_payable_used
+ journal, = Journal.search([
+ ('type', '=', kind),
+ ], limit=1)
+ line_account, = Account.search([
+ ('type.%s' % kind, '=', True),
+ ], limit=1)
+ if currency is None:
+ currency = company.currency
+ invoice, = Invoice.create([{
+ 'type': type_,
+ 'company': company.id,
+ 'currency': currency.id,
+ 'party': party.id,
+ 'invoice_address': party.addresses[0].id,
+ 'journal': journal.id,
+ 'account': invoice_account.id,
+ 'invoice_date': today,
+ 'lines': [
+ ('create', [{
+ 'currency': currency.id,
+ 'account': line_account.id,
+ 'quantity': quantity,
+ 'unit_price': Decimal('50'),
+ 'taxes': [('add', [t.id for t in taxes])],
+ }]),
+ ],
+ }])
+ Invoice.post([invoice])
+ sii_invoices = InvoiceSII.search([('invoice', '=', invoice.id)])
+ if sii_invoices:
+ sii_invoice, = sii_invoices
+ return sii_invoice
+ return sii_invoices
+
+
+class AccountEsSiiTestCase(ModuleTestCase):
+ "Test Account Es Sii module"
+ module = 'account_es_sii'
+
+ @with_transaction()
+ def test_party_identifier_sii_values(self):
+ "Test party identifier sii values"
+
+ for type_, code, value in [
+ ('eu_vat', 'ES00000000T', {'NIF': '00000000T'}),
+ ('es_nif', '00000000T', {'NIF': '00000000T'}),
+ ('eu_vat', 'BE0897290877', {
+ 'IDOtro': {
+ 'ID': 'BE0897290877',
+ 'IDType': '02',
+ 'CodigoPais': 'BE',
+ },
+ }),
+ ('eu_vat', 'EL094259216', {
+ 'IDOtro': {
+ 'ID': 'GR094259216',
+ 'IDType': '02',
+ 'CodigoPais': 'GR',
+ }
+ }),
+ ('ad_nrt', 'L709604E', {
+ 'IDOtro': {
+ 'ID': 'ADL709604E',
+ 'IDType': '06',
+ 'CodigoPais': 'AD',
+ }
+ }),
+ ]:
+
+ party = create_party('Customer', type_, code)
+ self.assertDictEqual(party.tax_identifier.es_sii_values(), value)
+
+ @with_transaction()
+ def test_fiscalyear_sii_send_invoices(self):
+ "Test Fiscalyear SII send invoices"
+ pool = Pool()
+ FiscalYear = pool.get('account.fiscalyear')
+ company = create_company()
+ with set_company(company):
+ create_chart(company, chart='account_es.pgc_0_pyme')
+ fiscalyear = set_invoice_sequences(get_fiscalyear(company))
+ fiscalyear.save()
+ FiscalYear.create_period([fiscalyear])
+
+ self.assertFalse(fiscalyear.es_sii_send_invoices)
+
+ fiscalyear.es_sii_send_invoices = True
+ fiscalyear.save()
+ self.assertTrue(fiscalyear.es_sii_send_invoices)
+
+ period = fiscalyear.periods[0]
+ period.es_sii_send_invoices = False
+ period.save()
+
+ fiscalyear = FiscalYear(fiscalyear.id)
+ self.assertIsNone(fiscalyear.es_sii_send_invoices)
+
+ @with_transaction()
+ def test_customer_invoice_sii_payload(self):
+ "Test Customer Invoice SII Payload"
+ pool = Pool()
+ FiscalYear = pool.get('account.fiscalyear')
+ Tax = pool.get('account.tax')
+ company = create_company()
+ with set_company(company):
+ create_chart(company, chart='account_es.pgc_0_pyme')
+ fiscalyear = set_invoice_sequences(get_fiscalyear(company))
+ fiscalyear.save()
+ FiscalYear.create_period([fiscalyear])
+ fiscalyear.es_sii_send_invoices = True
+ fiscalyear.save()
+ fiscalyear.es_sii_send_invoices = True
+
+ party = create_party('Customer', 'eu_vat', 'ES00000000T')
+ tax, = Tax.search([
+ ('company', '=', company.id),
+ ('name', '=', 'IVA 21% (bienes)'),
+ ('group.kind', '=', 'sale'),
+ ])
+ sii_invoice = create_invoice('out', company, party, [tax])
+
+ payload = sii_invoice.get_payload()
+
+ self.assertListEqual(
+ list(payload.keys()),
+ ['PeriodoLiquidacion', 'IDFactura', 'FacturaExpedida'])
+ self.assertEqual(
+ payload['FacturaExpedida']['TipoFactura'], 'F1')
+ self.assertEqual(
+ payload['FacturaExpedida']['ImporteTotal'], '60.50')
+ invoice_detail = {
+ 'DesgloseFactura': {
+ 'Sujeta': [{
+ 'NoExenta': {
+ 'TipoNoExenta': 'S1',
+ 'DesgloseIVA': {
+ 'DetalleIVA': [{
+ 'BaseImponible': Decimal('50.00'),
+ 'TipoImpositivo': '21.00',
+ 'CuotaRepercutida': (
+ Decimal('10.50')),
+ }],
+ },
+ },
+ }]
+ },
+ }
+ self.assertDictEqual(
+ payload['FacturaExpedida']['TipoDesglose'], invoice_detail)
+
+ @with_transaction()
+ def test_customer_invoice_excempt_sii_payload(self):
+ "Test Customer Invoice Excempt SII Payload"
+ pool = Pool()
+ FiscalYear = pool.get('account.fiscalyear')
+ Tax = pool.get('account.tax')
+ company = create_company()
+ with set_company(company):
+ create_chart(company, chart='account_es.pgc_0_pyme')
+ fiscalyear = set_invoice_sequences(get_fiscalyear(company))
+ fiscalyear.save()
+ FiscalYear.create_period([fiscalyear])
+ fiscalyear.es_sii_send_invoices = True
+ fiscalyear.save()
+
+ party = create_party('Customer', 'es_nif', '00000000T')
+ tax, = Tax.search([
+ ('company', '=', company.id),
+ ('name', '=', 'IVA Exento (bienes)'),
+ ('group.kind', '=', 'sale'),
+ ])
+ sii_invoice = create_invoice('out', company, party, [tax])
+
+ payload = sii_invoice.get_payload()
+
+ invoice_detail = {
+ 'DesgloseFactura': {
+ 'Sujeta': [{
+ 'Exenta': {
+ 'DetalleExenta': {
+ 'CausaExencion': 'E1',
+ 'BaseImponible': Decimal('50.00'),
+ },
+ },
+ }],
+ },
+ }
+ self.assertDictEqual(
+ payload['FacturaExpedida']['TipoDesglose'], invoice_detail)
+
+ @with_transaction()
+ def test_customer_surcharge_tax_invoice_sii_payload(self):
+ "Test Customer Surcharge Tax Invoice SII Payload"
+ pool = Pool()
+ FiscalYear = pool.get('account.fiscalyear')
+ Tax = pool.get('account.tax')
+ company = create_company()
+ with set_company(company):
+ create_chart(company, chart='account_es.pgc_0_pyme')
+ fiscalyear = set_invoice_sequences(get_fiscalyear(company))
+ fiscalyear.save()
+ FiscalYear.create_period([fiscalyear])
+ fiscalyear.es_sii_send_invoices = True
+ fiscalyear.save()
+
+ party = create_party('Customer', 'eu_vat', 'ES00000000T')
+ tax, = Tax.search([
+ ('company', '=', company.id),
+ ('name', '=', 'Recargo Equivalencia 1.4%'),
+ ('group.kind', '=', 'sale'),
+ ])
+ sii_invoice = create_invoice(
+ 'out', company, party, [tax.es_reported_with, tax])
+
+ payload = sii_invoice.get_payload()
+
+ self.assertEqual(
+ payload['FacturaExpedida']['ImporteTotal'], '55.70')
+ tax_detail = {
+ 'DetalleIVA': [{
+ 'BaseImponible': Decimal('50.00'),
+ 'TipoImpositivo': '10.0',
+ 'CuotaRepercutida': (
+ Decimal('5.00')),
+ 'TipoRecargoEquivalencia': '1.4',
+ 'CuotaRecargoEquivalencia': (
+ Decimal('0.70')),
+ },
+ ],
+ }
+ self.assertDictEqual(
+ payload['FacturaExpedida']['TipoDesglose']['DesgloseFactura'][
+ 'Sujeta'][0]['NoExenta']['DesgloseIVA'], tax_detail)
+
+ @with_transaction()
+ def test_customer_intracomunitary_invoice_sii_payload(self):
+ "Test Customer Intracomunitary Invoice Excempt SII Payload"
+ pool = Pool()
+ FiscalYear = pool.get('account.fiscalyear')
+ Tax = pool.get('account.tax')
+ company = create_company()
+ with set_company(company):
+ create_chart(company, chart='account_es.pgc_0_pyme')
+ fiscalyear = set_invoice_sequences(get_fiscalyear(company))
+ fiscalyear.save()
+ FiscalYear.create_period([fiscalyear])
+ fiscalyear.es_sii_send_invoices = True
+ fiscalyear.save()
+
+ party = create_party('Customer', 'eu_vat', 'BE0897290877')
+ tax, = Tax.search([
+ ('company', '=', company.id),
+ ('name', '=', 'IVA Intracomunitario (bienes)'),
+ ('group.kind', '=', 'sale'),
+ ])
+ sii_invoice = create_invoice('out', company, party, [tax])
+
+ payload = sii_invoice.get_payload()
+
+ invoice_detail = {
+ 'Entrega': {
+ 'Sujeta': [{
+ 'Exenta': {
+ 'DetalleExenta': {
+ 'CausaExencion': 'E5',
+ 'BaseImponible': Decimal('50.00'),
+ },
+ },
+ }],
+ },
+ }
+ self.assertDictEqual(
+ payload['FacturaExpedida']['TipoDesglose'][
+ 'DesgloseTipoOperacion'], invoice_detail)
+
+ @with_transaction()
+ def test_customer_invoice_alternate_currency_sii_payload(self):
+ "Test Customer Invoice Alternate Currency SII Payload"
+ pool = Pool()
+ FiscalYear = pool.get('account.fiscalyear')
+ Tax = pool.get('account.tax')
+ company = create_company()
+ with set_company(company):
+ create_chart(company, chart='account_es.pgc_0_pyme')
+ fiscalyear = set_invoice_sequences(get_fiscalyear(company))
+ fiscalyear.save()
+ FiscalYear.create_period([fiscalyear])
+ fiscalyear.es_sii_send_invoices = True
+ fiscalyear.save()
+
+ currency = create_currency('gbp')
+ add_currency_rate(currency, 2)
+
+ party = create_party('Customer', 'eu_vat', 'ES00000000T')
+ tax, = Tax.search([
+ ('company', '=', company.id),
+ ('name', '=', 'IVA 21% (bienes)'),
+ ('group.kind', '=', 'sale'),
+ ])
+ sii_invoice = create_invoice(
+ 'out', company, party, [tax], currency=currency)
+
+ payload = sii_invoice.get_payload()
+
+ self.assertEqual(
+ payload['FacturaExpedida']['ImporteTotal'], '30.25')
+ tax_detail = {
+ 'DetalleIVA': [{
+ 'BaseImponible': Decimal('25.00'),
+ 'TipoImpositivo': '21.00',
+ 'CuotaRepercutida': (
+ Decimal('5.25')),
+ },
+ ],
+ }
+ self.assertDictEqual(
+ payload['FacturaExpedida']['TipoDesglose']['DesgloseFactura'][
+ 'Sujeta'][0]['NoExenta']['DesgloseIVA'], tax_detail)
+
+ @with_transaction()
+ def test_customer_credit_note_sii_payload(self):
+ "Test Customer Credit Note SII Payload"
+ pool = Pool()
+ FiscalYear = pool.get('account.fiscalyear')
+ Tax = pool.get('account.tax')
+ company = create_company()
+ with set_company(company):
+ create_chart(company, chart='account_es.pgc_0_pyme')
+ fiscalyear = set_invoice_sequences(get_fiscalyear(company))
+ fiscalyear.save()
+ FiscalYear.create_period([fiscalyear])
+ fiscalyear.es_sii_send_invoices = True
+ fiscalyear.save()
+
+ party = create_party('Customer', 'eu_vat', 'ES00000000T')
+ tax, = Tax.search([
+ ('company', '=', company.id),
+ ('name', '=', 'IVA 21% (bienes)'),
+ ('group.kind', '=', 'sale'),
+ ])
+ sii_invoice = create_invoice(
+ 'out', company, party, [tax], quantity=-1)
+
+ payload = sii_invoice.get_payload()
+
+ self.assertEqual(
+ payload['FacturaExpedida']['ImporteTotal'], '-60.50')
+ self.assertEqual(
+ payload['FacturaExpedida']['TipoFactura'], 'R1')
+ self.assertEqual(
+ payload['FacturaExpedida']['TipoRectificativa'], 'I')
+ tax_detail = {
+ 'DetalleIVA': [{
+ 'BaseImponible': Decimal('-50.00'),
+ 'TipoImpositivo': '21.00',
+ 'CuotaRepercutida': (
+ Decimal('-10.50')),
+ },
+ ],
+ }
+ self.assertDictEqual(
+ payload['FacturaExpedida']['TipoDesglose']['DesgloseFactura'][
+ 'Sujeta'][0]['NoExenta']['DesgloseIVA'], tax_detail)
+
+ @with_transaction()
+ def test_supplier_invoice_sii_payload(self):
+ "Test Supplier Invoice SII Payload"
+ pool = Pool()
+ FiscalYear = pool.get('account.fiscalyear')
+ Tax = pool.get('account.tax')
+ company = create_company()
+ with set_company(company):
+ create_chart(company, chart='account_es.pgc_0_pyme')
+ fiscalyear = set_invoice_sequences(get_fiscalyear(company))
+ fiscalyear.save()
+ FiscalYear.create_period([fiscalyear])
+ fiscalyear.es_sii_send_invoices = True
+ fiscalyear.save()
+
+ party = create_party('Supplier', 'eu_vat', 'ES00000000T')
+ tax, = Tax.search([
+ ('company', '=', company.id),
+ ('name', '=', 'IVA 10% (bienes)'),
+ ('group.kind', '=', 'purchase'),
+ ])
+ sii_invoice = create_invoice('in', company, party, [tax])
+
+ payload = sii_invoice.get_payload()
+
+ self.assertListEqual(
+ list(payload.keys()),
+ ['PeriodoLiquidacion', 'IDFactura', 'FacturaRecibida'])
+ self.assertEqual(
+ payload['FacturaRecibida']['TipoFactura'], 'F1')
+ self.assertEqual(
+ payload['FacturaRecibida'][
+ 'ClaveRegimenEspecialOTrascendencia'], '01')
+ self.assertEqual(
+ payload['FacturaRecibida']['ImporteTotal'], '55.00')
+ self.assertEqual(
+ payload['FacturaRecibida']['CuotaDeducible'], '5.00')
+
+ invoice_detail = {
+ 'DesgloseIVA': {
+ 'DetalleIVA': [{
+ 'BaseImponible': Decimal('50.00'),
+ 'TipoImpositivo': '10.0',
+ 'CuotaSoportada': Decimal('5.00')}]}}
+ self.assertDictEqual(
+ payload['FacturaRecibida']['DesgloseFactura'], invoice_detail)
+
+ @with_transaction()
+ def test_supplier_intracomunitary_invoice_sii_payload(self):
+ "Test Supplier Intracomunitary Invoice SII Payload"
+ pool = Pool()
+ FiscalYear = pool.get('account.fiscalyear')
+ Tax = pool.get('account.tax')
+ company = create_company()
+ with set_company(company):
+ create_chart(company, chart='account_es.pgc_0_pyme')
+ fiscalyear = set_invoice_sequences(get_fiscalyear(company))
+ fiscalyear.save()
+ FiscalYear.create_period([fiscalyear])
+ fiscalyear.es_sii_send_invoices = True
+ fiscalyear.save()
+
+ party = create_party('Supplier', 'eu_vat', 'BE0897290877')
+ tax, = Tax.search([
+ ('company', '=', company.id),
+ ('name', '=', 'IVA Intracomunitario 21% (bienes)'),
+ ('group.kind', '=', 'purchase'),
+ ])
+ sii_invoice = create_invoice('in', company, party, [tax])
+
+ payload = sii_invoice.get_payload()
+
+ self.assertListEqual(
+ list(payload.keys()),
+ ['PeriodoLiquidacion', 'IDFactura', 'FacturaRecibida'])
+ self.assertEqual(
+ payload['FacturaRecibida']['TipoFactura'], 'F1')
+ self.assertEqual(
+ payload['FacturaRecibida'][
+ 'ClaveRegimenEspecialOTrascendencia'], '09')
+ self.assertEqual(
+ payload['FacturaRecibida']['ImporteTotal'], '60.50')
+ self.assertEqual(
+ payload['FacturaRecibida']['CuotaDeducible'], '10.50')
+
+ invoice_detail = {
+ 'DesgloseIVA': {
+ 'DetalleIVA': [{
+ 'BaseImponible': Decimal('50.00'),
+ 'TipoImpositivo': '21.00',
+ 'CuotaSoportada': Decimal('10.50')}]}}
+ self.assertDictEqual(
+ payload['FacturaRecibida']['DesgloseFactura'], invoice_detail)
+
+ @with_transaction()
+ def test_taxes_excluded_from_sii_taxes(self):
+ "Test Taxes excluded from SII"
+ pool = Pool()
+ FiscalYear = pool.get('account.fiscalyear')
+ Tax = pool.get('account.tax')
+ company = create_company()
+ with set_company(company):
+ create_chart(company, chart='account_es.pgc_0_pyme')
+ fiscalyear = set_invoice_sequences(get_fiscalyear(company))
+ fiscalyear.save()
+ FiscalYear.create_period([fiscalyear])
+ fiscalyear.es_sii_send_invoices = True
+ fiscalyear.save()
+
+ party = create_party('Supplier', 'eu_vat', 'BE0897290877')
+ tax, = Tax.search([
+ ('company', '=', company.id),
+ ('name', '=', 'IVA Importaciones (bienes)'),
+ ('group.kind', '=', 'purchase'),
+ ])
+ self.assertTrue(tax.es_exclude_from_sii)
+
+ sii_invoice = create_invoice('in', company, party, [tax])
+
+ self.assertEqual(sii_invoice, [])
+
+
+del ModuleTestCase
diff -r 1bf5b52c83a5 -r 317fa22aef46 tox.ini
--- a/tox.ini Sat Apr 16 17:10:59 2022 +0200
+++ b/tox.ini Sat Apr 16 18:30:16 2022 +0200
@@ -2,8 +2,9 @@
envlist = {py37,py38,py39,py310}-{sqlite,postgresql}
[testenv]
+extras = test
commands =
- coverage run --include=.*/account_es_sii/* setup.py test
+ coverage run --include=.*/account_es_sii/* -m unittest discover -s tests
coverage report --include=.*/account_es_sii/* --omit=*/tests/*
deps =
coverage