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.

55 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. ###############################################################################
  3. #
  4. # Module for Odoo
  5. # Copyright (C) 2015 Akretion (http://www.akretion.com).
  6. # @author Valentin CHEMIERE <valentin.chemiere@akretion.com>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ###############################################################################
  22. from openerp import api, models, fields
  23. class StockPicking(models.Model):
  24. _inherit = 'stock.picking'
  25. sms_sent = fields.Boolean()
  26. @api.model
  27. def _send_sms(self):
  28. sms_sender_obj = self.env['partner.sms.send']
  29. gateways = self.env['sms.smsclient'].search([('default_gateway', '=', True)])
  30. gateway = gateways[0]
  31. pickings = self.env['stock.picking'].search([('state', '=', 'assigned'),
  32. ('sms_sent', '=', False),
  33. ('picking_type_id.code', '=', 'outgoing')
  34. ])
  35. for pick in pickings:
  36. data = {
  37. 'gateway': gateway.id,
  38. 'text': 'Your picking %s is ready to transfert' % pick.name,
  39. 'mobile_to': pick.partner_id.phone,
  40. }
  41. sms_sender = sms_sender_obj.create(data)
  42. sms_sender.sms_send()
  43. pick.sms_sent = True
  44. @api.one
  45. def copy(self, default=None):
  46. if default is None:
  47. default = {}
  48. default['sms_sent'] = False
  49. return super(StockPicking, self).copy(default=default)