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.

82 lines
2.8 KiB

8 years ago
  1. # coding: utf-8
  2. # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
  3. # Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.fr>
  4. # Copyright (C) 2015 Valentin Chemiere <valentin.chemiere@akretion.com>
  5. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  6. from odoo import models, fields, api
  7. class WizardMassSms(models.TransientModel):
  8. _name = 'wizard.mass.sms'
  9. @api.model
  10. def _default_get_gateway(self):
  11. return self.env['sms.gateway'].search([], limit=1).id
  12. @api.model
  13. def _default_get_partner(self):
  14. if self._context.get('active_model') == 'res.partner':
  15. return self._context.get('active_ids')
  16. gateway_id = fields.Many2one(
  17. 'sms.gateway',
  18. required=True,
  19. default=_default_get_gateway)
  20. message = fields.Text(required=True)
  21. validity = fields.Integer(
  22. help='The maximum time -in minute(s)- before the message is dropped')
  23. classes = fields.Selection([
  24. ('0', 'Flash'),
  25. ('1', 'Phone display'),
  26. ('2', 'SIM'),
  27. ('3', 'Toolkit'),
  28. ], help='The sms class: flash(0),phone display(1),SIM(2),toolkit(3)')
  29. deferred = fields.Integer(
  30. help='The time -in minute(s)- to wait before sending the message')
  31. priority = fields.Selection([
  32. ('0', '0'),
  33. ('1', '1'),
  34. ('2', '2'),
  35. ('3', '3')
  36. ], help='The priority of the message')
  37. coding = fields.Selection([
  38. ('1', '7 bit'),
  39. ('2', 'Unicode')
  40. ], help='The sms coding: 1 for 7 bit or 2 for unicode')
  41. tag = fields.Char(size=256, help='An optional tag')
  42. nostop = fields.Boolean(
  43. help='Do not display STOP clause in the message, this requires that '
  44. 'this is not an advertising message')
  45. partner_ids = fields.Many2many('res.partner', default=_default_get_partner)
  46. @api.onchange('gateway_id')
  47. def onchange_gateway_mass(self):
  48. for key in ['validity', 'classes', 'deferred', 'priority',
  49. 'coding', 'tag', 'nostop']:
  50. self[key] = self.gateway_id[key]
  51. @api.model
  52. def _prepare_sms_vals(self, partner):
  53. return {
  54. 'gateway_id': self.gateway_id.id,
  55. 'state': 'draft',
  56. 'message': self.message,
  57. 'validity': self.validity,
  58. 'classes': self.classes,
  59. 'deferred': self.deferred,
  60. 'priority': self.priority,
  61. 'coding': self.coding,
  62. 'tag': self.tag,
  63. 'nostop': self.nostop,
  64. 'partner_id': partner.id,
  65. 'mobile': partner.mobile,
  66. }
  67. @api.multi
  68. def send(self):
  69. sms_obj = self.env['sms.sms']
  70. partner_obj = self.env['res.partner']
  71. for partner in partner_obj.browse(self._context.get('active_ids')):
  72. vals = self._prepare_sms_vals(partner)
  73. sms_obj.create(vals)