From 2c5b3e83f571cd3f886f093520d55db4356e85d1 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Thu, 13 Jul 2017 18:37:18 +0530 Subject: [PATCH] New design for daily work summary (#9844) * New design for daily work summary * Update tests --- erpnext/hooks.py | 2 + .../daily_work_summary/daily_work_summary.py | 47 ++++++--------- .../test_daily_work_summary.py | 4 +- .../templates/emails/daily_work_summary.html | 59 +++++++++++++++++++ .../templates/emails/daily_work_summary.txt | 11 ++++ 5 files changed, 91 insertions(+), 32 deletions(-) create mode 100644 erpnext/templates/emails/daily_work_summary.html create mode 100644 erpnext/templates/emails/daily_work_summary.txt diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 6777a71694b..6ff0a13c8d3 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -193,6 +193,8 @@ scheduler_events = { ] } +email_brand_image = "assets/erpnext/images/erpnext-logo.jpg" + default_mail_footer = """
Sent via ERPNext diff --git a/erpnext/hr/doctype/daily_work_summary/daily_work_summary.py b/erpnext/hr/doctype/daily_work_summary/daily_work_summary.py index 7fff5f52df4..f03c6fa491d 100644 --- a/erpnext/hr/doctype/daily_work_summary/daily_work_summary.py +++ b/erpnext/hr/doctype/daily_work_summary/daily_work_summary.py @@ -8,7 +8,7 @@ from frappe.model.document import Document from frappe import _ from email_reply_parser import EmailReplyParser from erpnext.hr.doctype.employee.employee import is_holiday -from frappe.utils import formatdate +from frappe.utils import global_date_format from markdown2 import markdown class DailyWorkSummary(Document): @@ -24,17 +24,18 @@ class DailyWorkSummary(Document): def send_summary(self): '''Send summary of all replies. Called at midnight''' - message = self.get_summary_message() + args = self.get_message_details() frappe.sendmail(recipients = get_employee_emails(self.company, False), - message = message, + template='daily_work_summary', + args=args, subject = _('Daily Work Summary for {0}').format(self.company), reference_doctype=self.doctype, reference_name=self.name) self.db_set('status', 'Sent') - def get_summary_message(self): - '''Return summary of replies as HTML''' + def get_message_details(self): + '''Return args for template''' settings = frappe.get_doc('Daily Work Summary Settings') replies = frappe.get_all('Communication', fields=['content', 'text_content', 'sender'], @@ -45,8 +46,12 @@ class DailyWorkSummary(Document): did_not_reply = self.email_sent_to.split() for d in replies: - d.sender_name = frappe.db.get_value("Employee", {"user_id": d.sender}, - "employee_name") or d.sender + emp = frappe.db.get_values("Employee", {"user_id": d.sender}, + ["employee_name", "image"], as_dict=True) + + d.sender_name = emp[0].employee_name if emp else d.sender + d.image = emp[0].image if emp and emp[0].image else None + if d.sender in did_not_reply: did_not_reply.remove(d.sender) if d.text_content: @@ -56,30 +61,12 @@ class DailyWorkSummary(Document): did_not_reply = [(frappe.db.get_value("Employee", {"user_id": email}, "employee_name") or email) for email in did_not_reply] - return frappe.render_template(self.get_summary_template(), - dict(replies=replies, - original_message=settings.message, - title=_('Daily Work Summary for {0}'.format(formatdate(self.creation))), - did_not_reply= ', '.join(did_not_reply) or '', - did_not_reply_title = _('No replies from'))) + return dict(replies=replies, + original_message=settings.message, + title=_('Daily Work Summary for {0}'.format(global_date_format(self.creation))), + did_not_reply= ', '.join(did_not_reply) or '', + did_not_reply_title = _('No replies from')) - def get_summary_template(self): - return ''' -

{{ title }}

- -{% for reply in replies %} -

{{ reply.sender_name }}

-

- {{ reply.content }} -

-
-{% endfor %} - -{% if did_not_reply %} -

{{ did_not_reply_title }}: {{ did_not_reply }}

-{% endif %} - -''' def get_employee_emails(company, only_working=True): '''Returns list of Employee user ids for the given company who are working today diff --git a/erpnext/hr/doctype/daily_work_summary/test_daily_work_summary.py b/erpnext/hr/doctype/daily_work_summary/test_daily_work_summary.py index ad9d43f5519..63e6fdf9f29 100644 --- a/erpnext/hr/doctype/daily_work_summary/test_daily_work_summary.py +++ b/erpnext/hr/doctype/daily_work_summary/test_daily_work_summary.py @@ -46,9 +46,9 @@ class TestDailyWorkSummary(unittest.TestCase): daily_work_summary = frappe.get_doc('Daily Work Summary', frappe.get_all('Daily Work Summary')[0].name) - summary = daily_work_summary.get_summary_message() + args = daily_work_summary.get_message_details() - self.assertTrue('I built Daily Work Summary!' in summary) + self.assertTrue('I built Daily Work Summary!' in args.get('replies')[0].content) def setup_and_prepare_test(self, hour=None): frappe.db.sql('delete from `tabDaily Work Summary`') diff --git a/erpnext/templates/emails/daily_work_summary.html b/erpnext/templates/emails/daily_work_summary.html new file mode 100644 index 00000000000..726de3b8906 --- /dev/null +++ b/erpnext/templates/emails/daily_work_summary.html @@ -0,0 +1,59 @@ + + +
+

{{ title }}

+
+ +
+{% for reply in replies %} + + + + + + + + + + +
+ {% if reply.image %} + + {% else %} +
+ {{ reply.sender_name[0] }} +
+ {% endif %} +
+
+ {{ reply.sender_name }} +
+
+ + + + + + + + +
+
+ {{ reply.content }} +
+
+ + +
+{% endfor %} +{% if did_not_reply %} + + +
+

{{ did_not_reply_title }}: {{ did_not_reply }}

+
+ +
+{% endif %} \ No newline at end of file diff --git a/erpnext/templates/emails/daily_work_summary.txt b/erpnext/templates/emails/daily_work_summary.txt new file mode 100644 index 00000000000..2fb4380d8ff --- /dev/null +++ b/erpnext/templates/emails/daily_work_summary.txt @@ -0,0 +1,11 @@ +{{ title }} + +{% for reply in replies %} +{{ reply.sender_name }}: +{{ reply.content }} + + +{% endfor %} +{% if did_not_reply %} +{{ did_not_reply_title }}: {{ did_not_reply }} +{% endif %} \ No newline at end of file