Merge pull request #2051 from anandpdoshi/anand-august-12

[logic] Email Digest - use transaction/posting date
This commit is contained in:
Anand Doshi 2014-08-12 19:51:22 +05:30
commit cf8bb668b3
2 changed files with 32 additions and 23 deletions

View File

@ -28,7 +28,7 @@ erpnext.selling.Opportunity = frappe.ui.form.Controller.extend({
if(!this.frm.doc.__islocal) { if(!this.frm.doc.__islocal) {
cur_frm.communication_view = new frappe.views.CommunicationList({ cur_frm.communication_view = new frappe.views.CommunicationList({
list: frappe.get_list("Communication", {"opportunity": this.frm.doc.name}), list: frappe.get_list("Communication", {"parent": this.frm.doc.name, "parenttype": "Opportunity"}),
parent: cur_frm.fields_dict.communication_html.wrapper, parent: cur_frm.fields_dict.communication_html.wrapper,
doc: this.frm.doc, doc: this.frm.doc,
recipients: this.frm.doc.contact_email recipients: this.frm.doc.contact_email

View File

@ -247,35 +247,40 @@ class EmailDigest(Document):
return self.get_new_count("Lead", self.meta.get_label("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", self.meta.get_label("new_enquiries"), docstatus=1) return self.get_new_count("Opportunity", self.meta.get_label("new_enquiries"), docstatus=1,
date_field="transaction_date")
def get_new_quotations(self): def get_new_quotations(self):
return self.get_new_sum("Quotation", self.meta.get_label("new_quotations"), "grand_total") return self.get_new_sum("Quotation", self.meta.get_label("new_quotations"), "grand_total",
date_field="transaction_date")
def get_new_sales_orders(self): def get_new_sales_orders(self):
return self.get_new_sum("Sales Order", self.meta.get_label("new_sales_orders"), "grand_total") return self.get_new_sum("Sales Order", self.meta.get_label("new_sales_orders"), "grand_total",
date_field="transaction_date")
def get_new_delivery_notes(self): def get_new_delivery_notes(self):
return self.get_new_sum("Delivery Note", self.meta.get_label("new_delivery_notes"), "grand_total") return self.get_new_sum("Delivery Note", self.meta.get_label("new_delivery_notes"), "grand_total",
date_field="posting_date")
def get_new_purchase_requests(self): def get_new_purchase_requests(self):
return self.get_new_count("Material Request", return self.get_new_count("Material Request", self.meta.get_label("new_purchase_requests"), docstatus=1,
self.meta.get_label("new_purchase_requests"), docstatus=1) date_field="transaction_date")
def get_new_supplier_quotations(self): def get_new_supplier_quotations(self):
return self.get_new_sum("Supplier Quotation", self.meta.get_label("new_supplier_quotations"), return self.get_new_sum("Supplier Quotation", self.meta.get_label("new_supplier_quotations"),
"grand_total") "grand_total", date_field="transaction_date")
def get_new_purchase_orders(self): def get_new_purchase_orders(self):
return self.get_new_sum("Purchase Order", self.meta.get_label("new_purchase_orders"), return self.get_new_sum("Purchase Order", self.meta.get_label("new_purchase_orders"),
"grand_total") "grand_total", date_field="transaction_date")
def get_new_purchase_receipts(self): def get_new_purchase_receipts(self):
return self.get_new_sum("Purchase Receipt", self.meta.get_label("new_purchase_receipts"), return self.get_new_sum("Purchase Receipt", self.meta.get_label("new_purchase_receipts"),
"grand_total") "grand_total", date_field="posting_date")
def get_new_stock_entries(self): def get_new_stock_entries(self):
return self.get_new_sum("Stock Entry", self.meta.get_label("new_stock_entries"), "total_amount") return self.get_new_sum("Stock Entry", self.meta.get_label("new_stock_entries"), "total_amount",
date_field="posting_date")
def get_new_support_tickets(self): def get_new_support_tickets(self):
return self.get_new_count("Support Ticket", self.meta.get_label("new_support_tickets"), return self.get_new_count("Support Ticket", self.meta.get_label("new_support_tickets"),
@ -333,24 +338,28 @@ class EmailDigest(Document):
else: else:
return 0, "<p>To Do</p>" return 0, "<p>To Do</p>"
def get_new_count(self, doctype, label, docstatus=0, filter_by_company=True): def get_new_count(self, doctype, label, docstatus=0, filter_by_company=True, date_field="creation"):
if filter_by_company: if filter_by_company:
company = """and company="%s" """ % self.company.replace('"', '\"') company_condition = """and company="%s" """ % self.company.replace('"', '\"')
else: else:
company = "" company_condition = ""
count = frappe.db.sql("""select count(*) from `tab%s`
where docstatus=%s %s and count = frappe.db.sql("""select count(*) from `tab{doctype}`
date(creation)>=%s and date(creation)<=%s""" % where ifnull(`docstatus`, 0)=%s {company_condition} and
(doctype, docstatus, company, "%s", "%s"), (self.from_date, self.to_date)) date(`{date_field}`)>=%s and date({date_field})<=%s""".format(doctype=doctype,
company_condition=company_condition, date_field=date_field),
(docstatus, self.from_date, self.to_date))
count = count and count[0][0] or 0 count = count and count[0][0] or 0
return count, self.get_html(label, None, count) return count, self.get_html(label, None, count)
def get_new_sum(self, doctype, label, sum_field): def get_new_sum(self, doctype, label, sum_field, date_field="creation"):
count_sum = frappe.db.sql("""select count(*), sum(ifnull(`%s`, 0)) count_sum = frappe.db.sql("""select count(*), sum(ifnull(`{sum_field}`, 0))
from `tab%s` where docstatus=1 and company = %s and from `tab{doctype}` where docstatus=1 and company = %s and
date(creation)>=%s and date(creation)<=%s""" % (sum_field, doctype, "%s", date(`{date_field}`)>=%s and date(`{date_field}`)<=%s""".format(sum_field=sum_field,
"%s", "%s"), (self.company, self.from_date, self.to_date)) date_field=date_field, doctype=doctype), (self.company, self.from_date, self.to_date))
count, total = count_sum and count_sum[0] or (0, 0) count, total = count_sum and count_sum[0] or (0, 0)
return count, self.get_html(label, self.currency, return count, self.get_html(label, self.currency,