Move code related to redirection in its own class method. This way all controllers perform their own actions and checks before calling the redirection itself. Moreover it is necessary for some controllers to be able to call the redirection independently outside of the mail/view controller scope. This commit also fixes some links generated for mail notification email buttons. Assign and (un)follow buttons now effectively use the link helper when generating the associated URL instead of manually crafting it. Custom routes for notification buttons used in HR and CRM are added. Indeed in order to be able to fine-tune the behavior called by those buttons, using dedicated controllers is simpler than trying to use a generic one. As there are few custom buttons in notification emails using dedicated controllers does not lead to a code overhead.
39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from openerp.addons.mail.controllers.main import MailController
|
|
from openerp import http
|
|
|
|
|
|
class CrmController(http.Controller):
|
|
|
|
@http.route('/lead/case_mark_won', type='http', auth='user', methods=['GET'])
|
|
def crm_lead_case_mark_won(self, res_id, token):
|
|
comparison, record, redirect = MailController._check_token_and_record_or_redirect('crm.lead', int(res_id), token)
|
|
if comparison and record:
|
|
try:
|
|
record.case_mark_won()
|
|
except Exception:
|
|
return MailController._redirect_to_messaging()
|
|
return redirect
|
|
|
|
@http.route('/lead/case_mark_lost', type='http', auth='user', methods=['GET'])
|
|
def crm_lead_case_mark_lost(self, res_id, token):
|
|
comparison, record, redirect = MailController._check_token_and_record_or_redirect('crm.lead', int(res_id), token)
|
|
if comparison and record:
|
|
try:
|
|
record.case_mark_lost()
|
|
except Exception:
|
|
return MailController._redirect_to_messaging()
|
|
return redirect
|
|
|
|
@http.route('/lead/convert', type='http', auth='user', methods=['GET'])
|
|
def crm_lead_convert(self, res_id, token):
|
|
comparison, record, redirect = MailController._check_token_and_record_or_redirect('crm.lead', int(res_id), token)
|
|
if comparison and record:
|
|
try:
|
|
record.convert_opportunity(record.partner_id.id)
|
|
except Exception:
|
|
return MailController._redirect_to_messaging()
|
|
return redirect
|