diff --git a/locale/de.po b/locale/de.po index 8eed6b4..c8098e7 100644 --- a/locale/de.po +++ b/locale/de.po @@ -35,6 +35,22 @@ msgid "X-Rechnung Route-ID" msgstr "X-Rechnung Leitweg-ID" +############### +# party.party # +############### +msgctxt "view:party.party:" +msgid "X-Rechnung" +msgstr "X-Rechnung" + +msgctxt "field:party.party,xrechnung_routeid:" +msgid "X-Rechnung Route-ID" +msgstr "X-Rechnung Leitweg-ID" + +msgctxt "help:party.party,xrechnung_routeid:" +msgid "Enables the need for an XRechnung route ID at the party for exporting the XRechnung." +msgstr "Aktiviert die Notwendigkeit einer XRechnung-Leitweg-ID an der Partei für den Export der XRechnung." + + ############### # account.tax # ############### diff --git a/locale/en.po b/locale/en.po index fbd1ffb..ab8715b 100644 --- a/locale/en.po +++ b/locale/en.po @@ -26,6 +26,18 @@ msgctxt "selection:party.configuration,identifier_types:" msgid "X-Rechnung Route-ID" msgstr "X-Rechnung Route-ID" +msgctxt "view:party.party:" +msgid "X-Rechnung" +msgstr "X-Rechnung" + +msgctxt "field:party.party,xrechnung_routeid:" +msgid "X-Rechnung Route-ID" +msgstr "X-Rechnung Route-ID" + +msgctxt "help:party.party,xrechnung_routeid:" +msgid "Enables the need for an XRechnung route ID at the party for exporting the XRechnung." +msgstr "Enables the need for an XRechnung route ID at the party for exporting the XRechnung." + msgctxt "field:account.tax,xrtax_category:" msgid "Tax Category" msgstr "Tax Category" @@ -66,3 +78,7 @@ msgctxt "selection:account.tax,xrtax_category:" msgid "General indirect tax of the Canary Islands" msgstr "General indirect tax of the Canary Islands" +msgctxt "selection:account.tax,xrtax_category:" +msgid "Tax on production; services and imports in Ceuta and Melilla" +msgstr "Tax on production; services and imports in Ceuta and Melilla" + diff --git a/party.py b/party.py index d35599b..cc020c6 100644 --- a/party.py +++ b/party.py @@ -6,20 +6,48 @@ from trytond.pool import PoolMeta from trytond.exceptions import UserError from trytond.i18n import gettext +from trytond.model import fields class Party(metaclass=PoolMeta): __name__ = 'party.party' + xrechnung_routeid = fields.Boolean( + string='X-Rechnung Route-ID', + help='Enables the need for an XRechnung route ID at the party ' + + 'for exporting the XRechnung.') + def get_xrechnung_route_id(self): """ search for route-id at party, fire-exception if missing """ for ident in self.identifiers: if ident.type == 'edoc_route_id': return ident.code - raise UserError(gettext( - 'edocument_xrechnung.msg_missing_xrechnung_route_id', - partyname=self.rec_name)) + + if self.xrechnung_routeid: + raise UserError(gettext( + 'edocument_xrechnung.msg_missing_xrechnung_route_id', + partyname=self.rec_name)) + + @classmethod + def default_xrechnung_routeid(cls): + """ default for needs-route-id + + Returns: + bool: default False + """ + return False + + @classmethod + def validate(cls, records): + """ validate setup of xrechnung route id + + Args: + records (list): records of party.party + """ + super(Party, cls).validate(records) + for record in records: + record.get_xrechnung_route_id() # end Party diff --git a/party.xml b/party.xml new file mode 100644 index 0000000..da53876 --- /dev/null +++ b/party.xml @@ -0,0 +1,15 @@ + + + + + + + party.party + + party_form + + + + diff --git a/setup.py b/setup.py index 931c09d..aceddc5 100644 --- a/setup.py +++ b/setup.py @@ -98,7 +98,8 @@ setup( 'trytond.modules.%s' % MODULE: ( info.get('xml', []) + ['tryton.cfg', 'locale/*.po', 'tests/*.py', - 'template/*/*.xml', 'versiondep.txt', 'README.rst']), + 'template/*/*.xml', 'versiondep.txt', 'README.rst', + 'tests/*/*/*/*.xsd']), }, install_requires=requires, diff --git a/template/XRechnung-2.2/XRechnung_credit.xml b/template/XRechnung-2.2/XRechnung_credit.xml index e12ba91..f0bf795 100644 --- a/template/XRechnung-2.2/XRechnung_credit.xml +++ b/template/XRechnung-2.2/XRechnung_credit.xml @@ -93,7 +93,7 @@ ${this.type_code} ${this.invoice_note()} ${this.invoice.currency.code} - ${this.invoice.party.get_xrechnung_route_id()} + ${this.invoice.party.get_xrechnung_route_id() or ''} ${this.invoice.reference} ${this.sales_order_nums()} diff --git a/template/XRechnung-2.2/XRechnung_invoice.xml b/template/XRechnung-2.2/XRechnung_invoice.xml index 396cf24..cf4ee6d 100644 --- a/template/XRechnung-2.2/XRechnung_invoice.xml +++ b/template/XRechnung-2.2/XRechnung_invoice.xml @@ -94,7 +94,7 @@ ${this.type_code} ${this.invoice_note()} ${this.invoice.currency.code} - ${this.invoice.party.get_xrechnung_route_id()} + ${this.invoice.party.get_xrechnung_route_id() or ''} ${this.invoice.reference} ${this.sales_order_nums()} diff --git a/template/XRechnung-2.3/XRechnung_credit.xml b/template/XRechnung-2.3/XRechnung_credit.xml index b487804..4ad9ccc 100644 --- a/template/XRechnung-2.3/XRechnung_credit.xml +++ b/template/XRechnung-2.3/XRechnung_credit.xml @@ -93,7 +93,7 @@ ${this.type_code} ${this.invoice_note()} ${this.invoice.currency.code} - ${this.invoice.party.get_xrechnung_route_id()} + ${this.invoice.party.get_xrechnung_route_id() or ''} ${this.invoice.reference} ${this.sales_order_nums()} diff --git a/template/XRechnung-2.3/XRechnung_invoice.xml b/template/XRechnung-2.3/XRechnung_invoice.xml index f3599a1..517b6e4 100644 --- a/template/XRechnung-2.3/XRechnung_invoice.xml +++ b/template/XRechnung-2.3/XRechnung_invoice.xml @@ -94,7 +94,7 @@ ${this.type_code} ${this.invoice_note()} ${this.invoice.currency.code} - ${this.invoice.party.get_xrechnung_route_id()} + ${this.invoice.party.get_xrechnung_route_id() or ''} ${this.invoice.reference} ${this.sales_order_nums()} diff --git a/template/XRechnung-3.0/XRechnung_credit.xml b/template/XRechnung-3.0/XRechnung_credit.xml index 6c3db35..102d85b 100644 --- a/template/XRechnung-3.0/XRechnung_credit.xml +++ b/template/XRechnung-3.0/XRechnung_credit.xml @@ -93,7 +93,7 @@ ${this.type_code} ${this.invoice_note()} ${this.invoice.currency.code} - ${this.invoice.party.get_xrechnung_route_id()} + ${this.invoice.party.get_xrechnung_route_id() or ''} ${this.invoice.reference} ${this.sales_order_nums()} diff --git a/template/XRechnung-3.0/XRechnung_invoice.xml b/template/XRechnung-3.0/XRechnung_invoice.xml index c25d170..9108504 100644 --- a/template/XRechnung-3.0/XRechnung_invoice.xml +++ b/template/XRechnung-3.0/XRechnung_invoice.xml @@ -94,7 +94,7 @@ ${this.type_code} ${this.invoice_note()} ${this.invoice.currency.code} - ${this.invoice.party.get_xrechnung_route_id()} + ${this.invoice.party.get_xrechnung_route_id() or ''} ${this.invoice.reference} ${this.sales_order_nums()} diff --git a/tests/test_edocument.py b/tests/test_edocument.py index 936a00d..e86e3c0 100644 --- a/tests/test_edocument.py +++ b/tests/test_edocument.py @@ -11,6 +11,7 @@ from datetime import date from trytond.tests.test_tryton import ModuleTestCase, with_transaction from trytond.pool import Pool from trytond.modules.edocument_uncefact.tests.test_edocument_uncefact import get_invoice +from trytond.exceptions import UserError from unittest.mock import Mock from decimal import Decimal @@ -19,6 +20,34 @@ class EdocTestCase(ModuleTestCase): 'Test e-rechnung module' module = 'edocument_xrechnung' + @with_transaction() + def test_xrechn_check_validator(self): + """ check validation of optional route-id + """ + Party = Pool().get('party.party') + + party, = Party.create([{'name': 'P1'}]) + self.assertEqual(party.xrechnung_routeid, False) + + Party.write(*[ + [party], + { + 'xrechnung_routeid': True, + 'identifiers': [('create', [{ + 'type': 'edoc_route_id', + 'code': '1234'}])]}]) + self.assertEqual(party.xrechnung_routeid, True) + self.assertEqual(party.get_xrechnung_route_id(), '1234') + + self.assertRaisesRegex( + UserError, + "No XRechnung routing ID is stored for the party 'P1'.", + Party.write, + *[ + [party], + {'identifiers': [('delete', [party.identifiers[0].id])]}] + ) + @with_transaction() def test_xrechn_export_xml_invoice(self): """ run export - invoice diff --git a/tryton.cfg b/tryton.cfg index 95aecba..aed6464 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -7,3 +7,4 @@ depends: account_invoice xml: message.xml + party.xml diff --git a/view/party_form.xml b/view/party_form.xml new file mode 100644 index 0000000..0bc31b7 --- /dev/null +++ b/view/party_form.xml @@ -0,0 +1,16 @@ + + + + + + + + +