[fixes] email digest

This commit is contained in:
Rushabh Mehta
2015-10-15 16:31:16 +05:30
parent 3a519f269d
commit 2e7f9d2b8f
4 changed files with 69 additions and 46 deletions

View File

@@ -84,7 +84,9 @@ def get_balance_on(account=None, date=None, party_type=None, party=None, in_acco
if account: if account:
acc = frappe.get_doc("Account", 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 # for pl accounts, get balance within a fiscal year
if acc.report_type == 'Profit and Loss': 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 = jv_obj.get("accounts", {"name": d["voucher_detail_no"]})[0]
jv_detail.set(d["dr_or_cr"], d["allocated_amt"]) 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)) d["allocated_amt"]*flt(jv_detail.exchange_rate))
original_reference_type = jv_detail.reference_type 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 select cost_center, balance, against_account, is_advance, account_type, exchange_rate
from `tabJournal Entry Account` where name = %s from `tabJournal Entry Account` where name = %s
""", d['voucher_detail_no'], as_dict=True) """, d['voucher_detail_no'], as_dict=True)
amount_in_account_currency = flt(d['unadjusted_amt']) - flt(d['allocated_amt']) 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']) 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.party = d["party"]
ch.cost_center = cstr(jvd[0]["cost_center"]) ch.cost_center = cstr(jvd[0]["cost_center"])
ch.balance = flt(jvd[0]["balance"]) ch.balance = flt(jvd[0]["balance"])
ch.set(d['dr_or_cr'], amount_in_account_currency) 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('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) else 'debit_in_account_currency', 0)
ch.set('credit' if d['dr_or_cr']== 'debit_in_account_currency' else 'debit', 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.against_account = cstr(jvd[0]["against_account"])
ch.reference_type = original_reference_type ch.reference_type = original_reference_type
ch.reference_name = original_reference_name ch.reference_name = original_reference_name

View File

@@ -23,22 +23,24 @@ cur_frm.cscript.refresh = function(doc, dt, dn) {
}); });
}, "icon-eye-open", "btn-default"); }, "icon-eye-open", "btn-default");
cur_frm.add_custom_button(__('Send Now'), function() { if(user==="Administrator") {
doc = locals[dt][dn]; cur_frm.add_custom_button(__('Send Now'), function() {
if(doc.__unsaved != 1) { doc = locals[dt][dn];
return $c_obj(doc, 'send', '', function(r, rt) { if(doc.__unsaved != 1) {
if(r.exc) { return $c_obj(doc, 'send', '', function(r, rt) {
msgprint(err_msg); if(r.exc) {
console.log(r.exc); msgprint(err_msg);
} else { console.log(r.exc);
//console.log(arguments); } else {
msgprint(__('Message Sent')); //console.log(arguments);
} msgprint(__('Message Sent'));
}); }
} else { });
msgprint(save_msg); } else {
} msgprint(save_msg);
}, "icon-envelope", "btn-default"); }
}, "icon-envelope", "btn-default");
}
} }
cur_frm.cscript.addremove_recipients = function(doc, dt, dn) { cur_frm.cscript.addremove_recipients = function(doc, dt, dn) {

View File

@@ -69,6 +69,8 @@ class EmailDigest(Document):
def get_msg_html(self): def get_msg_html(self):
"""Build email digest content""" """Build email digest content"""
frappe.flags.ignore_account_permission = True
context = frappe._dict() context = frappe._dict()
context.update(self.__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): if not (context.events or context.todo_list or context.notifications or context.cards):
return None return None
frappe.flags.ignore_account_permission = False
# style # style
return frappe.render_template("erpnext/setup/doctype/email_digest/templates/default.html", return frappe.render_template("erpnext/setup/doctype/email_digest/templates/default.html",
context, is_path=True) context, is_path=True)
@@ -103,11 +107,13 @@ class EmailDigest(Document):
def set_style(self, context): def set_style(self, context):
"""Set standard digest style""" """Set standard digest style"""
context.text_muted = '#8D99A6' 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}; context.label_css = '''display: inline-block; color: {text_muted};
padding: 3px 7px; margin-right: 7px;'''.format(text_muted = context.text_muted) padding: 3px 7px; margin-right: 7px;'''.format(text_muted = context.text_muted)
context.section_head = 'margin-top: 60px;' context.section_head = 'margin-top: 60px; font-size: 16px;'
context.line_item = 'padding: 7px 0px; margin: 0; border-bottom: 1px solid #d1d8dd;' 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): def get_notifications(self):
@@ -154,25 +160,35 @@ class EmailDigest(Document):
def set_accounting_cards(self, context): def set_accounting_cards(self, context):
"""Create accounting cards if checked""" """Create accounting cards if checked"""
cache = frappe.cache()
context.cards = [] context.cards = []
for key in ("income", "expenses_booked", "income_year_to_date", "expense_year_to_date", for key in ("income", "expenses_booked", "income_year_to_date", "expense_year_to_date",
"invoiced_amount", "payables", "bank_balance"): "invoiced_amount", "payables", "bank_balance"):
if self.get(key): 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:
if card.last_value: card = eval(card)
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) 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) context.cards.append(card)

View File

@@ -1,9 +1,9 @@
{% macro show_card(card) %} {% macro show_card(card) %}
<div style="width: 50%; float:left; min-height: 120px; padding-top: 20px;"> <div style="width: 50%; float:left; min-height: 80px; padding-top: 20px;">
<h6 style="color: {{ text_muted }}">{{ card.label }}</h6> <h6 style="color: {{ text_muted }}; font-size: 12px; margin-bottom: 0px; margin-top: 0px;">{{ card.label }}</h6>
<h4>{{ card.value }}</h4> <h4 style="margin-top: 7px; font-size: 16px;">{{ card.value }}</h4>
{% if card.diff %} {% if card.diff %}
<p style="color: {{ text_muted }}">{{ card.diff }}%</p> <p style="color: {{ text_muted }}; font-size: 12px;">{{ card.diff }}%</p>
{% endif %} {% endif %}
</div> </div>
{% endmacro %} {% endmacro %}
@@ -12,7 +12,7 @@
{% if cards %} {% if cards %}
<h1 style="{{ h1 }}">{{ title }}</h1> <h1 style="{{ h1 }}">{{ title }}</h1>
<h4 style="font-weight: normal; color: {{ text_muted }}; margin-top: 7px"> <h4 style="font-weight: normal; color: {{ text_muted }}; margin-top: 7px; font-size: 16px; margin-top: 7px;">
<p>{% if frequency == "Daily "%} <p>{% if frequency == "Daily "%}
{{ frappe.format_date(future_from_date) }} {{ frappe.format_date(future_from_date) }}
{% else %} {% else %}
@@ -31,6 +31,7 @@
{% endif %} {% endif %}
{% if events or todo_list or notifications %}
<h1 style="{{ h1 }}">{{ _("Pending Activities") }}</h1> <h1 style="{{ h1 }}">{{ _("Pending Activities") }}</h1>
<!-- events --> <!-- events -->
@@ -45,7 +46,7 @@
<table style="width: 100%;"> <table style="width: 100%;">
<tr> <tr>
<td> <td>
<a href="{{ e.link }}">{{ e.subject }}</a> <a style="{{ link_css }}" href="{{ e.link }}">{{ e.subject }}</a>
</td> </td>
<td style="width: 40%; text-align: right"> <td style="width: 40%; text-align: right">
<span style="{{ label_css }}"> <span style="{{ label_css }}">
@@ -72,7 +73,7 @@
<table style="width: 100%;"> <table style="width: 100%;">
<tr> <tr>
<td> <td>
<a href="{{ t.link }}">{{ t.description }}</a> <a style="{{ link_css }}" href="{{ t.link }}">{{ t.description }}</a>
</td> </td>
<td style="width: 25%; text-align: right"> <td style="width: 25%; text-align: right">
<span style="{{ label_css }}"> <span style="{{ label_css }}">
@@ -95,7 +96,7 @@
<table style="width: 100%;"> <table style="width: 100%;">
<tr> <tr>
<td> <td>
<a href="n.link">{{ n.key }}</a> <a style="{{ link_css }}" href="{{ n.link }}">{{ n.key }}</a>
</td> </td>
<td style="width: 25%; text-align: right"> <td style="width: 25%; text-align: right">
<span style="{{ label_css }}"> <span style="{{ label_css }}">
@@ -109,3 +110,5 @@
</div> </div>
{% endif %} {% endif %}
</div> </div>
{% endif %}