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.

97 lines
3.6 KiB

  1. ##############################################################################
  2. #
  3. # OpenERP, Open Source Management Solution
  4. # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>)
  5. # Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.fr>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>
  19. #
  20. ##############################################################################
  21. from openerp import models, fields, api
  22. class WizardSendSms(models.TransientModel):
  23. _name = 'wizard.send.sms'
  24. @api.model
  25. def _default_get_gateway(self):
  26. return self.env['sms.gateway'].search([], limit=1).id
  27. @api.model
  28. def _default_get_partner(self):
  29. if self._context.get('active_model') == 'res.partner':
  30. return self._context.get('active_ids')
  31. @api.onchange('gateway_id')
  32. def onchange_gateway_mass(self):
  33. for key in ['validity', 'classes', 'deferred', 'priority',
  34. 'coding', 'tag', 'nostop']:
  35. self[key] = self.gateway_id[key]
  36. @api.model
  37. def _prepare_sms_vals(self, partner):
  38. return {
  39. 'gateway_id': self.gateway_id.id,
  40. 'state': 'draft',
  41. 'message': self.message,
  42. 'validity': self.validity,
  43. 'classes': self.classes,
  44. 'deferred': self.deferred,
  45. 'priority': self.priority,
  46. 'coding': self.coding,
  47. 'tag': self.tag,
  48. 'nostop': self.nostop,
  49. 'partner_id': partner.id,
  50. 'mobile': partner.mobile,
  51. }
  52. @api.multi
  53. def send(self):
  54. sms_obj = self.env['sms.sms']
  55. partner_obj = self.env['res.partner']
  56. for partner in partner_obj.browse(self._context.get('active_ids')):
  57. vals = self._prepare_sms_vals(partner)
  58. sms_obj.create(vals)
  59. gateway_id = fields.Many2one(
  60. 'sms.gateway',
  61. required=True,
  62. default=_default_get_gateway)
  63. message = fields.Text(required=True)
  64. validity = fields.Integer(
  65. help='The maximum time -in minute(s)- before the message is dropped')
  66. classes = fields.Selection([
  67. ('0', 'Flash'),
  68. ('1', 'Phone display'),
  69. ('2', 'SIM'),
  70. ('3', 'Toolkit'),
  71. ], help='The sms class: flash(0),phone display(1),SIM(2),toolkit(3)')
  72. deferred = fields.Integer(
  73. help='The time -in minute(s)- to wait before sending the message')
  74. priority = fields.Selection([
  75. ('0', '0'),
  76. ('1', '1'),
  77. ('2', '2'),
  78. ('3', '3')
  79. ], help='The priority of the message')
  80. coding = fields.Selection([
  81. ('1', '7 bit'),
  82. ('2', 'Unicode')
  83. ], help='The sms coding: 1 for 7 bit or 2 for unicode')
  84. tag = fields.Char(size=256, help='An optional tag')
  85. nostop = fields.Boolean(
  86. help='Do not display STOP clause in the message, this requires that '
  87. 'this is not an advertising message')
  88. partner_ids = fields.Many2many('res.partner', default=_default_get_partner)