fixes in email digest

This commit is contained in:
Anand Doshi 2013-02-25 13:13:04 +05:30
parent 7bc7aefcbb
commit 98e78e7ccb
2 changed files with 82 additions and 52 deletions

View File

@ -17,14 +17,16 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes import _ from webnotes import _
from webnotes.utils import fmt_money, formatdate, now_datetime, cstr, esc, get_url_to_form from webnotes.utils import fmt_money, formatdate, now_datetime, cstr, esc, \
get_url_to_form, get_fullname
from webnotes.utils.dateutils import datetime_in_user_format from webnotes.utils.dateutils import datetime_in_user_format
from datetime import timedelta from datetime import timedelta
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
content_sequence = [ content_sequence = [
["Accounts", ["income_year_to_date", "bank_balance", ["Income / Expenses", ["income_year_to_date", "bank_balance",
"income", "expenses_booked", "collections", "payments", "income", "expenses_booked"]],
["Receivables / Payables", ["collections", "payments",
"invoiced_amount", "payables"]], "invoiced_amount", "payables"]],
["Buying", ["new_purchase_requests", "new_supplier_quotations", "new_purchase_orders"]], ["Buying", ["new_purchase_requests", "new_supplier_quotations", "new_purchase_orders"]],
["Selling", ["new_leads", "new_enquiries", "new_quotations", "new_sales_orders"]], ["Selling", ["new_leads", "new_enquiries", "new_quotations", "new_sales_orders"]],
@ -53,7 +55,8 @@ row_template = """<p style="%(style)s">
<span style="color: grey">%(currency)s</span>%(value)s <span style="color: grey">%(currency)s</span>%(value)s
</span></p>""" </span></p>"""
class DocType: from webnotes.model.controller import DocListController
class DocType(DocListController):
def __init__(self, doc, doclist=[]): def __init__(self, doc, doclist=[]):
self.doc, self.doclist = doc, doclist self.doc, self.doclist = doc, doclist
self.from_date, self.to_date = self.get_from_to_date() self.from_date, self.to_date = self.get_from_to_date()
@ -156,7 +159,7 @@ class DocType:
def get_income_year_to_date(self): def get_income_year_to_date(self):
return self.get_income(webnotes.conn.get_defaults("year_start_date"), return self.get_income(webnotes.conn.get_defaults("year_start_date"),
"Income Year To Date") self.meta.get_label("income_year_to_date"))
def get_bank_balance(self): def get_bank_balance(self):
# account is of type "Bank or Cash" # account is of type "Bank or Cash"
@ -186,7 +189,8 @@ class DocType:
if gle["account"] in accounts: if gle["account"] in accounts:
income += gle["credit"] - gle["debit"] income += gle["credit"] - gle["debit"]
return income, self.get_html(label or "Income", self.currency, fmt_money(income)) return income, self.get_html(label or self.meta.get_label("income"), self.currency,
fmt_money(income))
def get_expenses_booked(self): def get_expenses_booked(self):
# account is PL Account and Debit type account # account is PL Account and Debit type account
@ -198,13 +202,14 @@ class DocType:
if gle["account"] in accounts: if gle["account"] in accounts:
expense += gle["debit"] - gle["credit"] expense += gle["debit"] - gle["credit"]
return expense, self.get_html("Expenses", self.currency, fmt_money(expense)) return expense, self.get_html(self.meta.get_label("expenses_booked"), self.currency,
fmt_money(expense))
def get_collections(self): def get_collections(self):
return self.get_party_total("Customer", "credit", "Collections") return self.get_party_total("Customer", "credit", self.meta.get_label("collections"))
def get_payments(self): def get_payments(self):
return self.get_party_total("Supplier", "debit", "Payments") return self.get_party_total("Supplier", "debit", self.meta.get_label("payments"))
def get_party_total(self, party_type, gle_field, label): def get_party_total(self, party_type, gle_field, label):
import re import re
@ -222,16 +227,17 @@ class DocType:
# check that its made against a bank or cash account # check that its made against a bank or cash account
if gle["account"] in accounts and gle["against"] and \ if gle["account"] in accounts and gle["against"] and \
bc_regex.findall(gle["against"]): bc_regex.findall(gle["against"]):
total += gle[gle_field] val = gle["debit"] - gle["credit"]
total += (gle_field=="debit" and 1 or -1) * val
return total, self.get_html(label, self.currency, fmt_money(total)) return total, self.get_html(label, self.currency, fmt_money(total))
def get_invoiced_amount(self): def get_invoiced_amount(self):
# aka receivables # aka receivables
return self.get_booked_total("Customer", "debit", "Receivables") return self.get_booked_total("Customer", "debit", self.meta.get_label("invoiced_amount"))
def get_payables(self): def get_payables(self):
return self.get_booked_total("Supplier", "credit", "Payables") return self.get_booked_total("Supplier", "credit", self.meta.get_label("payables"))
def get_booked_total(self, party_type, gle_field, label): def get_booked_total(self, party_type, gle_field, label):
# account is of master_type Customer or Supplier # account is of master_type Customer or Supplier
@ -246,45 +252,46 @@ class DocType:
return total, self.get_html(label, self.currency, fmt_money(total)) return total, self.get_html(label, self.currency, fmt_money(total))
def get_new_leads(self): def get_new_leads(self):
return self.get_new_count("Lead", "New Leads") return self.get_new_count("Lead", self.meta.get_label("new_leads"))
def get_new_enquiries(self): def get_new_enquiries(self):
return self.get_new_count("Opportunity", "New Opportunities") return self.get_new_count("Opportunity", self.meta.get_label("new_enquiries"))
def get_new_quotations(self): def get_new_quotations(self):
return self.get_new_sum("Quotation", "New Quotations", "grand_total") return self.get_new_sum("Quotation", self.meta.get_label("new_quotations"), "grand_total")
def get_new_sales_orders(self): def get_new_sales_orders(self):
return self.get_new_sum("Sales Order", "New Sales Orders", "grand_total") return self.get_new_sum("Sales Order", self.meta.get_label("new_sales_orders"), "grand_total")
def get_new_delivery_notes(self): def get_new_delivery_notes(self):
return self.get_new_sum("Delivery Note", "New Delivery Notes", "grand_total") return self.get_new_sum("Delivery Note", self.meta.get_label("new_delivery_notes"), "grand_total")
def get_new_purchase_requests(self): def get_new_purchase_requests(self):
return self.get_new_count("Material Request", "New Material Requests") return self.get_new_count("Material Request", self.meta.get_label("new_purchase_requests"))
def get_new_supplier_quotations(self): def get_new_supplier_quotations(self):
return self.get_new_sum("Supplier Quotation", "New Supplier Quotations", return self.get_new_sum("Supplier Quotation", self.meta.get_label("new_supplier_quotations"),
"grand_total") "grand_total")
def get_new_purchase_orders(self): def get_new_purchase_orders(self):
return self.get_new_sum("Purchase Order", "New Purchase Orders", "grand_total") return self.get_new_sum("Purchase Order", self.meta.get_label("new_purchase_orders"),
"grand_total")
def get_new_purchase_receipts(self): def get_new_purchase_receipts(self):
return self.get_new_sum("Purchase Receipt", "New Purchase Receipts", return self.get_new_sum("Purchase Receipt", self.meta.get_label("new_purchase_receipts"),
"grand_total") "grand_total")
def get_new_stock_entries(self): def get_new_stock_entries(self):
return self.get_new_sum("Stock Entry", "New Stock Entries", "total_amount") return self.get_new_sum("Stock Entry", self.meta.get_label("new_stock_entries"), "total_amount")
def get_new_support_tickets(self): def get_new_support_tickets(self):
return self.get_new_count("Support Ticket", "New Support Tickets", False) return self.get_new_count("Support Ticket", self.meta.get_label("new_support_tickets"), False)
def get_new_communications(self): def get_new_communications(self):
return self.get_new_count("Communication", "New Communications", False) return self.get_new_count("Communication", self.meta.get_label("new_communications"), False)
def get_new_projects(self): def get_new_projects(self):
return self.get_new_count("Project", "New Projects", False) return self.get_new_count("Project", self.meta.get_label("new_projects"), False)
def get_calendar_events(self, user_id): def get_calendar_events(self, user_id):
from core.doctype.event.event import get_events from core.doctype.event.event import get_events
@ -302,7 +309,10 @@ class DocType:
html += "<li style='line-height: 200%%'>%s [%s - %s]</li>" % \ html += "<li style='line-height: 200%%'>%s [%s - %s]</li>" % \
(e.subject, datetime_in_user_format(e.starts_on), datetime_in_user_format(e.ends_on)) (e.subject, datetime_in_user_format(e.starts_on), datetime_in_user_format(e.ends_on))
return html and 1 or 0, "<h4>Upcoming Calendar Events (max 10):</h4><ul>" + html + "</ul><hr>" if html:
return 1, "<h4>Upcoming Calendar Events (max 10):</h4><ul>" + html + "</ul><hr>"
else:
return 0, "<p>Calendar Events</p>"
def get_todo_list(self, user_id): def get_todo_list(self, user_id):
from utilities.page.todo.todo import get from utilities.page.todo.todo import get
@ -313,11 +323,17 @@ class DocType:
for i, todo in enumerate([todo for todo in todo_list if not todo.checked]): for i, todo in enumerate([todo for todo in todo_list if not todo.checked]):
if i>= 10: if i>= 10:
break break
html += "<li style='line-height: 200%%'>%s [%s]</li>" % (todo.description or \ if not todo.description and todo.reference_type:
get_url_to_form(todo.reference_type, todo.reference_name), todo.priority) todo.description = "%s: %s - %s %s" % \
(todo.reference_type, get_url_to_form(todo.reference_type, todo.reference_name),
_("assigned by"), get_fullname(todo.assigned_by))
html += "<li style='line-height: 200%%'>%s [%s]</li>" % (todo.description, todo.priority)
return html and 1 or 0, "<h4>To Do (max 10):</h4><ul>" + html + "</ul><hr>" if html:
return 1, "<h4>To Do (max 10):</h4><ul>" + html + "</ul><hr>"
else:
return 0, "<p>To Do</p>"
def get_new_count(self, doctype, label, filter_by_company=True): def get_new_count(self, doctype, label, filter_by_company=True):
if filter_by_company: if filter_by_company:
@ -376,7 +392,7 @@ class DocType:
self.accounts = webnotes.conn.sql("""select name, is_pl_account, self.accounts = webnotes.conn.sql("""select name, is_pl_account,
debit_or_credit, account_type, account_name, master_type debit_or_credit, account_type, account_name, master_type
from `tabAccount` where company=%s and docstatus < 2 from `tabAccount` where company=%s and docstatus < 2
order by lft""", and group_or_ledger = "Ledger" order by lft""",
(self.doc.company,), as_dict=1) (self.doc.company,), as_dict=1)
return self.accounts return self.accounts

View File

@ -1,8 +1,8 @@
[ [
{ {
"creation": "2013-02-18 13:36:19", "creation": "2013-02-21 14:15:31",
"docstatus": 0, "docstatus": 0,
"modified": "2013-02-18 13:43:50", "modified": "2013-02-25 13:08:26",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -109,7 +109,7 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "accounts_module", "fieldname": "accounts_module",
"fieldtype": "Column Break", "fieldtype": "Column Break",
"label": "Accounts" "label": "Income / Expense"
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@ -118,47 +118,67 @@
"label": "Income Year to Date" "label": "Income Year to Date"
}, },
{ {
"description": "Balances of Accounts of type \"Bank or Cash\"",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "bank_balance", "fieldname": "bank_balance",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Bank Balance" "label": "Bank/Cash Balance"
}, },
{ {
"description": "Income booked for the digest period",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "income", "fieldname": "income",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Income" "label": "Income Booked"
}, },
{ {
"description": "Expenses booked for the digest period",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "expenses_booked", "fieldname": "expenses_booked",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Expenses Booked" "label": "Expenses Booked"
}, },
{ {
"description": "Receivable / Payable account will be identified based on the field Master Type",
"doctype": "DocField",
"fieldname": "column_break_16",
"fieldtype": "Column Break",
"label": "Receivables / Payables"
},
{
"description": "Payments received during the digest period",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "collections", "fieldname": "collections",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Collections" "label": "Payments Received"
}, },
{ {
"description": "Payments made during the digest period",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "payments", "fieldname": "payments",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Payments" "label": "Payments Made"
}, },
{ {
"description": "Total amount of invoices sent to the customer during the digest period",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "invoiced_amount", "fieldname": "invoiced_amount",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Receivables" "label": "Receivables"
}, },
{ {
"description": "Total amount of invoices received from suppliers during the digest period",
"doctype": "DocField", "doctype": "DocField",
"fieldname": "payables", "fieldname": "payables",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Payables" "label": "Payables"
}, },
{
"doctype": "DocField",
"fieldname": "section_break_20",
"fieldtype": "Section Break",
"options": "Simple"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "buying_module", "fieldname": "buying_module",
@ -213,12 +233,6 @@
"fieldtype": "Check", "fieldtype": "Check",
"label": "New Sales Orders" "label": "New Sales Orders"
}, },
{
"doctype": "DocField",
"fieldname": "section_break_34",
"fieldtype": "Section Break",
"options": "Simple"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "stock_module", "fieldname": "stock_module",
@ -243,6 +257,12 @@
"fieldtype": "Check", "fieldtype": "Check",
"label": "New Stock Entries" "label": "New Stock Entries"
}, },
{
"doctype": "DocField",
"fieldname": "section_break_34",
"fieldtype": "Section Break",
"options": "Simple"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "support_module", "fieldname": "support_module",
@ -279,12 +299,6 @@
"fieldtype": "Check", "fieldtype": "Check",
"label": "New Projects" "label": "New Projects"
}, },
{
"doctype": "DocField",
"fieldname": "section_break_41",
"fieldtype": "Section Break",
"options": "Simple"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "utilities_module", "fieldname": "utilities_module",