Add ir.message and use custom exceptions
issue3672
This commit is contained in:
1 parent
7f103ddf43
commit
ac0a7d1ac5
3 files changed
+14
-12
No files matched your search
+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_sms_text">
|
||||
<field name="text">%(name)s code %(code)s</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
@@ -6,6 +6,7 @@ import random
|
||||
|
||||
from trytond.config import config
|
||||
from trytond.exceptions import LoginException
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import ModelSQL, fields
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.tools import resolve
|
||||
@@ -69,13 +70,6 @@ class SMSCode(ModelSQL):
|
||||
user = fields.Function(fields.Many2One('res.user', 'User'), 'get_user')
|
||||
code = fields.Char('Code')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(SMSCode, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'sms_text': '%(name)s code %(code)s',
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def default_code(cls):
|
||||
length = config.getint('authentication_sms', 'length', default=6)
|
||||
@@ -106,11 +100,8 @@ class SMSCode(ModelSQL):
|
||||
record = cls(user_id=user)
|
||||
record.save()
|
||||
name = config.get('authentication_sms', 'name', default='Tryton')
|
||||
text = cls.raise_user_error(
|
||||
'sms_text', {
|
||||
'name': name,
|
||||
'code': record.code,
|
||||
}, raise_exception=False)
|
||||
text = gettext('authentication_sms.msg_sms_text',
|
||||
name=name, code=record.code)
|
||||
if mobile:
|
||||
send_sms(text, mobile)
|
||||
elif record.user.mobile:
|
||||
|
||||
@@ -5,3 +5,4 @@ depends:
|
||||
res
|
||||
xml:
|
||||
res.xml
|
||||
message.xml
|
||||
Reference in new issue
Block a user