diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index fdb7961e094..509643801ff 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -1234,13 +1234,13 @@ class Lead(models.Model): } @api.model - def get_empty_list_help(self, help): + def get_empty_list_help(self, help_message): """ This method returns the action helpers for the leads. If help is already provided on the action, the same is returned. Otherwise, we build the help message which contains the alias responsible for creating the lead (if available) and return it. """ - if not is_html_empty(help): - return help + if not is_html_empty(help_message): + return help_message help_title, sub_title = "", "" if self._context.get('default_type') == 'lead': @@ -1258,7 +1258,9 @@ class Lead(models.Model): email = '%s@%s' % (alias_record.alias_name, alias_record.alias_domain) email_link = "%s" % (email, email) sub_title = _('Use the top left Create button, or send an email to %s to test the email gateway.') % (email_link) - return '
%s
%s
' % (help_title, sub_title) + return super().get_empty_list_help( + f'{help_title}
{sub_title}
' + ) # ------------------------------------------------------------ # BUSINESS diff --git a/addons/crm_iap_mine/models/crm_iap_lead_mining_request.py b/addons/crm_iap_mine/models/crm_iap_lead_mining_request.py index c2c5af9535f..5796a61cff9 100644 --- a/addons/crm_iap_mine/models/crm_iap_lead_mining_request.py +++ b/addons/crm_iap_mine/models/crm_iap_lead_mining_request.py @@ -6,6 +6,7 @@ import logging from odoo import api, fields, models, _ from odoo.addons.iap.tools import iap_tools from odoo.exceptions import UserError +from odoo.tools import is_html_empty _logger = logging.getLogger(__name__) @@ -185,10 +186,15 @@ class CRMLeadMiningRequest(models.Model): self.company_size_max = self.company_size_min @api.model - def get_empty_list_help(self, help_string): + def get_empty_list_help(self, help_message): + if not is_html_empty(help_message): + return help_message + help_title = _('Create a Lead Mining Request') sub_title = _('Generate new leads based on their country, industry, size, etc.') - return '%s
%s
' % (help_title, sub_title) + return super().get_empty_list_help( + f'{help_title}
{sub_title}
' + ) def _prepare_iap_payload(self): """ diff --git a/addons/hr_expense/models/__init__.py b/addons/hr_expense/models/__init__.py index e0f6b9318ec..e52cfb4506a 100644 --- a/addons/hr_expense/models/__init__.py +++ b/addons/hr_expense/models/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. from . import hr_employee from . import account_move diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index 6452a4ac736..17ba2c82c35 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -3,6 +3,8 @@ import re from markupsafe import Markup +import werkzeug + from odoo import api, fields, Command, models, _ from odoo.tools import float_round from odoo.exceptions import UserError, ValidationError @@ -403,17 +405,23 @@ class HrExpense(models.Model): @api.model def get_empty_list_help(self, help_message): - return super(HrExpense, self).get_empty_list_help(help_message or '' + self._get_empty_list_mail_alias()) + return super().get_empty_list_help((help_message or '') + self._get_empty_list_mail_alias()) @api.model def _get_empty_list_mail_alias(self): use_mailgateway = self.env['ir.config_parameter'].sudo().get_param('hr_expense.use_mailgateway') - alias_record = use_mailgateway and self.env.ref('hr_expense.mail_alias_expense') or False - if alias_record and alias_record.alias_domain and alias_record.alias_name: - return Markup(""" --Or send your receipts at %(email)s. -
""") % {'email': '%s@%s' % (alias_record.alias_name, alias_record.alias_domain)} + expense_alias = self.env.ref('hr_expense.mail_alias_expense') if use_mailgateway else False + if expense_alias and expense_alias.alias_domain and expense_alias.alias_name: + alias_email = f'{expense_alias.alias_name}@{expense_alias.alias_domain}' + # encode, but force %20 encoding for space instead of a + (URL / mailto difference) + params = werkzeug.urls.url_encode({'subject': _("Lunch with customer $12.32")}).replace('+', '%20') + return Markup( + """%(send_string)s %(alias_email)s
""" + ) % { + 'alias_email': alias_email, + 'params': params, + 'send_string': _("Or send your receipts at"), + } return "" # ---------------------------------------- diff --git a/addons/hr_expense/models/res_config_settings.py b/addons/hr_expense/models/res_config_settings.py index b9db4a03fdc..20977d87352 100644 --- a/addons/hr_expense/models/res_config_settings.py +++ b/addons/hr_expense/models/res_config_settings.py @@ -6,14 +6,13 @@ from odoo import api, fields, models class ResConfigSettings(models.TransientModel): _inherit = 'res.config.settings' - expense_alias_prefix = fields.Char( + hr_expense_alias_prefix = fields.Char( 'Default Alias Name for Expenses', - compute='_compute_expense_alias_prefix', + compute='_compute_hr_expense_alias_prefix', store=True, readonly=False) - use_mailgateway = fields.Boolean(string='Let your employees record expenses by email', - config_parameter='hr_expense.use_mailgateway') - + hr_expense_use_mailgateway = fields.Boolean(string='Let your employees record expenses by email', + config_parameter='hr_expense.use_mailgateway') module_hr_payroll_expense = fields.Boolean(string='Reimburse Expenses in Payslip') module_hr_expense_extract = fields.Boolean(string='Send bills to OCR to generate expenses') expense_journal_id = fields.Many2one('account.journal', related='company_id.expense_journal_id', readonly=False) @@ -22,17 +21,32 @@ class ResConfigSettings(models.TransientModel): @api.model def get_values(self): res = super(ResConfigSettings, self).get_values() + expense_alias = self.env.ref('hr_expense.mail_alias_expense', raise_if_not_found=False) res.update( - expense_alias_prefix=self.env.ref('hr_expense.mail_alias_expense').alias_name, + hr_expense_alias_prefix=expense_alias.alias_name if expense_alias else False, ) return res def set_values(self): super().set_values() - alias = self.env.ref('hr_expense.mail_alias_expense', raise_if_not_found=False) - if alias and alias.alias_name != self.expense_alias_prefix: - alias.alias_name = self.expense_alias_prefix + expense_alias = self.env.ref('hr_expense.mail_alias_expense', raise_if_not_found=False) + if not expense_alias and self.hr_expense_alias_prefix: + # create data again + alias = self.env['mail.alias'].sudo().create({ + 'alias_contact': 'employees', + 'alias_model_id': self.env['ir.model']._get_id('hr.expense'), + 'alias_name': self.hr_expense_alias_prefix, + }) + self.env['ir.model.data'].sudo().create({ + 'name': 'mail_alias_expense', + 'module': 'hr_expense', + 'model': 'mail.alias', + 'noupdate': True, + 'res_id': alias.id, + }) + elif expense_alias and expense_alias.alias_name != self.hr_expense_alias_prefix: + expense_alias.alias_name = self.hr_expense_alias_prefix - @api.depends('use_mailgateway') - def _compute_expense_alias_prefix(self): - self.filtered(lambda w: not w.use_mailgateway).update({'expense_alias_prefix': False}) + @api.depends('hr_expense_use_mailgateway') + def _compute_hr_expense_alias_prefix(self): + self.filtered(lambda w: not w.hr_expense_use_mailgateway).hr_expense_alias_prefix = False diff --git a/addons/hr_expense/views/res_config_settings_views.xml b/addons/hr_expense/views/res_config_settings_views.xml index f2b16ea85ca..d1cf962c873 100644 --- a/addons/hr_expense/views/res_config_settings_views.xml +++ b/addons/hr_expense/views/res_config_settings_views.xml @@ -15,22 +15,22 @@ id="create_expense_setting" title="Send an email to this email alias with the receipt in attachment to create an expense in one click. If the first word of the mail subject contains the category's internal reference or the category name, the corresponding category will automatically be set. Type the expense amount in the mail subject to set it on the expense too.">%(email_link)s
""" + nocontent_body += """%(email_link)s
""" - return nocontent_body % nocontent_values + return super().get_empty_list_help(nocontent_body % nocontent_values) @api.model def get_view(self, view_id=None, view_type='form', **options): diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 79412950823..1a8c7b837f5 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -338,14 +338,14 @@ class MailThread(models.AbstractModel): return super(MailThread, self.with_context(mail_notrack=True)).copy_data(default=default) @api.model - def get_empty_list_help(self, help): + def get_empty_list_help(self, help_message): """ Override of BaseModel.get_empty_list_help() to generate an help message that adds alias information. """ model = self._context.get('empty_list_help_model') res_id = self._context.get('empty_list_help_id') catchall_domain = self.env['ir.config_parameter'].sudo().get_param("mail.catchall.domain") document_name = self._context.get('empty_list_help_document_name', _('document')) - nothing_here = not help + nothing_here = is_html_empty(help_message) alias = None if catchall_domain and model and res_id: # specific res_id -> find its alias (i.e. section_id specified) @@ -369,28 +369,28 @@ class MailThread(models.AbstractModel): if alias: email_link = "%(email)s" % {'email': alias.display_name} if nothing_here: - return "%(dyn_help)s
" % { + return super().get_empty_list_help("%(dyn_help)s
" % { 'dyn_help': _("Add a new %(document)s or send an email to %(email_link)s", document=document_name, email_link=email_link, ) - } + }) # do not add alias two times if it was added previously - if "oe_view_nocontent_alias" not in help: - return "%(static_help)s%(dyn_help)s
" % { - 'static_help': help, + if "oe_view_nocontent_alias" not in help_message: + return super().get_empty_list_help("%(static_help)s%(dyn_help)s
" % { + 'static_help': help_message, 'dyn_help': _("Create new %(document)s by sending an email to %(email_link)s", document=document_name, email_link=email_link, ) - } + }) if nothing_here: - return "%(dyn_help)s
" % { + return super().get_empty_list_help("%(dyn_help)s
" % { 'dyn_help': _("Create new %(document)s", document=document_name), - } + }) - return help + return super().get_empty_list_help(help_message) # ------------------------------------------------------ # MODELS / CRUD HELPERS diff --git a/addons/mail/views/mail_alias_views.xml b/addons/mail/views/mail_alias_views.xml index 08269cf7cf5..aeaa280b845 100644 --- a/addons/mail/views/mail_alias_views.xml +++ b/addons/mail/views/mail_alias_views.xml @@ -11,7 +11,7 @@