changeset eda8ec460896 in modules/bank:default
details: https://hg.tryton.org/modules/bank?cmd=changeset;node=eda8ec460896
description:
        Add ir.message and use custom exceptions

        issue3672
diffstat:

 bank.py       |  10 ++++++----
 exceptions.py |   8 ++++++++
 message.xml   |  10 ++++++++++
 tryton.cfg    |   1 +
 4 files changed, 25 insertions(+), 4 deletions(-)

diffs (71 lines):

diff -r 243933d4270c -r eda8ec460896 bank.py
--- a/bank.py   Mon Oct 01 12:38:44 2018 +0200
+++ b/bank.py   Sat Dec 29 14:20:29 2018 +0100
@@ -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 @@
     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 @@
         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 -r 243933d4270c -r eda8ec460896 exceptions.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/exceptions.py     Sat Dec 29 14:20:29 2018 +0100
@@ -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 -r 243933d4270c -r eda8ec460896 message.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/message.xml       Sat Dec 29 14:20:29 2018 +0100
@@ -0,0 +1,10 @@
+<?xml version="1.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. -->
+<tryton>
+    <data group="1">
+        <record model="ir.message" id="msg_invalid_iban">
+            <field name="text">IBAN number "%(number)s" is not valid.</field>
+        </record>
+    </data>
+</tryton>
diff -r 243933d4270c -r eda8ec460896 tryton.cfg
--- a/tryton.cfg        Mon Oct 01 12:38:44 2018 +0200
+++ b/tryton.cfg        Sat Dec 29 14:20:29 2018 +0100
@@ -7,3 +7,4 @@
 xml:
     bank.xml
     party.xml
+    message.xml

Reply via email to