From 9c011850180fbbdd9c0af7fd7f2c3396321baf1e Mon Sep 17 00:00:00 2001 From: Valentin Chemiere Date: Tue, 4 Aug 2015 16:40:33 +0200 Subject: [PATCH 01/16] Add only delivery filter, rename the module --- sms_send_picking/__init__.py | 1 + sms_send_picking/__openerp__.py | 45 +++++++++++++++++++++++++++ sms_send_picking/cron.xml | 15 +++++++++ sms_send_picking/stock.py | 55 +++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 sms_send_picking/__init__.py create mode 100644 sms_send_picking/__openerp__.py create mode 100644 sms_send_picking/cron.xml create mode 100644 sms_send_picking/stock.py diff --git a/sms_send_picking/__init__.py b/sms_send_picking/__init__.py new file mode 100644 index 0000000..12bab77 --- /dev/null +++ b/sms_send_picking/__init__.py @@ -0,0 +1 @@ +from . import stock diff --git a/sms_send_picking/__openerp__.py b/sms_send_picking/__openerp__.py new file mode 100644 index 0000000..2f8b8bd --- /dev/null +++ b/sms_send_picking/__openerp__.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# Module for Odoo +# Copyright (C) 2015 Akretion (http://www.akretion.com). +# @author Valentin CHEMIERE +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################### + +{'name': 'Sms Send Picking', + 'version': '0.0.1', + 'author': 'Akretion', + 'website': 'www.akretion.com', + 'license': 'AGPL-3', + 'category': 'Generic Modules', + 'description': """ + Automatic sms sending when a delivery is ready to transfert + """, + 'depends': [ + 'stock', + 'smsclient_core', + ], + 'data': [ + 'cron.xml' + ], + 'installable': True, + 'application': False, +} + + + + diff --git a/sms_send_picking/cron.xml b/sms_send_picking/cron.xml new file mode 100644 index 0000000..5e649ca --- /dev/null +++ b/sms_send_picking/cron.xml @@ -0,0 +1,15 @@ + + + + + Auto Send SMS Picking Ready + 5 + minutes + -1 + + + + + + + diff --git a/sms_send_picking/stock.py b/sms_send_picking/stock.py new file mode 100644 index 0000000..3022140 --- /dev/null +++ b/sms_send_picking/stock.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# Module for Odoo +# Copyright (C) 2015 Akretion (http://www.akretion.com). +# @author Valentin CHEMIERE +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################### + +from openerp import api, models, fields + + +class StockPicking(models.Model): + _inherit = 'stock.picking' + + sms_sent = fields.Boolean() + + @api.model + def _send_sms(self): + sms_sender_obj = self.env['partner.sms.send'] + gateways = self.env['sms.smsclient'].search([('default_gateway', '=', True)]) + gateway = gateways[0] + pickings = self.env['stock.picking'].search([('state', '=', 'assigned'), + ('sms_sent', '=', False), + ('picking_type_id.code', '=', 'outgoing') + ]) + for pick in pickings: + data = { + 'gateway': gateway.id, + 'text': 'Your picking %s is ready to transfert' % pick.name, + 'mobile_to': pick.partner_id.phone, + } + sms_sender = sms_sender_obj.create(data) + sms_sender.sms_send() + pick.sms_sent = True + + @api.one + def copy(self, default=None): + if default is None: + default = {} + default['sms_sent'] = False + return super(StockPicking, self).copy(default=default) From 992b41062a5465ed29835a97e730a4ea5a921b49 Mon Sep 17 00:00:00 2001 From: Valentin Chemiere Date: Tue, 4 Aug 2015 17:44:36 +0200 Subject: [PATCH 02/16] Fix flake 8 --- sms_send_picking/__openerp__.py | 41 +++++++++++++++------------------ sms_send_picking/stock.py | 10 ++++---- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/sms_send_picking/__openerp__.py b/sms_send_picking/__openerp__.py index 2f8b8bd..5bf5063 100644 --- a/sms_send_picking/__openerp__.py +++ b/sms_send_picking/__openerp__.py @@ -20,26 +20,23 @@ # ############################################################################### -{'name': 'Sms Send Picking', - 'version': '0.0.1', - 'author': 'Akretion', - 'website': 'www.akretion.com', - 'license': 'AGPL-3', - 'category': 'Generic Modules', - 'description': """ - Automatic sms sending when a delivery is ready to transfert - """, - 'depends': [ - 'stock', - 'smsclient_core', - ], - 'data': [ - 'cron.xml' - ], - 'installable': True, - 'application': False, +{ + 'name': 'Sms Send Picking', + 'version': '0.0.1', + 'author': 'Akretion', + 'website': 'www.akretion.com', + 'license': 'AGPL-3', + 'category': 'Generic Modules', + 'description': """ + Automatic sms sending when a delivery is ready to transfert + """, + 'depends': [ + 'stock', + 'smsclient_core', + ], + 'data': [ + 'cron.xml' + ], + 'installable': True, + 'application': False, } - - - - diff --git a/sms_send_picking/stock.py b/sms_send_picking/stock.py index 3022140..5e1a6f7 100644 --- a/sms_send_picking/stock.py +++ b/sms_send_picking/stock.py @@ -31,12 +31,12 @@ class StockPicking(models.Model): @api.model def _send_sms(self): sms_sender_obj = self.env['partner.sms.send'] - gateways = self.env['sms.smsclient'].search([('default_gateway', '=', True)]) + gateways = self.env['sms.smsclient'].search([('default_gateway', '=', + True)]) gateway = gateways[0] - pickings = self.env['stock.picking'].search([('state', '=', 'assigned'), - ('sms_sent', '=', False), - ('picking_type_id.code', '=', 'outgoing') - ]) + pickings = self.env['stock.picking'].search( + [('state', '=', 'assigned'), ('sms_sent', '=', False), + ('picking_type_id.code', '=', 'outgoing')]) for pick in pickings: data = { 'gateway': gateway.id, From dbc3de272dedf83faaf8a857609e8dfe1fc2bd8f Mon Sep 17 00:00:00 2001 From: Valentin Chemiere Date: Tue, 4 Aug 2015 18:33:31 +0200 Subject: [PATCH 03/16] Fixing multiple comments from @yvaucher --- sms_send_picking/__openerp__.py | 4 ++-- sms_send_picking/stock.py | 11 ++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/sms_send_picking/__openerp__.py b/sms_send_picking/__openerp__.py index 5bf5063..cc1c42f 100644 --- a/sms_send_picking/__openerp__.py +++ b/sms_send_picking/__openerp__.py @@ -23,10 +23,10 @@ { 'name': 'Sms Send Picking', 'version': '0.0.1', - 'author': 'Akretion', + 'author': 'Akretion, OCA', 'website': 'www.akretion.com', 'license': 'AGPL-3', - 'category': 'Generic Modules', + 'category': 'Phone', 'description': """ Automatic sms sending when a delivery is ready to transfert """, diff --git a/sms_send_picking/stock.py b/sms_send_picking/stock.py index 5e1a6f7..bb6573e 100644 --- a/sms_send_picking/stock.py +++ b/sms_send_picking/stock.py @@ -26,13 +26,13 @@ from openerp import api, models, fields class StockPicking(models.Model): _inherit = 'stock.picking' - sms_sent = fields.Boolean() + sms_sent = fields.Boolean(default=False) @api.model def _send_sms(self): sms_sender_obj = self.env['partner.sms.send'] gateways = self.env['sms.smsclient'].search([('default_gateway', '=', - True)]) + True)], limit=1) gateway = gateways[0] pickings = self.env['stock.picking'].search( [('state', '=', 'assigned'), ('sms_sent', '=', False), @@ -46,10 +46,3 @@ class StockPicking(models.Model): sms_sender = sms_sender_obj.create(data) sms_sender.sms_send() pick.sms_sent = True - - @api.one - def copy(self, default=None): - if default is None: - default = {} - default['sms_sent'] = False - return super(StockPicking, self).copy(default=default) From 0bee89e419abe527f5d752b7ce60bfaa2b5255d2 Mon Sep 17 00:00:00 2001 From: Valentin Chemiere Date: Tue, 4 Aug 2015 19:39:33 +0200 Subject: [PATCH 04/16] Add README.rst files in sms modules --- sms_send_picking/README.rst | 64 +++++++++++++++++++++++++++++++++ sms_send_picking/__openerp__.py | 3 -- 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 sms_send_picking/README.rst diff --git a/sms_send_picking/README.rst b/sms_send_picking/README.rst new file mode 100644 index 0000000..467c15d --- /dev/null +++ b/sms_send_picking/README.rst @@ -0,0 +1,64 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +SMS send picking +=========== + +This module provide 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 +* put some picking delivery in ready to transfert state + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +Known issues / Roadmap +====================== + +* ... + +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 +`here `_. + + +Credits +======= + +Contributors +------------ + +* Valentin Chemiere + +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/__openerp__.py b/sms_send_picking/__openerp__.py index cc1c42f..107583e 100644 --- a/sms_send_picking/__openerp__.py +++ b/sms_send_picking/__openerp__.py @@ -27,9 +27,6 @@ 'website': 'www.akretion.com', 'license': 'AGPL-3', 'category': 'Phone', - 'description': """ - Automatic sms sending when a delivery is ready to transfert - """, 'depends': [ 'stock', 'smsclient_core', From a027a58403b3ea48e5cb3559da53d497e001ab77 Mon Sep 17 00:00:00 2001 From: Valentin Chemiere Date: Wed, 5 Aug 2015 16:01:35 +0200 Subject: [PATCH 05/16] Add correct OCA author name --- sms_send_picking/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sms_send_picking/__openerp__.py b/sms_send_picking/__openerp__.py index 107583e..6452b37 100644 --- a/sms_send_picking/__openerp__.py +++ b/sms_send_picking/__openerp__.py @@ -23,7 +23,7 @@ { 'name': 'Sms Send Picking', 'version': '0.0.1', - 'author': 'Akretion, OCA', + 'author': 'Akretion, Odoo Community Association (OCA)', 'website': 'www.akretion.com', 'license': 'AGPL-3', 'category': 'Phone', From fbaa15a204d7463535e7671d440891f65aca16d9 Mon Sep 17 00:00:00 2001 From: Valentin Chemiere Date: Fri, 4 Sep 2015 15:30:15 +0200 Subject: [PATCH 06/16] Ad translation --- sms_send_picking/i18n/fr.po | 33 +++++++++++++++++++++++++++++++++ sms_send_picking/stock.py | 3 ++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 sms_send_picking/i18n/fr.po 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/stock.py b/sms_send_picking/stock.py index bb6573e..4b1ea55 100644 --- a/sms_send_picking/stock.py +++ b/sms_send_picking/stock.py @@ -21,6 +21,7 @@ ############################################################################### from openerp import api, models, fields +from openerp.tools.translate import _ class StockPicking(models.Model): @@ -40,7 +41,7 @@ class StockPicking(models.Model): for pick in pickings: data = { 'gateway': gateway.id, - 'text': 'Your picking %s is ready to transfert' % pick.name, + 'text': _('Your picking %s is ready to transfert') % pick.name, 'mobile_to': pick.partner_id.phone, } sms_sender = sms_sender_obj.create(data) From 20af4dfa370c7c61a70e070635de4d756a511e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Tue, 22 Sep 2015 02:18:22 +0200 Subject: [PATCH 07/16] refactor sending sms for picking, add a todo for using template --- sms_send_picking/cron.xml | 3 ++- sms_send_picking/stock.py | 53 ++++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/sms_send_picking/cron.xml b/sms_send_picking/cron.xml index 5e649ca..9204430 100644 --- a/sms_send_picking/cron.xml +++ b/sms_send_picking/cron.xml @@ -8,8 +8,9 @@ -1 - + + diff --git a/sms_send_picking/stock.py b/sms_send_picking/stock.py index 4b1ea55..c8f7032 100644 --- a/sms_send_picking/stock.py +++ b/sms_send_picking/stock.py @@ -27,23 +27,40 @@ from openerp.tools.translate import _ class StockPicking(models.Model): _inherit = 'stock.picking' - sms_sent = fields.Boolean(default=False) + availability_sent_by_sms = fields.Boolean(default=False) + #TODO use a templating instead @api.model - def _send_sms(self): - sms_sender_obj = self.env['partner.sms.send'] - gateways = self.env['sms.smsclient'].search([('default_gateway', '=', - True)], limit=1) - gateway = gateways[0] - pickings = self.env['stock.picking'].search( - [('state', '=', 'assigned'), ('sms_sent', '=', False), - ('picking_type_id.code', '=', 'outgoing')]) - for pick in pickings: - data = { - 'gateway': gateway.id, - 'text': _('Your picking %s is ready to transfert') % pick.name, - 'mobile_to': pick.partner_id.phone, - } - sms_sender = sms_sender_obj.create(data) - sms_sender.sms_send() - pick.sms_sent = True + def _prepare_availability_sms_notification(self): + gateway = self.env['sms.gateway'].search([ + ('default_gateway', '=', True)], limit=1) + return { + 'gateway': gateway.id, + 'message': _('Your picking %s is ready to transfert') % pick.name, + 'mobile': self.partner_id.phone, + '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, + } + + @api.model + def _get_send_picking_availability_sms_domain(self): + return [ + ('state', '=', 'assigned'), + ('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_sms_domain() + pickings = self.env['stock.picking'].search(domain) + for picking in pickings: + vals = picking._prepare_availability_sms_notification() + self.env['sms.sms'].create(vals) + pickings.write({'availability_sent_by_sms': True}) From a07672f1d8eff6b1fde59835cc66400c5eda50c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Tue, 22 Sep 2015 07:28:41 +0200 Subject: [PATCH 08/16] continue refactoring, fix some error, add multi-company support --- sms_send_picking/stock.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sms_send_picking/stock.py b/sms_send_picking/stock.py index c8f7032..ddb8068 100644 --- a/sms_send_picking/stock.py +++ b/sms_send_picking/stock.py @@ -35,9 +35,9 @@ class StockPicking(models.Model): gateway = self.env['sms.gateway'].search([ ('default_gateway', '=', True)], limit=1) return { - 'gateway': gateway.id, - 'message': _('Your picking %s is ready to transfert') % pick.name, - 'mobile': self.partner_id.phone, + 'gateway_id': gateway.id, + 'message': _('Your picking %s is ready to transfert') % self.name, + 'mobile': self.partner_id.mobile, 'partner_id': self.partner_id.id, 'state': 'draft', 'validity': gateway.validity, @@ -46,6 +46,7 @@ class StockPicking(models.Model): 'priority': gateway.priority, 'coding': gateway.coding, 'nostop': gateway.nostop, + 'company_id': self.company_id.id, } @api.model From 537b0040b7875eb3e5b44f4ca551f617229b530c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Tue, 22 Sep 2015 09:34:18 +0200 Subject: [PATCH 09/16] rename method in order to be more homogenous --- sms_send_picking/stock.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sms_send_picking/stock.py b/sms_send_picking/stock.py index ddb8068..645aa83 100644 --- a/sms_send_picking/stock.py +++ b/sms_send_picking/stock.py @@ -31,7 +31,7 @@ class StockPicking(models.Model): #TODO use a templating instead @api.model - def _prepare_availability_sms_notification(self): + def _prepare_availability_by_sms_notification(self): gateway = self.env['sms.gateway'].search([ ('default_gateway', '=', True)], limit=1) return { @@ -50,7 +50,7 @@ class StockPicking(models.Model): } @api.model - def _get_send_picking_availability_sms_domain(self): + def _get_send_picking_availability_by_sms_domain(self): return [ ('state', '=', 'assigned'), ('availability_sent_by_sms', '=', False), @@ -59,9 +59,9 @@ class StockPicking(models.Model): @api.model def _cron_send_picking_availability_by_sms(self): - domain = self._get_send_picking_availability_sms_domain() + domain = self._get_send_picking_availability_by_sms_domain() pickings = self.env['stock.picking'].search(domain) for picking in pickings: - vals = picking._prepare_availability_sms_notification() + vals = picking._prepare_availability_by_sms_notification() self.env['sms.sms'].create(vals) pickings.write({'availability_sent_by_sms': True}) From 968b429b2b28dbc160f4798f225d63b719429b61 Mon Sep 17 00:00:00 2001 From: Valentin Chemiere Date: Fri, 6 Nov 2015 14:55:23 +0100 Subject: [PATCH 10/16] Add period at the end of some help sentence, clean dead code, reformat header and versionning according to OCA. --- sms_send_picking/README.rst | 4 ++-- sms_send_picking/__openerp__.py | 24 +++--------------------- sms_send_picking/stock.py | 2 +- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/sms_send_picking/README.rst b/sms_send_picking/README.rst index 467c15d..4c37c03 100644 --- a/sms_send_picking/README.rst +++ b/sms_send_picking/README.rst @@ -4,8 +4,8 @@ SMS send picking =========== -This module provide a cron and a method to automaticly sending a SMS when a -picking delivery is ready to transfert +This module provides a cron and a method to automaticly sending a SMS when a +picking delivery is ready to transfert. Configuration diff --git a/sms_send_picking/__openerp__.py b/sms_send_picking/__openerp__.py index 6452b37..03e5b7d 100644 --- a/sms_send_picking/__openerp__.py +++ b/sms_send_picking/__openerp__.py @@ -1,28 +1,10 @@ # -*- coding: utf-8 -*- -############################################################################### -# -# Module for Odoo -# Copyright (C) 2015 Akretion (http://www.akretion.com). -# @author Valentin CHEMIERE -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################### +# © 2015 Valentin CHEMIERE +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'Sms Send Picking', - 'version': '0.0.1', + 'version': '8.0.1', 'author': 'Akretion, Odoo Community Association (OCA)', 'website': 'www.akretion.com', 'license': 'AGPL-3', diff --git a/sms_send_picking/stock.py b/sms_send_picking/stock.py index 645aa83..02de8cf 100644 --- a/sms_send_picking/stock.py +++ b/sms_send_picking/stock.py @@ -36,7 +36,7 @@ class StockPicking(models.Model): ('default_gateway', '=', True)], limit=1) return { 'gateway_id': gateway.id, - 'message': _('Your picking %s is ready to transfert') % self.name, + 'message': _('Your picking %s is ready to transfer.') % self.name, 'mobile': self.partner_id.mobile, 'partner_id': self.partner_id.id, 'state': 'draft', From 530f4216bb89d6db2b14611f98cac26b12a6cddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Beau?= Date: Thu, 13 Oct 2016 07:46:32 +0200 Subject: [PATCH 11/16] add better logging and commit after generating the sms --- sms_send_picking/stock.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sms_send_picking/stock.py b/sms_send_picking/stock.py index 02de8cf..020ce66 100644 --- a/sms_send_picking/stock.py +++ b/sms_send_picking/stock.py @@ -22,6 +22,9 @@ from openerp import api, models, fields from openerp.tools.translate import _ +import logging + +_logger = logging.getLogger(__name__) class StockPicking(models.Model): @@ -61,7 +64,10 @@ class StockPicking(models.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) - for picking in pickings: + 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() self.env['sms.sms'].create(vals) - pickings.write({'availability_sent_by_sms': True}) + picking.write({'availability_sent_by_sms': True}) + picking._cr.commit() From a0ebc66ca9f2a641d3eda0dd49a38658fc288b05 Mon Sep 17 00:00:00 2001 From: MonsieurB Date: Wed, 19 Apr 2017 11:47:31 +0200 Subject: [PATCH 12/16] before test with base_sms_client --- sms_send_picking/README.rst | 7 ++--- sms_send_picking/__init__.py | 6 ++++- .../{__openerp__.py => __manifest__.py} | 6 ++--- sms_send_picking/{ => data}/cron.xml | 8 +++--- sms_send_picking/models/__init__.py | 5 ++++ sms_send_picking/{ => models}/stock.py | 26 +++---------------- 6 files changed, 25 insertions(+), 33 deletions(-) rename sms_send_picking/{__openerp__.py => __manifest__.py} (84%) rename sms_send_picking/{ => data}/cron.xml (66%) create mode 100644 sms_send_picking/models/__init__.py rename sms_send_picking/{ => models}/stock.py (63%) diff --git a/sms_send_picking/README.rst b/sms_send_picking/README.rst index 4c37c03..129f85c 100644 --- a/sms_send_picking/README.rst +++ b/sms_send_picking/README.rst @@ -1,8 +1,9 @@ .. 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. @@ -18,7 +19,7 @@ Usage To use this module, you need to: -* have a gateway correctly configured +* have a gateway correctly configured with keychain account * put some picking delivery in ready to transfert state For further information, please visit: @@ -36,7 +37,6 @@ 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 -`here `_. Credits @@ -46,6 +46,7 @@ Contributors ------------ * Valentin Chemiere +* MonsieurB Maintainer ---------- diff --git a/sms_send_picking/__init__.py b/sms_send_picking/__init__.py index 12bab77..f3af6e4 100644 --- a/sms_send_picking/__init__.py +++ b/sms_send_picking/__init__.py @@ -1 +1,5 @@ -from . import stock +# -*- 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/__openerp__.py b/sms_send_picking/__manifest__.py similarity index 84% rename from sms_send_picking/__openerp__.py rename to sms_send_picking/__manifest__.py index 03e5b7d..d2dab0b 100644 --- a/sms_send_picking/__openerp__.py +++ b/sms_send_picking/__manifest__.py @@ -4,17 +4,17 @@ { 'name': 'Sms Send Picking', - 'version': '8.0.1', + 'version': '10.0.1.0.0', 'author': 'Akretion, Odoo Community Association (OCA)', 'website': 'www.akretion.com', 'license': 'AGPL-3', 'category': 'Phone', 'depends': [ 'stock', - 'smsclient_core', + 'base_sms_client', ], 'data': [ - 'cron.xml' + 'data/cron.xml' ], 'installable': True, 'application': False, diff --git a/sms_send_picking/cron.xml b/sms_send_picking/data/cron.xml similarity index 66% rename from sms_send_picking/cron.xml rename to sms_send_picking/data/cron.xml index 9204430..f30f988 100644 --- a/sms_send_picking/cron.xml +++ b/sms_send_picking/data/cron.xml @@ -6,10 +6,10 @@ 5 minutes -1 - - - - + False + stock.picking + _cron_send_picking_availability_by_sms + () 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/stock.py b/sms_send_picking/models/stock.py similarity index 63% rename from sms_send_picking/stock.py rename to sms_send_picking/models/stock.py index 020ce66..e4a8687 100644 --- a/sms_send_picking/stock.py +++ b/sms_send_picking/models/stock.py @@ -1,27 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################### -# -# Module for Odoo -# Copyright (C) 2015 Akretion (http://www.akretion.com). -# @author Valentin CHEMIERE -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################### +# © 2015 Valentin CHEMIERE +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import api, models, fields -from openerp.tools.translate import _ +from odoo import api, models, fields +from odoo.tools.translate import _ import logging _logger = logging.getLogger(__name__) From 3f510ddef3de0fb030a526df1c3af10add72c18d Mon Sep 17 00:00:00 2001 From: MonsieurB Date: Fri, 28 Apr 2017 17:32:46 +0200 Subject: [PATCH 13/16] pylint --- sms_send_picking/README.rst | 4 ---- sms_send_picking/models/stock.py | 5 +++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/sms_send_picking/README.rst b/sms_send_picking/README.rst index 129f85c..c9264dc 100644 --- a/sms_send_picking/README.rst +++ b/sms_send_picking/README.rst @@ -26,10 +26,6 @@ For further information, please visit: * https://www.odoo.com/forum/help-1 -Known issues / Roadmap -====================== - -* ... Bug Tracker =========== diff --git a/sms_send_picking/models/stock.py b/sms_send_picking/models/stock.py index e4a8687..573fa07 100644 --- a/sms_send_picking/models/stock.py +++ b/sms_send_picking/models/stock.py @@ -14,7 +14,7 @@ class StockPicking(models.Model): availability_sent_by_sms = fields.Boolean(default=False) - #TODO use a templating instead + # TODO use a templating instead @api.model def _prepare_availability_by_sms_notification(self): gateway = self.env['sms.gateway'].search([ @@ -48,7 +48,8 @@ class StockPicking(models.Model): pickings = self.env['stock.picking'].search(domain) total = len(pickings) for idx, picking in enumerate(pickings): - _logger.debug('Send Sms for picking %s, progress %s/%s', picking, idx, total) + _logger.debug('Send Sms for picking %s, progress %s/%s', picking, + idx, total) vals = picking._prepare_availability_by_sms_notification() self.env['sms.sms'].create(vals) picking.write({'availability_sent_by_sms': True}) From 9388dc0995595631bfc2323f3a3c8e03164d11ec Mon Sep 17 00:00:00 2001 From: hpar Date: Fri, 13 Oct 2017 11:47:10 +0200 Subject: [PATCH 14/16] Fix minors remarks and add tests --- sms_send_picking/README.rst | 2 +- sms_send_picking/models/stock.py | 14 ++++-- sms_send_picking/tests/__init__.py | 1 + .../tests/test_sms_send_picking.py | 49 +++++++++++++++++++ 4 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 sms_send_picking/tests/__init__.py create mode 100644 sms_send_picking/tests/test_sms_send_picking.py 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..083f21c --- /dev/null +++ b/sms_send_picking/tests/test_sms_send_picking.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion France (Alexis de Lattre ) + +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) From 6f5d2ce3cc9b0d679ed7eb292443a32332624885 Mon Sep 17 00:00:00 2001 From: hpar Date: Fri, 13 Oct 2017 14:42:23 +0200 Subject: [PATCH 15/16] Fix copyright --- sms_send_picking/tests/test_sms_send_picking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sms_send_picking/tests/test_sms_send_picking.py b/sms_send_picking/tests/test_sms_send_picking.py index 083f21c..9f32f58 100644 --- a/sms_send_picking/tests/test_sms_send_picking.py +++ b/sms_send_picking/tests/test_sms_send_picking.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © 2016 Akretion France (Alexis de Lattre ) +# © 2016 Akretion France from openerp.tests.common import TransactionCase From 26cde6451822dbc94d574aa533e2365102d5f6af Mon Sep 17 00:00:00 2001 From: MonsieurB Date: Mon, 16 Oct 2017 13:52:37 +0200 Subject: [PATCH 16/16] change from openerp 2 from odoo --- sms_send_picking/tests/test_sms_send_picking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sms_send_picking/tests/test_sms_send_picking.py b/sms_send_picking/tests/test_sms_send_picking.py index 9f32f58..c331248 100644 --- a/sms_send_picking/tests/test_sms_send_picking.py +++ b/sms_send_picking/tests/test_sms_send_picking.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # © 2016 Akretion France -from openerp.tests.common import TransactionCase +from odoo.tests.common import TransactionCase class TestSmsSendPicking(TransactionCase):