Add ir.message and use custom exceptions
issue3672
This commit is contained in:
1 parent
755eb04925
commit
1d653dc03b
4 files changed
+25
-4
No files matched your search
@@ -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):
|
||||
|
||||
@@ -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
|
||||
+10
@@ -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>
|
||||
@@ -7,3 +7,4 @@ depends:
|
||||
xml:
|
||||
bank.xml
|
||||
party.xml
|
||||
message.xml
|
||||
Reference in new issue
Block a user