Files
odoo_source/addons/crm_mail_plugin/controllers/crm_client.py
T
nounoubensebia 3d514037bb [REF] [crm_]mail_client_extension: rename to mail_plugin
Rename the mail_client_extension and crm_mail_client_extension modules to
mail_plugin and crm_mail_plugin respectively, purpose is to shorten the name of
the modules as it is now quite big and verbose.

Task-2427737

UPG-PR: https://github.com/odoo/upgrade/pull/2156
COM-PR: https://github.com/odoo/odoo/pull/66139
2021-03-29 14:21:05 +00:00

68 lines
3.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import werkzeug
from odoo import http
from odoo.http import request
from odoo.tools import html2plaintext
class CrmClient(http.Controller):
@http.route(route='/mail_client_extension/log_single_mail_content',
type="json", auth="outlook", cors="*")
def log_single_mail_content(self, lead, message, **kw):
"""
deprecated as of saas-14.3, not needed for newer versions of the mail plugin but necessary
for supporting older versions
"""
crm_lead = request.env['crm.lead'].browse(lead)
crm_lead.message_post(body=message)
@http.route('/mail_client_extension/lead/get_by_partner_id', type="json", auth="outlook", cors="*")
def crm_lead_get_by_partner_id(self, partner, limit=5, offset=0, **kwargs):
"""
deprecated as of saas-14.3, not needed for newer versions of the mail plugin but necessary
for supporting older versions
"""
partner_instance = request.env['res.partner'].browse(partner)
return {'leads': self._fetch_partner_leads(partner_instance, limit, offset)}
@http.route('/mail_client_extension/lead/create_from_partner', type='http', auth='user', methods=['GET'])
def crm_lead_redirect_create_form_view(self, partner_id):
"""
deprecated as of saas-14.3, not needed for newer versions of the mail plugin but necessary
for supporting older versions
"""
server_action = http.request.env.ref("crm_mail_plugin.lead_creation_prefilled_action")
return werkzeug.utils.redirect(
'/web#action=%s&model=crm.lead&partner_id=%s' % (server_action.id, int(partner_id)))
@http.route('/mail_plugin/lead/create', type='json', auth='outlook', cors="*")
def crm_lead_create(self, partner_id, email_body, email_subject):
partner = request.env['res.partner'].browse(partner_id).exists()
if not partner:
return {'error': 'partner_not_found'}
# In a multi-company environment, we will not be able to create a lead if the user is connected to a different
# company then the one linked to the contact, this is not supported, and users are encouraged to check if they
# are connected to the right company before performing such operation.
record = request.env['crm.lead'].create({
'name': html2plaintext(email_subject),
'partner_id': partner_id,
'description': html2plaintext(email_body),
})
return {'lead_id': record.id}
@http.route('/mail_client_extension/lead/open', type='http', auth='user')
def crm_lead_open(self, lead_id):
"""
deprecated as of saas-14.3, not needed for newer versions of the mail plugin but necessary
for supporting older versions
"""
action = http.request.env.ref("crm.crm_lead_view_form")
url = '/web#id=%s&action=%s&model=crm.lead&edit=1&model=crm.lead' % (lead_id, action.id)
return werkzeug.utils.redirect(url)