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.

66 lines
2.5 KiB

9 years ago
  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. from openerp.tools.translate import _
  24. class StockPicking(models.Model):
  25. _inherit = 'stock.picking'
  26. availability_sent_by_sms = fields.Boolean(default=False)
  27. #TODO use a templating instead
  28. @api.model
  29. def _prepare_availability_sms_notification(self):
  30. gateway = self.env['sms.gateway'].search([
  31. ('default_gateway', '=', True)], limit=1)
  32. return {
  33. 'gateway': gateway.id,
  34. 'message': _('Your picking %s is ready to transfert') % pick.name,
  35. 'mobile': self.partner_id.phone,
  36. 'partner_id': self.partner_id.id,
  37. 'state': 'draft',
  38. 'validity': gateway.validity,
  39. 'classes': gateway.classes,
  40. 'deferred': gateway.deferred,
  41. 'priority': gateway.priority,
  42. 'coding': gateway.coding,
  43. 'nostop': gateway.nostop,
  44. }
  45. @api.model
  46. def _get_send_picking_availability_sms_domain(self):
  47. return [
  48. ('state', '=', 'assigned'),
  49. ('availability_sent_by_sms', '=', False),
  50. ('picking_type_id.code', '=', 'outgoing'),
  51. ]
  52. @api.model
  53. def _cron_send_picking_availability_by_sms(self):
  54. domain = self._get_send_picking_availability_sms_domain()
  55. pickings = self.env['stock.picking'].search(domain)
  56. for picking in pickings:
  57. vals = picking._prepare_availability_sms_notification()
  58. self.env['sms.sms'].create(vals)
  59. pickings.write({'availability_sent_by_sms': True})