Files
odoo_source/addons/website_sms/models/website_visitor.py
T
Martin Trigaux 2683184aa6 [FIX] *: fix all the typos
And other reported English mistakes in source string
Courtesy of Transifex translators

And remove leftover from gengo

closes odoo/odoo#59022

X-original-commit: 26efc84c5cac47a2cc83d7b084f8b71528fec6c7
Related: odoo/enterprise#13781
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2020-10-05 09:36:34 +00:00

41 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, _
from odoo.exceptions import UserError
class WebsiteVisitor(models.Model):
_inherit = 'website.visitor'
def _check_for_sms_composer(self):
""" Purpose of this method is to actualize visitor model prior to contacting
him. Used notably for inheritance purpose, when dealing with leads that
could update the visitor model. """
return bool(self.partner_id and (self.partner_id.mobile or self.partner_id.phone))
def _prepare_sms_composer_context(self):
return {
'default_res_model': 'res.partner',
'default_res_id': self.partner_id.id,
'default_composition_mode': 'comment',
'default_number_field_name': 'mobile' if self.partner_id.mobile else 'phone',
}
def action_send_sms(self):
self.ensure_one()
if not self._check_for_sms_composer():
raise UserError(_("There are no contact and/or no phone or mobile numbers linked to this visitor."))
visitor_composer_ctx = self._prepare_sms_composer_context()
compose_ctx = dict(self.env.context)
compose_ctx.update(**visitor_composer_ctx)
return {
"name": _("Send SMS Text Message"),
"type": "ir.actions.act_window",
"res_model": "sms.composer",
"view_mode": 'form',
"context": compose_ctx,
"target": "new",
}