diff --git a/sms_send_picking/README.rst b/sms_send_picking/README.rst index c9264dc..faa2953 100644 --- a/sms_send_picking/README.rst +++ b/sms_send_picking/README.rst @@ -30,7 +30,7 @@ For further information, please visit: Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. +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 diff --git a/sms_send_picking/models/stock.py b/sms_send_picking/models/stock.py index 573fa07..bc58cfe 100644 --- a/sms_send_picking/models/stock.py +++ b/sms_send_picking/models/stock.py @@ -15,8 +15,9 @@ class StockPicking(models.Model): availability_sent_by_sms = fields.Boolean(default=False) # TODO use a templating instead - @api.model + @api.multi def _prepare_availability_by_sms_notification(self): + self.ensure_one() gateway = self.env['sms.gateway'].search([ ('default_gateway', '=', True)], limit=1) return { @@ -37,20 +38,25 @@ class StockPicking(models.Model): @api.model def _get_send_picking_availability_by_sms_domain(self): return [ - ('state', '=', 'assigned'), + ('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.env['stock.picking'].search(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..9f32f58 --- /dev/null +++ b/sms_send_picking/tests/test_sms_send_picking.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion France + +from openerp.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)