[IMP] crm: improves description field type from text to html
Replace text fields to html fields as we have our own 'OdooEditor'. Indeed, it gives more options to users in the way they format their content without weighting too much on the UI (tools appear on demand and not by default). Models -> Fields 1) crm.lead -> description 2) event.event -> note Task Id: 2499504 X-original-commit: 524e2f089a611d897b98d86001bda5d17263db66
This commit is contained in:
committed by
Thibault Delavallée
parent
f247476155
commit
586ae4bcc4
@@ -121,7 +121,7 @@ class Lead(models.Model):
|
||||
'res.company', string='Company', index=True,
|
||||
compute='_compute_company_id', readonly=False, store=True)
|
||||
referred = fields.Char('Referred By')
|
||||
description = fields.Text('Notes')
|
||||
description = fields.Html('Notes')
|
||||
active = fields.Boolean('Active', default=True, tracking=True)
|
||||
type = fields.Selection([
|
||||
('lead', 'Lead'), ('opportunity', 'Opportunity')],
|
||||
@@ -1376,7 +1376,7 @@ class Lead(models.Model):
|
||||
|
||||
def _merge_get_fields_specific(self):
|
||||
return {
|
||||
'description': lambda fname, leads: '\n\n'.join(desc for desc in leads.mapped('description') if desc),
|
||||
'description': lambda fname, leads: '<br/><br/>'.join(desc for desc in leads.mapped('description') if not is_html_empty(desc)),
|
||||
'type': lambda fname, leads: 'opportunity' if any(lead.type == 'opportunity' for lead in leads) else 'lead',
|
||||
'priority': lambda fname, leads: max(leads.mapped('priority')) if leads else False,
|
||||
}
|
||||
|
||||
@@ -399,7 +399,7 @@ class TestCrmCommon(TestSalesCommon, MailCase):
|
||||
|
||||
def _get_description():
|
||||
values = [_find_value(lead, 'description') for lead in leads]
|
||||
return '\n\n'.join(value for value in values if value)
|
||||
return '<br><br>'.join(value for value in values if value)
|
||||
|
||||
def _get_priority():
|
||||
values = [_find_value(lead, 'priority') for lead in leads]
|
||||
|
||||
@@ -88,7 +88,7 @@ class TestLeadMerge(TestLeadMergeCommon):
|
||||
# and exclude inactive leads, but that's not written anywhere ... intended ??
|
||||
self.assertEqual(merge.opportunity_ids, self.leads - self.lead_w_partner_company - self.lead_w_email_lost)
|
||||
ordered_merge = self.lead_w_contact + self.lead_w_email + self.lead_1 + self.lead_w_partner
|
||||
ordered_merge_description = '\n\n'.join(l.description for l in ordered_merge)
|
||||
ordered_merge_description = '<br><br>'.join(l.description for l in ordered_merge)
|
||||
|
||||
# merged opportunity: in this test, all input are leads. Confidence is based on stage
|
||||
# sequence -> lead_w_contact has a stage sequence of 30
|
||||
|
||||
@@ -28,9 +28,9 @@ class MailChannel(models.Model):
|
||||
:param key: operator input in chat ('/lead Lead about Product')
|
||||
"""
|
||||
description = ''.join(
|
||||
'%s: %s\n' % (message.author_id.name or self.anonymous_name, message.body)
|
||||
'%s: %s<br/>' % (message.author_id.name or self.anonymous_name, html2plaintext(message.body))
|
||||
for message in self.message_ids.sorted('id')
|
||||
)
|
||||
) # converting message body back to plaintext for correct data formating in description
|
||||
# if public user is part of the chat: consider lead to be linked to an
|
||||
# anonymous user whatever the participants. Otherwise keep only share
|
||||
# partners (no user or portal user) to link to the lead.
|
||||
@@ -48,7 +48,7 @@ class MailChannel(models.Model):
|
||||
'partner_id': customers[0].id if customers else False,
|
||||
'user_id': False,
|
||||
'team_id': False,
|
||||
'description': html2plaintext(description),
|
||||
'description': description,
|
||||
'referred': partner.name,
|
||||
'source_id': utm_source and utm_source.id,
|
||||
})
|
||||
|
||||
@@ -106,7 +106,7 @@ class EventEvent(models.Model):
|
||||
return self.env['ir.ui.view']._render_template('event.event_default_descripton')
|
||||
|
||||
name = fields.Char(string='Event', translate=True, required=True)
|
||||
note = fields.Text(string='Note')
|
||||
note = fields.Html(string='Note')
|
||||
description = fields.Html(string='Description', translate=html_translate, sanitize_attributes=False, sanitize_form=False, default=_default_description)
|
||||
active = fields.Boolean(default=True)
|
||||
user_id = fields.Many2one(
|
||||
|
||||
@@ -177,7 +177,7 @@ class EventLeadRule(models.Model):
|
||||
additionnal_description = group_registrations._get_lead_description(_("New registrations"), line_counter=True)
|
||||
for lead in toupdate_leads:
|
||||
lead.write({
|
||||
'description': "%s\n%s" % (lead.description, additionnal_description),
|
||||
'description': "%s<br/>%s" % (lead.description, additionnal_description),
|
||||
'registration_ids': [(4, reg.id) for reg in group_registrations],
|
||||
})
|
||||
elif group_registrations:
|
||||
|
||||
@@ -132,7 +132,7 @@ class EventRegistration(models.Model):
|
||||
upd_description_fields = [field for field in self._get_lead_description_fields() if field in new_vals.keys()]
|
||||
if any(new_vals[field] != old_vals[field] for field in upd_description_fields):
|
||||
for lead in leads_attendee:
|
||||
lead_values['description'] = "%s\n%s" % (
|
||||
lead_values['description'] = "%s<br/>%s" % (
|
||||
lead.description,
|
||||
registration._get_lead_description(_("Updated registrations"), line_counter=True)
|
||||
)
|
||||
@@ -148,7 +148,7 @@ class EventRegistration(models.Model):
|
||||
if not lead.partner_id:
|
||||
lead_values['description'] = lead.registration_ids._get_lead_description(_("Participants"), line_counter=True)
|
||||
elif new_vals['partner_id'] != lead.partner_id.id:
|
||||
lead_values['description'] = lead.description + "\n" + lead.registration_ids._get_lead_description(_("Updated registrations"), line_counter=True, line_suffix=_("(updated)"))
|
||||
lead_values['description'] = lead.description + "<br/>" + lead.registration_ids._get_lead_description(_("Updated registrations"), line_counter=True, line_suffix=_("(updated)"))
|
||||
if lead_values:
|
||||
lead.write(lead_values)
|
||||
|
||||
@@ -232,17 +232,16 @@ class EventRegistration(models.Model):
|
||||
"""
|
||||
reg_lines = [
|
||||
registration._get_lead_description_registration(
|
||||
prefix="%s. " % (index + 1) if line_counter else "",
|
||||
line_suffix=line_suffix
|
||||
) for index, registration in enumerate(self)
|
||||
) for registration in self
|
||||
]
|
||||
return ("%s\n" % prefix if prefix else "") + ("\n".join(reg_lines))
|
||||
return ("%s<br/>" % prefix if prefix else "") + (
|
||||
"<ol>" if line_counter else "<ul>") + ("".join(reg_lines)) + ("</ol>" if line_counter else "</ul>")
|
||||
|
||||
def _get_lead_description_registration(self, prefix='', line_suffix=''):
|
||||
def _get_lead_description_registration(self, line_suffix=''):
|
||||
""" Build the description line specific to a given registration. """
|
||||
self.ensure_one()
|
||||
return "%s%s (%s)%s" % (
|
||||
prefix or "",
|
||||
return "<li>%s (%s)%s</li>" % (
|
||||
self.name or self.partner_id.name or self.email,
|
||||
" - ".join(self[field] for field in ('email', 'phone') if self[field]),
|
||||
" %s" % line_suffix if line_suffix else "",
|
||||
|
||||
@@ -7,18 +7,18 @@ from odoo import models, _
|
||||
class EventRegistration(models.Model):
|
||||
_inherit = 'event.registration'
|
||||
|
||||
def _get_lead_description_registration(self, prefix='', line_suffix=''):
|
||||
def _get_lead_description_registration(self, line_suffix=''):
|
||||
"""Add the questions and answers linked to the registrations into the description of the lead."""
|
||||
reg_description = super(EventRegistration, self)._get_lead_description_registration(prefix=prefix, line_suffix=line_suffix)
|
||||
reg_description = super(EventRegistration, self)._get_lead_description_registration(line_suffix=line_suffix)
|
||||
if not self.registration_answer_ids:
|
||||
return reg_description
|
||||
|
||||
answer_descriptions = []
|
||||
for answer in self.registration_answer_ids:
|
||||
answer_value = answer.value_answer_id.name if answer.question_type == "simple_choice" else answer.value_text_box
|
||||
answer_value = "\n".join([" %s" % line for line in answer_value.split('\n')])
|
||||
answer_descriptions.append(" - %s\n%s" % (answer.question_id.title, answer_value))
|
||||
return "%s\n%s\n%s" % (reg_description, _("Questions"), '\n'.join(answer_descriptions))
|
||||
answer_value = "<br/>".join([" %s" % line for line in answer_value.split('\n')])
|
||||
answer_descriptions.append(" - %s<br/>%s" % (answer.question_id.title, answer_value))
|
||||
return "%s%s<br/>%s" % (reg_description, _("Questions"), '<br/>'.join(answer_descriptions))
|
||||
|
||||
def _get_lead_description_fields(self):
|
||||
res = super(EventRegistration, self)._get_lead_description_fields()
|
||||
|
||||
Reference in New Issue
Block a user