You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.2 KiB

  1. # coding: utf-8
  2. # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
  3. # Copyright (C) 2011 SYLEAM (<http://syleam.fr/>)
  4. # Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.fr>
  5. # Copyright (C) 2015 Valentin Chemiere <valentin.chemiere@akretion.com>
  6. # Copyright (C) 2015 Sébastien BEAU <sebastien.beau@akretion.com>
  7. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  8. from odoo import models, fields, api
  9. PRIORITY_LIST = [
  10. ('0', '0'),
  11. ('1', '1'),
  12. ('2', '2'),
  13. ('3', '3')
  14. ]
  15. CLASSES_LIST = [
  16. ('0', 'Flash'),
  17. ('1', 'Phone display'),
  18. ('2', 'SIM'),
  19. ('3', 'Toolkit')
  20. ]
  21. class SmsAbstract(models.AbstractModel):
  22. _name = 'sms.abstract'
  23. _description = 'SMS Abstract Model'
  24. code = fields.Char('Verification Code')
  25. body = fields.Text(
  26. string='Message',
  27. help="The message text that will be send along with the"
  28. " email which is send through this server.")
  29. classes = fields.Selection(
  30. selection=CLASSES_LIST, string='Class',
  31. default='1',
  32. help='The SMS class')
  33. deferred = fields.Integer(
  34. help='The time -in minute(s)- to wait before sending the message.')
  35. priority = fields.Selection(
  36. selection=PRIORITY_LIST, string='Priority', default='3',
  37. help='The priority of the message')
  38. coding = fields.Selection(selection=[
  39. ('1', '7 bit'),
  40. ('2', 'Unicode')
  41. ], string='Coding',
  42. help='The SMS coding: 1 for 7 bit (160 chracters max'
  43. 'length) or 2 for unicode (70 characters max'
  44. 'length)',
  45. default='1'
  46. )
  47. tag = fields.Char('Tag', help='an optional tag')
  48. nostop = fields.Boolean(
  49. default=True,
  50. help='Do not display STOP clause in the message, this requires that '
  51. 'this is not an advertising message.')
  52. validity = fields.Integer(
  53. default=10,
  54. help="The maximum time - in minute(s) - before the message "
  55. "is dropped.")
  56. char_limit = fields.Integer(string='Character Limit', default=160)
  57. default_gateway = fields.Boolean()
  58. company_id = fields.Many2one(comodel_name='res.company')
  59. class SmsGateway(models.Model):
  60. _name = 'sms.gateway'
  61. _description = 'SMS Client'
  62. _inherit = 'sms.abstract'
  63. name = fields.Char(string='Gateway Name', required=True)
  64. from_provider = fields.Char(string="From")
  65. method = fields.Selection(string='API Method', selection=[])
  66. url = fields.Char(
  67. string='Gateway URL', help='Base url for message')
  68. state = fields.Selection(selection=[
  69. ('new', 'Not Verified'),
  70. ('waiting', 'Waiting for Verification'),
  71. ('confirm', 'Verified'),
  72. ], string='Gateway Status', index=True, readonly=True, default='new')
  73. user_ids = fields.Many2many(
  74. comodel_name='res.users',
  75. string='Users Allowed to use the gateway')
  76. @api.multi
  77. def _check_permissions(self):
  78. self.ensure_one()
  79. if self.env.uid not in self.sudo().user_ids.ids:
  80. return False
  81. return True
  82. @api.model
  83. def _run_send_sms(self, domain=None):
  84. if domain is None:
  85. domain = []
  86. domain.append(('state', '=', 'draft'))
  87. sms = self.env['sms.sms'].search(domain)
  88. return sms.send()