From add1a04a9451a684b5503d92a07f0ddf37f6921e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 26 May 2020 13:58:55 +0000 Subject: [PATCH] [REF] digest: make digest template bioutifoul MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PURPOSE Make digest email and tips more appealing. The goals of these tips are * to encourage the adoption of other apps (Did you know ?); * to make Odoo look more fun (Fun tips and tricks, young and dynamic style); * to show social proof and increase trust (emphasis on already existing projects / customers to); SPECIFICATIONS Improve template according to FP specifications, aka Header Tip KPIs Preference text Want to customize? Mobile Tip Footer LINKS Task ID 2197417 PR odoo/odoo#51619 Upgrade PR odoo/upgrade#1256 Co-Authored-By: Elisabeth Dickinson Co-Authored-By: Thibault Delavallée --- addons/digest/__manifest__.py | 5 +- addons/digest/data/digest_data.xml | 111 ++++---- addons/digest/data/digest_template_data.xml | 293 +++++++++++--------- addons/digest/data/digest_tips_data.xml | 59 ++++ addons/digest/models/digest.py | 34 ++- 5 files changed, 302 insertions(+), 200 deletions(-) create mode 100644 addons/digest/data/digest_tips_data.xml diff --git a/addons/digest/__manifest__.py b/addons/digest/__manifest__.py index 024305a0dca..b27fbd29ed7 100644 --- a/addons/digest/__manifest__.py +++ b/addons/digest/__manifest__.py @@ -7,7 +7,7 @@ Send KPI Digests periodically ============================= """, - 'version': '1.0', + 'version': '1.1', 'depends': [ 'mail', 'portal', @@ -15,8 +15,9 @@ Send KPI Digests periodically ], 'data': [ 'security/ir.model.access.csv', - 'data/digest_template_data.xml', 'data/digest_data.xml', + 'data/digest_template_data.xml', + 'data/digest_tips_data.xml', 'data/ir_cron_data.xml', 'data/res_config_settings_data.xml', 'views/digest_views.xml', diff --git a/addons/digest/data/digest_data.xml b/addons/digest/data/digest_data.xml index 375dd660681..67bd019bc00 100644 --- a/addons/digest/data/digest_data.xml +++ b/addons/digest/data/digest_data.xml @@ -1,59 +1,56 @@ - - - - - Weekly Stats in Odoo - - - True - True - - + + - - - Mail: ping colleagues - 1 - -
- % set users = object.env['res.users'].search([('share', '=' , False)], limit=10, order='id desc') - % set channel_id = object.env.ref('mail.channel_all_employees').id - Did you know...? -
You can ping colleagues by tagging them in your messages using "@". They will be instantly notified.
-
-
-
-
- ${', '.join(users.mapped('name'))} signed up. Say hello in the company's discussion channel. -
-
-
-
-
- - Mail: get things done with activities - 7 - -
- Get things done with activities -
You don't have any activity scheduled. Use activities on any business document to schedule meetings, calls and todos.
-
-
-
-
-
-
+ + +
diff --git a/addons/digest/data/digest_template_data.xml b/addons/digest/data/digest_template_data.xml index 2b9e607796d..dc5109c4b56 100644 --- a/addons/digest/data/digest_template_data.xml +++ b/addons/digest/data/digest_template_data.xml @@ -6,103 +6,126 @@ ${'%s: %s' % (ctx.get('user', user).company_id.name, object.name)} ${('%s' % (object.company_id.partner_id.email_formatted or user.email_formatted))|safe} - - -
- % set user = ctx.get('user', user) - % set company = user.company_id - % set data = object.compute_kpis(company, user) - % set tips = object.compute_tips(company, user) - % set kpi_actions = object.compute_kpis_actions(company, user) - % set kpis = data.yesterday.keys() - - - - - - -
- ${object.name} -
${datetime.date.today().strftime('%B %d, %Y')}
-
- -
- Connect -
-
-
-
- % for kpi in kpis: - +
+ % set user = ctx.get('user', user) + % set company = user.company_id + % set data = object.compute_kpis(company, user) + % set tips = object.compute_tips(company, user, tips_count=ctx.get('tips_count', 1)) + % set kpi_actions = object.compute_kpis_actions(company, user) + % set kpis = data.yesterday.keys() +
+ + + + +
+ - +

- ${object.fields_get()[kpi]['string']} - %if kpi in kpi_actions: - - View more - - %endif +
+ + + + + +
+ ${company.name} +
+ ${object.name} + ${datetime.date.today().strftime('%B %d, %Y')} +
+ Connect +
+
+ % if tips: + + +
+ -
- + + +
+ - - + +
- - - - -
- ${data['yesterday'][kpi][kpi]}
- Yesterday - % if data['yesterday'][kpi]['margin'] != 0.0: - - % if data['yesterday'][kpi]['margin'] is greaterthan(0.0): - ▲${"%.2f" % data['yesterday'][kpi]['margin']} % - % endif - % if data['yesterday'][kpi]['margin'] is lessthan(0.0): - ▼${"%.2f" % data['yesterday'][kpi]['margin']} % - % endif - - % endif -
+
+ ${tip | safe} - - - +
- ${data['lastweek'][kpi][kpi]}
- Last 7 Days - % if data['lastweek'][kpi]['margin'] != 0.0: - - % if data['lastweek'][kpi]['margin'] is greaterthan(0.0): - ▲${"%.2f" % data['lastweek'][kpi]['margin']} % - % endif - % if data['lastweek'][kpi]['margin'] is lessthan(0.0): - ▼${"%.2f" % data['lastweek'][kpi]['margin']} % - %endif - +
+
+
+ % endif + + +
+ % for kpi in kpis: + + + + + + + + + + +
+ + + + + + - - -
+ ${object.fields_get()[kpi]['string']} + %if kpi in kpi_actions: + View + %endif +
+ + + - -
+ ${data['yesterday'][kpi][kpi]}
+ Yesterday + % if data['yesterday'][kpi]['margin'] != 0.0: + % if data['yesterday'][kpi]['margin'] is greaterthan(0.0): +
+ ▲ ${"%.2f" % data['yesterday'][kpi]['margin']} +
+ %endif + % if data['yesterday'][kpi]['margin'] is lessthan(0.0): +
+ ▼ ${"%.2f" % data['yesterday'][kpi]['margin']} +
+ %endif %endif
-
- - - + @@ -113,52 +136,62 @@
- ${data['lastmonth'][kpi][kpi]}
- Last 30 Days +
+ ${data['lastweek'][kpi][kpi]}
+ Last 7 Days + % if data['lastweek'][kpi]['margin'] != 0.0: + % if data['lastweek'][kpi]['margin'] is greaterthan(0.0): +
+ ▲ ${"%.2f" % data['lastweek'][kpi]['margin']} +
+ %endif + % if data['lastweek'][kpi]['margin'] is lessthan(0.0): +
+ ▼ ${"%.2f" % data['lastweek'][kpi]['margin']} +
+ %endif + %endif +
+ ${data['lastmonth'][kpi][kpi]}
+ Last 30 Days % if data['lastmonth'][kpi]['margin'] != 0.0: - - % if data['lastmonth'][kpi]['margin'] is greaterthan(0.0): - ▲${"%.2f" % data['lastmonth'][kpi]['margin']} % - % endif - % if data['lastmonth'][kpi]['margin'] is lessthan(0.0): - ▼${"%.2f" % data['lastmonth'][kpi]['margin']} % - %endif - + % if data['lastmonth'][kpi]['margin'] is greaterthan(0.0): +
+ ▲ ${"%.2f" % data['lastmonth'][kpi]['margin']} +
+ %endif + % if data['lastmonth'][kpi]['margin'] is lessthan(0.0): +
+ ▼ ${"%.2f" % data['lastmonth'][kpi]['margin']} +
+ %endif %endif
- % endfor - % if tips: - + % endfor + % if user.has_group('base.group_system'): +
-

-
${tips | safe}
+
+

Want to customize this email? + Choose the metrics you care about

- % endif - - - - - - - -

-
Run your business from anywhere with Odoo Mobile.
-
-
-
-
- - - - -
- % if user.has_group('base.group_system'): -
- Want to customize this email? - Choose the metrics you care about -
-
- % endif -

- - Sent by - Odoo - Unsubscribe - -

-
-
+ % endif +
+ + + + +
+ + + + + +
+ Odoo Mobile + +

Run your business from anywhere with
Odoo Mobile.

+ + + + +
+
+
+ + + + + + + + + + +
${company.name}
Powered by Odoo.
+
+ + ${user.lang} - + diff --git a/addons/digest/data/digest_tips_data.xml b/addons/digest/data/digest_tips_data.xml new file mode 100644 index 00000000000..375dd660681 --- /dev/null +++ b/addons/digest/data/digest_tips_data.xml @@ -0,0 +1,59 @@ + + + + + Weekly Stats in Odoo + + + True + True + + + + + + Mail: ping colleagues + 1 + +
+ % set users = object.env['res.users'].search([('share', '=' , False)], limit=10, order='id desc') + % set channel_id = object.env.ref('mail.channel_all_employees').id + Did you know...? +
You can ping colleagues by tagging them in your messages using "@". They will be instantly notified.
+
+
+
+
+ ${', '.join(users.mapped('name'))} signed up. Say hello in the company's discussion channel. +
+
+
+
+
+ + Mail: get things done with activities + 7 + +
+ Get things done with activities +
You don't have any activity scheduled. Use activities on any business document to schedule meetings, calls and todos.
+
+
+
+
+
+
+ + + Mail: apps videos tour + + 0 + +
+ To reach your full potential with Odoo, have a look at our apps videos and discover new tools to work better and faster. +
+
+
+ +
+
diff --git a/addons/digest/models/digest.py b/addons/digest/models/digest.py index 609f7198478..4b33ebc7937 100644 --- a/addons/digest/models/digest.py +++ b/addons/digest/models/digest.py @@ -101,10 +101,20 @@ class Digest(models.Model): def action_send(self): for digest in self: for user in digest.user_ids: - subject = '%s: %s' % (user.company_id.name, digest.name) - digest.template_id.with_context(user=user).send_mail(digest.id, force_send=True, raise_exception=True, email_values={'email_to': user.email, 'subject': subject}) + digest._action_send_to_user(user, tips_count=1) digest.next_run_date = digest._get_next_run_date() + def _action_send_to_user(self, user, tips_count=1): + subject = '%s: %s' % (user.company_id.name, self.name) + self.template_id.with_context(user=user, tips_count=tips_count).send_mail( + self.id, + force_send=True, + notif_layout="digest.digest_mail_layout", + raise_exception=True, + email_values={ + 'email_to': user.email, 'subject': subject + } + ) @api.model def _cron_send_digest_email(self): @@ -148,15 +158,17 @@ class Digest(models.Model): res.update({tf_name: kpis}) return res - def compute_tips(self, company, user): - tip = self.env['digest.tip'].search([('user_ids', '!=', user.id), '|', ('group_id', 'in', user.groups_id.ids), ('group_id', '=', False)], limit=1) - if not tip: - return False - tip.user_ids += user - body = tools.html_sanitize(tip.tip_description) - # FIXME: sanitize ? links ? - tip_description = self.env['mail.render.mixin']._render_template(body, 'digest.tip', self.ids)[self.id] - return tip_description + def compute_tips(self, company, user, tips_count=1): + tips = self.env['digest.tip'].search([ + ('user_ids', '!=', user.id), + '|', ('group_id', 'in', user.groups_id.ids), ('group_id', '=', False) + ], limit=tips_count) + tip_descriptions = [ + self.env['mail.render.mixin']._render_template(tools.html_sanitize(tip.tip_description), 'digest.tip', tip.ids, post_process=True)[tip.id] + for tip in tips + ] + # tip.user_ids += user + return tip_descriptions def compute_kpis_actions(self, company, user): """ Give an optional action to display in digest email linked to some KPIs.