[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:
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

View File

@ -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) {

View File

@ -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)

View File

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