New design for daily work summary (#9844)
* New design for daily work summary
* Update tests
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index 6777a71..6ff0a13 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -193,6 +193,8 @@
]
}
+email_brand_image = "assets/erpnext/images/erpnext-logo.jpg"
+
default_mail_footer = """<div style="text-align: center;">
<a href="https://erpnext.com?source=via_email_footer" target="_blank" style="color: #8d99a6;">
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 7fff5f5..f03c6fa 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 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 @@
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 @@
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 @@
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 '''
-<h3>{{ title }}</h3>
-
-{% for reply in replies %}
-<h4>{{ reply.sender_name }}</h4>
-<p style="padding-bottom: 20px">
- {{ reply.content }}
-</p>
-<hr>
-{% endfor %}
-
-{% if did_not_reply %}
-<p>{{ did_not_reply_title }}: {{ did_not_reply }}</p>
-{% 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 ad9d43f..63e6fdf 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 @@
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 0000000..726de3b
--- /dev/null
+++ b/erpnext/templates/emails/daily_work_summary.html
@@ -0,0 +1,59 @@
+<table border="0" cellpadding="0" cellspacing="0" width="100%">
+ <tr>
+ <div style="color: #333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; word-wrap: break-word; overflow-wrap: break-word;">
+ <h3>{{ title }}</h3>
+ </div>
+ </tr>
+</table>
+{% for reply in replies %}
+<table border="0" cellpadding="0" cellspacing="0" width="100%"
+ style="background-color: #fafbfc; border: 1px solid #d1d8dd; border-radius: 3px 3px 0 0">
+ <tr height="10"></tr>
+ <tr>
+ <td width="15"></td>
+ <td valign="top" width="24">
+ {% if reply.image %}
+ <img width="24" height="24" embed="{{ reply.image }}" style="border-radius: 3px; vertical-align: middle;" />
+ {% else %}
+ <div style="width: 24px; height: 24px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;background: #fff; border-radius: 3px; border: 1px solid #d1d8dd; text-align: center; line-height: 24px; color: #d1d8dd;">
+ {{ reply.sender_name[0] }}
+ </div>
+ {% endif %}
+ </td>
+ <td width="10"></td>
+ <td>
+ <div style="font-size: 12px; color: #8D99A6; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; word-wrap: break-word; line-height: 22px; overflow-wrap: break-word; text-decoration: none;">
+ <span>{{ reply.sender_name }}</span>
+ </div>
+ </td>
+ <td width="15"></td>
+ </tr>
+ <tr height="10"></tr>
+</table>
+<table border="0" cellpadding="0" cellspacing="0" width="100%"
+ style="background-color: #fff; border: 1px solid #d1d8dd; border-top: none; border-radius: 0 0 3px 3px">
+ <tr height="10"></tr>
+ <tr>
+ <td width="15"></td>
+ <td>
+ <div style="font-size: 14px; color: #333; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; word-wrap: break-word; line-height: 22px; overflow-wrap: break-word; text-decoration: none;">
+ {{ reply.content }}
+ </div>
+ </td>
+ <td width="15"></td>
+ </tr>
+ <tr height="10"></tr>
+</table>
+<table border="0" cellpadding="0" cellspacing="0" width="100%">
+ <tr height="20"></tr>
+</table>
+{% endfor %}
+{% if did_not_reply %}
+<table border="0" cellpadding="0" cellspacing="0" width="100%">
+ <tr>
+ <div style="font-size: 14px; color: #8D99A6; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; word-wrap: break-word; line-height: 22px; overflow-wrap: break-word; text-decoration: none;">
+ <p>{{ did_not_reply_title }}: {{ did_not_reply }}</p>
+ </div>
+ </tr>
+</table>
+{% 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 0000000..2fb4380
--- /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