Add ir.message and use UserWarning/UserError
This commit is contained in:
parent
cb8a3d614d
commit
4c13095dc8
22
account.py
22
account.py
|
@ -3,6 +3,8 @@
|
|||
# the full copyright notices and license terms.
|
||||
from trytond.model import fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.i18n import gettext
|
||||
from trytond.exceptions import UserError
|
||||
|
||||
__all__ = ['Configuration', 'ConfigurationDefaultAccount', 'AccountTemplate',
|
||||
'Account', 'CreateChartAccount', 'CreateChart', 'UpdateChartStart',
|
||||
|
@ -67,15 +69,6 @@ class AccountTemplate(metaclass=PoolMeta):
|
|||
class Account(metaclass=PoolMeta):
|
||||
__name__ = 'account.account'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Account, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'invalid_code_digits': ('The number of code digits '
|
||||
'%(account_digits)d of account "%(account)s" must be '
|
||||
'%(digits)d.'),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def validate(cls, accounts):
|
||||
pool = Pool()
|
||||
|
@ -90,12 +83,11 @@ class Account(metaclass=PoolMeta):
|
|||
# Only the first item of code is checked: "570000 (1)" -> "570000"
|
||||
code = self.code.split(' ')[0]
|
||||
if self.kind != 'view' and len(code) != digits:
|
||||
self.raise_user_error('invalid_code_digits', error_args={
|
||||
'account_digits': len(code),
|
||||
'account': self.rec_name,
|
||||
'digits': digits,
|
||||
})
|
||||
|
||||
raise UserError(gettext(
|
||||
'account_code_digits.invalid_code_digits',
|
||||
account_digits=len(code),
|
||||
account=self.rec_name,
|
||||
digits=digits))
|
||||
|
||||
class CreateChartAccount(metaclass=PoolMeta):
|
||||
__name__ = 'account.create_chart.account'
|
||||
|
|
|
@ -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="invalid_code_digits">
|
||||
<field name="text">The number of code digits %(account_digits)d of account "%(account)s" must be %(digits)d.</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
|
@ -6,3 +6,4 @@ depends:
|
|||
account
|
||||
xml:
|
||||
account.xml
|
||||
message.xml
|
||||
|
|
Loading…
Reference in New Issue