diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/stock_sms/models | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/stock_sms/models')
| -rw-r--r-- | addons/stock_sms/models/__init__.py | 6 | ||||
| -rw-r--r-- | addons/stock_sms/models/res_company.py | 22 | ||||
| -rw-r--r-- | addons/stock_sms/models/res_config_settings.py | 14 | ||||
| -rw-r--r-- | addons/stock_sms/models/stock_picking.py | 64 |
4 files changed, 106 insertions, 0 deletions
diff --git a/addons/stock_sms/models/__init__.py b/addons/stock_sms/models/__init__.py new file mode 100644 index 00000000..81799f3f --- /dev/null +++ b/addons/stock_sms/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import res_company +from . import res_config_settings +from . import stock_picking diff --git a/addons/stock_sms/models/res_company.py b/addons/stock_sms/models/res_company.py new file mode 100644 index 00000000..d7639c8e --- /dev/null +++ b/addons/stock_sms/models/res_company.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class Company(models.Model): + _inherit = "res.company" + + def _default_confirmation_sms_picking_template(self): + try: + return self.env.ref('stock_sms.sms_template_data_stock_delivery').id + except ValueError: + return False + + stock_move_sms_validation = fields.Boolean("SMS Confirmation", default=True) + stock_sms_confirmation_template_id = fields.Many2one( + 'sms.template', string="SMS Template", + domain="[('model', '=', 'stock.picking')]", + default=_default_confirmation_sms_picking_template, + help="SMS sent to the customer once the order is done.") + has_received_warning_stock_sms = fields.Boolean() diff --git a/addons/stock_sms/models/res_config_settings.py b/addons/stock_sms/models/res_config_settings.py new file mode 100644 index 00000000..12dab58a --- /dev/null +++ b/addons/stock_sms/models/res_config_settings.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + stock_move_sms_validation = fields.Boolean( + related='company_id.stock_move_sms_validation', + string='SMS Validation with stock move', readonly=False) + stock_sms_confirmation_template_id = fields.Many2one( + related='company_id.stock_sms_confirmation_template_id', readonly=False) diff --git a/addons/stock_sms/models/stock_picking.py b/addons/stock_sms/models/stock_picking.py new file mode 100644 index 00000000..846af192 --- /dev/null +++ b/addons/stock_sms/models/stock_picking.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, _ + +import threading + + +class Picking(models.Model): + _inherit = 'stock.picking' + + def _pre_action_done_hook(self): + res = super()._pre_action_done_hook() + if res is True and not self.env.context.get('skip_sms'): + pickings_to_warn_sms = self._check_warn_sms() + if pickings_to_warn_sms: + return pickings_to_warn_sms._action_generate_warn_sms_wizard() + return res + + def _check_warn_sms(self): + warn_sms_pickings = self.browse() + for picking in self: + is_delivery = picking.company_id.stock_move_sms_validation \ + and picking.picking_type_id.code == 'outgoing' \ + and (picking.partner_id.mobile or picking.partner_id.phone) + if is_delivery and not getattr(threading.currentThread(), 'testing', False) \ + and not self.env.registry.in_test_mode() \ + and not picking.company_id.has_received_warning_stock_sms \ + and picking.company_id.stock_move_sms_validation: + warn_sms_pickings |= picking + return warn_sms_pickings + + def _action_generate_warn_sms_wizard(self): + view = self.env.ref('stock_sms.view_confirm_stock_sms') + wiz = self.env['confirm.stock.sms'].create({'pick_ids': [(4, p.id) for p in self]}) + return { + 'name': _('SMS'), + 'type': 'ir.actions.act_window', + 'view_mode': 'form', + 'res_model': 'confirm.stock.sms', + 'views': [(view.id, 'form')], + 'view_id': view.id, + 'target': 'new', + 'res_id': wiz.id, + 'context': self.env.context, + } + + def _sms_get_number_fields(self): + """ This method returns the fields to use to find the number to use to + send an SMS on a record. """ + return ['mobile', 'phone'] + + def _send_confirmation_email(self): + super(Picking, self)._send_confirmation_email() + if not self.env.context.get('skip_sms') and not getattr(threading.currentThread(), 'testing', False) and not self.env.registry.in_test_mode(): + pickings = self.filtered(lambda p: p.company_id.stock_move_sms_validation and p.picking_type_id.code == 'outgoing' and (p.partner_id.mobile or p.partner_id.phone)) + for picking in pickings: + # Sudo as the user has not always the right to read this sms template. + template = picking.company_id.sudo().stock_sms_confirmation_template_id + picking._message_sms_with_template( + template=template, + partner_ids=picking.partner_id.ids, + put_in_queue=False + ) |
