From 1d653dc03b6c8f8aed719cc1628c6d39fd329b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 29 Dec 2018 14:20:29 +0100 Subject: [PATCH] Add ir.message and use custom exceptions issue3672 --- bank.py | 10 ++++++---- exceptions.py | 8 ++++++++ message.xml | 10 ++++++++++ tryton.cfg | 1 + 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 exceptions.py create mode 100644 message.xml diff --git a/bank.py b/bank.py index 0df5ed0799..d87bf42ba0 100644 --- a/bank.py +++ b/bank.py @@ -3,9 +3,12 @@ from stdnum import iban from sql import operators, Literal +from trytond.i18n import gettext from trytond.model import ( ModelView, ModelSQL, DeactivableMixin, fields, sequence_ordered) +from .exceptions import IBANValidationError + __all__ = ['Bank', 'BankAccount', 'BankAccountNumber', 'BankAccountParty'] @@ -63,9 +66,6 @@ class BankAccountNumber(sequence_ordered(), ModelSQL, ModelView): def __setup__(cls): super(BankAccountNumber, cls).__setup__() cls._order.insert(0, ('account', 'ASC')) - cls._error_messages.update({ - 'invalid_iban': 'Invalid IBAN "%s".', - }) @classmethod def default_type(cls): @@ -139,7 +139,9 @@ class BankAccountNumber(sequence_ordered(), ModelSQL, ModelView): super(BankAccountNumber, self).pre_validate() if (self.type == 'iban' and self.number and not iban.is_valid(self.number)): - self.raise_user_error('invalid_iban', self.number) + raise IBANValidationError( + gettext('bank.msg_invalid_iban', + number=self.number)) class BankAccountParty(ModelSQL): diff --git a/exceptions.py b/exceptions.py new file mode 100644 index 0000000000..857162d304 --- /dev/null +++ b/exceptions.py @@ -0,0 +1,8 @@ +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. + +from trytond.model.exceptions import ValidationError + + +class IBANValidationError(ValidationError): + pass diff --git a/message.xml b/message.xml new file mode 100644 index 0000000000..dc5c4d67db --- /dev/null +++ b/message.xml @@ -0,0 +1,10 @@ + + + + + + IBAN number "%(number)s" is not valid. + + + diff --git a/tryton.cfg b/tryton.cfg index a727d619dd..7c4f51fe57 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -7,3 +7,4 @@ depends: xml: bank.xml party.xml + message.xml