Browse Source

Merge pull request #2 from akretion/10.0-mig-sms_send_picking

Fix minors remarks and add tests
pull/130/head
MonsieurB 7 years ago
committed by GitHub
parent
commit
da70d29f07
  1. 2
      sms_send_picking/README.rst
  2. 14
      sms_send_picking/models/stock.py
  3. 1
      sms_send_picking/tests/__init__.py
  4. 49
      sms_send_picking/tests/test_sms_send_picking.py

2
sms_send_picking/README.rst

@ -30,7 +30,7 @@ For further information, please visit:
Bug Tracker Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/{project_repo}/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/connector-telephony/issues>`_.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us smashing it by providing a detailed and welcomed feedback

14
sms_send_picking/models/stock.py

@ -15,8 +15,9 @@ class StockPicking(models.Model):
availability_sent_by_sms = fields.Boolean(default=False) availability_sent_by_sms = fields.Boolean(default=False)
# TODO use a templating instead # TODO use a templating instead
@api.model
@api.multi
def _prepare_availability_by_sms_notification(self): def _prepare_availability_by_sms_notification(self):
self.ensure_one()
gateway = self.env['sms.gateway'].search([ gateway = self.env['sms.gateway'].search([
('default_gateway', '=', True)], limit=1) ('default_gateway', '=', True)], limit=1)
return { return {
@ -37,20 +38,25 @@ class StockPicking(models.Model):
@api.model @api.model
def _get_send_picking_availability_by_sms_domain(self): def _get_send_picking_availability_by_sms_domain(self):
return [ return [
('state', '=', 'assigned'),
('state', '=', 'assigned'), # assigned = available
('availability_sent_by_sms', '=', False), ('availability_sent_by_sms', '=', False),
('picking_type_id.code', '=', 'outgoing'), ('picking_type_id.code', '=', 'outgoing'),
]
]
@api.model @api.model
def _cron_send_picking_availability_by_sms(self): def _cron_send_picking_availability_by_sms(self):
domain = self._get_send_picking_availability_by_sms_domain() domain = self._get_send_picking_availability_by_sms_domain()
pickings = self.env['stock.picking'].search(domain)
pickings = self.search(domain)
total = len(pickings) total = len(pickings)
for idx, picking in enumerate(pickings): for idx, picking in enumerate(pickings):
_logger.debug('Send Sms for picking %s, progress %s/%s', picking, _logger.debug('Send Sms for picking %s, progress %s/%s', picking,
idx, total) idx, total)
vals = picking._prepare_availability_by_sms_notification() 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) self.env['sms.sms'].create(vals)
picking.write({'availability_sent_by_sms': True}) picking.write({'availability_sent_by_sms': True})
picking._cr.commit() picking._cr.commit()

1
sms_send_picking/tests/__init__.py

@ -0,0 +1 @@
from . import test_sms_send_picking

49
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)
Loading…
Cancel
Save