diff --git a/sms_send_picking/README.rst b/sms_send_picking/README.rst new file mode 100644 index 0000000..faa2953 --- /dev/null +++ b/sms_send_picking/README.rst @@ -0,0 +1,61 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +================= +SMS send picking +================= + +This module provides a cron and a method to automaticly sending a SMS when a +picking delivery is ready to transfert. + + +Configuration +============= + +You can configure the verification time in the scheduled action. + +Usage +===== + +To use this module, you need to: + +* have a gateway correctly configured with keychain account +* put some picking delivery in ready to transfert state + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback + + +Credits +======= + +Contributors +------------ + +* Valentin Chemiere +* MonsieurB + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. + diff --git a/sms_send_picking/__init__.py b/sms_send_picking/__init__.py new file mode 100644 index 0000000..f3af6e4 --- /dev/null +++ b/sms_send_picking/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2015 Valentin CHEMIERE +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/sms_send_picking/__manifest__.py b/sms_send_picking/__manifest__.py new file mode 100644 index 0000000..d2dab0b --- /dev/null +++ b/sms_send_picking/__manifest__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# © 2015 Valentin CHEMIERE +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Sms Send Picking', + 'version': '10.0.1.0.0', + 'author': 'Akretion, Odoo Community Association (OCA)', + 'website': 'www.akretion.com', + 'license': 'AGPL-3', + 'category': 'Phone', + 'depends': [ + 'stock', + 'base_sms_client', + ], + 'data': [ + 'data/cron.xml' + ], + 'installable': True, + 'application': False, +} diff --git a/sms_send_picking/data/cron.xml b/sms_send_picking/data/cron.xml new file mode 100644 index 0000000..f30f988 --- /dev/null +++ b/sms_send_picking/data/cron.xml @@ -0,0 +1,16 @@ + + + + + Auto Send SMS Picking Ready + 5 + minutes + -1 + False + stock.picking + _cron_send_picking_availability_by_sms + () + + + + diff --git a/sms_send_picking/i18n/fr.po b/sms_send_picking/i18n/fr.po new file mode 100644 index 0000000..2029fe8 --- /dev/null +++ b/sms_send_picking/i18n/fr.po @@ -0,0 +1,33 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sms_send_picking +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-09-04 13:28+0000\n" +"PO-Revision-Date: 2015-09-04 13:28+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: sms_send_picking +#: model:ir.model,name:sms_send_picking.model_stock_picking +msgid "Picking List" +msgstr "Opération de manutention" + +#. module: sms_send_picking +#: field:stock.picking,sms_sent:0 +msgid "Sms sent" +msgstr "Sms envoyé" + +#. module: sms_send_picking +#: code:addons/sms_send_picking/stock.py:44 +#, python-format +msgid "Your picking %s is ready to transfert" +msgstr "Votre commande %s est prète a être retiré" + diff --git a/sms_send_picking/models/__init__.py b/sms_send_picking/models/__init__.py new file mode 100644 index 0000000..5e98a3c --- /dev/null +++ b/sms_send_picking/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2015 Valentin CHEMIERE +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import stock diff --git a/sms_send_picking/models/stock.py b/sms_send_picking/models/stock.py new file mode 100644 index 0000000..bc58cfe --- /dev/null +++ b/sms_send_picking/models/stock.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# © 2015 Valentin CHEMIERE +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models, fields +from odoo.tools.translate import _ +import logging + +_logger = logging.getLogger(__name__) + + +class StockPicking(models.Model): + _inherit = 'stock.picking' + + availability_sent_by_sms = fields.Boolean(default=False) + + # TODO use a templating instead + @api.multi + def _prepare_availability_by_sms_notification(self): + self.ensure_one() + gateway = self.env['sms.gateway'].search([ + ('default_gateway', '=', True)], limit=1) + return { + 'gateway_id': gateway.id, + 'message': _('Your picking %s is ready to transfer.') % self.name, + 'mobile': self.partner_id.mobile, + 'partner_id': self.partner_id.id, + 'state': 'draft', + 'validity': gateway.validity, + 'classes': gateway.classes, + 'deferred': gateway.deferred, + 'priority': gateway.priority, + 'coding': gateway.coding, + 'nostop': gateway.nostop, + 'company_id': self.company_id.id, + } + + @api.model + def _get_send_picking_availability_by_sms_domain(self): + return [ + ('state', '=', 'assigned'), # assigned = available + ('availability_sent_by_sms', '=', False), + ('picking_type_id.code', '=', 'outgoing'), + ] + + @api.model + def _cron_send_picking_availability_by_sms(self): + domain = self._get_send_picking_availability_by_sms_domain() + pickings = self.search(domain) + total = len(pickings) + for idx, picking in enumerate(pickings): + _logger.debug('Send Sms for picking %s, progress %s/%s', picking, + idx, total) + vals = picking._prepare_availability_by_sms_notification() + if not vals['mobile']: + _logger.warning( + _("SMS issue for picking %s : no mobile phone" + % picking.id)) + continue + self.env['sms.sms'].create(vals) + picking.write({'availability_sent_by_sms': True}) + picking._cr.commit() diff --git a/sms_send_picking/tests/__init__.py b/sms_send_picking/tests/__init__.py new file mode 100644 index 0000000..0ce5b43 --- /dev/null +++ b/sms_send_picking/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sms_send_picking \ No newline at end of file diff --git a/sms_send_picking/tests/test_sms_send_picking.py b/sms_send_picking/tests/test_sms_send_picking.py new file mode 100644 index 0000000..c331248 --- /dev/null +++ b/sms_send_picking/tests/test_sms_send_picking.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion France + +from odoo.tests.common import TransactionCase + + +class TestSmsSendPicking(TransactionCase): + + def setUp(self): + super(TestSmsSendPicking, self).setUp() + self.partner = self.env['res.partner'].create({ + 'name': 'test man', + 'mobile': '336789123', + 'email': 'testcustomer+3@test.com', + }) + self.product = self.env.ref('product.product_product_4') + self.picking_out = self.env['stock.picking'].create({ + 'picking_type_id': self.ref('stock.picking_type_out'), + 'location_id': self.env.ref('stock.stock_location_stock').id, + 'location_dest_id': ( + self.env.ref('stock.stock_location_customers').id + ), + 'partner_id': self.partner.id + }) + self.env['stock.move'].create({ + 'name': 'a move', + 'product_id': self.product.id, + 'product_uom_qty': 3.0, + 'product_uom': self.product.uom_id.id, + 'picking_id': self.picking_out.id, + 'location_id': self.env.ref('stock.stock_location_stock').id, + 'location_dest_id': ( + self.env.ref('stock.stock_location_customers').id + ) + }) + self.picking_out.action_assign() + self.picking_out.force_assign() + + def test_availability_flag(self): + self.assertEqual(False, self.picking_out.availability_sent_by_sms) + self.picking_out._cron_send_picking_availability_by_sms() + self.assertEqual(True, self.picking_out.availability_sent_by_sms) + + def test_sms_created(self): + dom = [('message', 'ilike', + 'Your picking %s %%' % self.picking_out.name)] + self.assertTrue(len(self.env['sms.sms'].search(dom)) == 0) + self.picking_out._cron_send_picking_availability_by_sms() + self.assertTrue(len(self.env['sms.sms'].search(dom)) == 1)