diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 07606be1f75..ffb8a4c3dcb 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -84,7 +84,9 @@ def get_balance_on(account=None, date=None, party_type=None, party=None, in_acco if account: acc = frappe.get_doc("Account", account) - acc.check_permission("read") + + if not frappe.flags.ignore_account_permission: + acc.check_permission("read") # for pl accounts, get balance within a fiscal year if acc.report_type == 'Profit and Loss': @@ -198,7 +200,7 @@ def update_against_doc(d, jv_obj): """ jv_detail = jv_obj.get("accounts", {"name": d["voucher_detail_no"]})[0] jv_detail.set(d["dr_or_cr"], d["allocated_amt"]) - jv_detail.set('debit' if d['dr_or_cr']=='debit_in_account_currency' else 'credit', + jv_detail.set('debit' if d['dr_or_cr']=='debit_in_account_currency' else 'credit', d["allocated_amt"]*flt(jv_detail.exchange_rate)) original_reference_type = jv_detail.reference_type @@ -212,7 +214,7 @@ def update_against_doc(d, jv_obj): select cost_center, balance, against_account, is_advance, account_type, exchange_rate from `tabJournal Entry Account` where name = %s """, d['voucher_detail_no'], as_dict=True) - + amount_in_account_currency = flt(d['unadjusted_amt']) - flt(d['allocated_amt']) amount_in_company_currency = amount_in_account_currency * flt(jvd[0]['exchange_rate']) @@ -225,14 +227,14 @@ def update_against_doc(d, jv_obj): ch.party = d["party"] ch.cost_center = cstr(jvd[0]["cost_center"]) ch.balance = flt(jvd[0]["balance"]) - + ch.set(d['dr_or_cr'], amount_in_account_currency) ch.set('debit' if d['dr_or_cr']=='debit_in_account_currency' else 'credit', amount_in_company_currency) - - ch.set('credit_in_account_currency' if d['dr_or_cr']== 'debit_in_account_currency' + + ch.set('credit_in_account_currency' if d['dr_or_cr']== 'debit_in_account_currency' else 'debit_in_account_currency', 0) ch.set('credit' if d['dr_or_cr']== 'debit_in_account_currency' else 'debit', 0) - + ch.against_account = cstr(jvd[0]["against_account"]) ch.reference_type = original_reference_type ch.reference_name = original_reference_name diff --git a/erpnext/setup/doctype/email_digest/email_digest.js b/erpnext/setup/doctype/email_digest/email_digest.js index 0d2ea144448..9e3b4e6a5fa 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.js +++ b/erpnext/setup/doctype/email_digest/email_digest.js @@ -23,22 +23,24 @@ cur_frm.cscript.refresh = function(doc, dt, dn) { }); }, "icon-eye-open", "btn-default"); - cur_frm.add_custom_button(__('Send Now'), function() { - doc = locals[dt][dn]; - if(doc.__unsaved != 1) { - return $c_obj(doc, 'send', '', function(r, rt) { - if(r.exc) { - msgprint(err_msg); - console.log(r.exc); - } else { - //console.log(arguments); - msgprint(__('Message Sent')); - } - }); - } else { - msgprint(save_msg); - } - }, "icon-envelope", "btn-default"); + if(user==="Administrator") { + cur_frm.add_custom_button(__('Send Now'), function() { + doc = locals[dt][dn]; + if(doc.__unsaved != 1) { + return $c_obj(doc, 'send', '', function(r, rt) { + if(r.exc) { + msgprint(err_msg); + console.log(r.exc); + } else { + //console.log(arguments); + msgprint(__('Message Sent')); + } + }); + } else { + msgprint(save_msg); + } + }, "icon-envelope", "btn-default"); + } } cur_frm.cscript.addremove_recipients = function(doc, dt, dn) { diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py index 1dc317132bf..e62ff0fecda 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.py +++ b/erpnext/setup/doctype/email_digest/email_digest.py @@ -69,6 +69,8 @@ class EmailDigest(Document): def get_msg_html(self): """Build email digest content""" + frappe.flags.ignore_account_permission = True + context = frappe._dict() context.update(self.__dict__) @@ -84,6 +86,8 @@ class EmailDigest(Document): if not (context.events or context.todo_list or context.notifications or context.cards): return None + frappe.flags.ignore_account_permission = False + # style return frappe.render_template("erpnext/setup/doctype/email_digest/templates/default.html", context, is_path=True) @@ -103,11 +107,13 @@ class EmailDigest(Document): def set_style(self, context): """Set standard digest style""" context.text_muted = '#8D99A6' - context.h1 = 'margin-bottom: 30px; margin-bottom: 0' + context.text_color = '#36414C' + context.h1 = 'margin-bottom: 30px; margin-bottom: 0; margin-top: 40px; font-weight: 400;' context.label_css = '''display: inline-block; color: {text_muted}; padding: 3px 7px; margin-right: 7px;'''.format(text_muted = context.text_muted) - context.section_head = 'margin-top: 60px;' - context.line_item = 'padding: 7px 0px; margin: 0; border-bottom: 1px solid #d1d8dd;' + context.section_head = 'margin-top: 60px; font-size: 16px;' + context.line_item = 'padding: 5px 0px; margin: 0; border-bottom: 1px solid #d1d8dd;' + context.link_css = 'color: {text_color}; text-decoration: none;'.format(text_color = context.text_color) def get_notifications(self): @@ -154,25 +160,35 @@ class EmailDigest(Document): def set_accounting_cards(self, context): """Create accounting cards if checked""" + cache = frappe.cache() context.cards = [] for key in ("income", "expenses_booked", "income_year_to_date", "expense_year_to_date", "invoiced_amount", "payables", "bank_balance"): if self.get(key): - card = frappe._dict(getattr(self, "get_" + key)()) + cache_key = "email_digest:card:" + key + card = cache.get(cache_key) - # format values - if card.last_value: - card.diff = int(flt(card.value - card.last_value) / card.last_value * 100) - if card.diff < 0: - card.diff = str(card.diff) - card.gain = False - else: - card.diff = "+" + str(card.diff) - card.gain = True + if card: + card = eval(card) - card.last_value = self.fmt_money(card.last_value) + else: + card = frappe._dict(getattr(self, "get_" + key)()) - card.value = self.fmt_money(card.value) + # format values + if card.last_value: + card.diff = int(flt(card.value - card.last_value) / card.last_value * 100) + if card.diff < 0: + card.diff = str(card.diff) + card.gain = False + else: + card.diff = "+" + str(card.diff) + card.gain = True + + card.last_value = self.fmt_money(card.last_value) + + card.value = self.fmt_money(card.value) + + cache.setex(cache_key, card, 24 * 60 * 60) context.cards.append(card) diff --git a/erpnext/setup/doctype/email_digest/templates/default.html b/erpnext/setup/doctype/email_digest/templates/default.html index 460e8fa2a35..c836c466eab 100644 --- a/erpnext/setup/doctype/email_digest/templates/default.html +++ b/erpnext/setup/doctype/email_digest/templates/default.html @@ -1,9 +1,9 @@ {% macro show_card(card) %} -
{{ card.diff }}%
+{{ card.diff }}%
{% endif %}{% if frequency == "Daily "%} {{ frappe.format_date(future_from_date) }} {% else %} @@ -31,6 +31,7 @@ {% endif %} +{% if events or todo_list or notifications %}
| - {{ e.subject }} + {{ e.subject }} |
@@ -72,7 +73,7 @@
|