diff --git a/locale/de.po b/locale/de.po index ecc828d..d8156a9 100644 --- a/locale/de.po +++ b/locale/de.po @@ -30,6 +30,18 @@ msgctxt "model:ir.message,text:msg_linetax_invalid_catcode" msgid "Invalid category code at tax '%(taxname)s' (allowed: %(allowed)s)." msgstr "Ungültiger Kategoriecode an der Steuer '%(taxname)s' (erlaubt: %(allowed)s)." +msgctxt "model:ir.message,text:msg_no_seller_address" +msgid "There is no address for the seller party '%(sellerparty)s'." +msgstr "Für die Verkäuferpartei '%(sellerparty)s' existiert keine Adresse." + +msgctxt "model:ir.message,text:msg_no_buyer_address" +msgid "There is no address for the buyer party '%(buyerparty)s'." +msgstr "Für die Käuferpartei '%(sellerparty)s' existiert keine Adresse." + +msgctxt "model:ir.message,text:msg_no_address_country" +msgid "No country is specified for the address of the party '%(party)s'." +msgstr "Für die Adresse der Partei '%(party)s' ist kein Land festgelegt." + ####################### # party.configuration # diff --git a/locale/en.po b/locale/en.po index 465895a..a4978ea 100644 --- a/locale/en.po +++ b/locale/en.po @@ -26,6 +26,18 @@ msgctxt "model:ir.message,text:msg_linetax_invalid_catcode" msgid "Invalid category code at tax '%(taxname)s' (allowed: %(allowed)s)." msgstr "Invalid category code at tax '%(taxname)s' (allowed: %(allowed)s)." +msgctxt "model:ir.message,text:msg_no_seller_address" +msgid "There is no address for the seller party '%(sellerparty)s'." +msgstr "There is no address for the seller party '%(sellerparty)s'." + +msgctxt "model:ir.message,text:msg_no_buyer_address" +msgid "There is no address for the buyer party '%(buyerparty)s'." +msgstr "There is no address for the buyer party '%(buyerparty)s'." + +msgctxt "model:ir.message,text:msg_no_address_country" +msgid "No country is specified for the address of the party '%(party)s'." +msgstr "No country is specified for the address of the party '%(party)s'." + msgctxt "selection:party.configuration,identifier_types:" msgid "X-Rechnung Route-ID" msgstr "X-Rechnung Route-ID" diff --git a/message.xml b/message.xml index f2c47db..aa557fd 100644 --- a/message.xml +++ b/message.xml @@ -23,6 +23,15 @@ full copyright notices and license terms. --> Invalid category code at tax '%(taxname)s' (allowed: %(allowed)s). + + There is no address for the seller party '%(sellerparty)s'. + + + There is no address for the buyer party '%(buyerparty)s'. + + + No country is specified for the address of the party '%(party)s'. + diff --git a/mixin.py b/mixin.py index adcb478..f27804f 100644 --- a/mixin.py +++ b/mixin.py @@ -8,6 +8,7 @@ from decimal import Decimal import html from trytond.exceptions import UserError from trytond.i18n import gettext +from trytond.tools import cached_property class EdocumentMixin(object): @@ -15,6 +16,52 @@ class EdocumentMixin(object): """ __slots__ = () + @cached_property + def seller_trade_address(self): + """ get address of seller, throw exception if incomplete + + Raises: + UserError: if no address + UserError: if no country on address + + Returns: + record : model party.address + """ + result = super(EdocumentMixin, self).seller_trade_address + if not result: + raise UserError(gettext( + 'edocument_xrechnung.msg_no_seller_address', + sellerparty=self.invoice.company.rec_name + if self.invoice and self.invoice.company + else '-')) + if not result.country: + raise UserError(gettext( + 'edocument_xrechnung.msg_no_address_country', + party=result.party)) + return result + + @cached_property + def buyer_trade_address(self): + """ exception if no address + + Returns: + record: model party.address + """ + if (self.invoice.type == 'out') and ( + not self.invoice.invoice_address): + raise UserError(gettext( + 'edocument_xrechnung.msg_no_buyer_address', + buyerparty=self.invoice.party.rec_name + if self.invoice and self.invoice.party + else '-')) + + result = super(EdocumentMixin, self).buyer_trade_address + if result and not result.country: + raise UserError(gettext( + 'edocument_xrechnung.msg_no_address_country', + party=result.party)) + return result + def get_list_of_comments(self): """ comment, to export in