Rewrote query using orm

This commit is contained in:
deepeshgarg007 2018-11-29 16:24:28 +05:30
parent c981fb389b
commit ee05e358d1

View File

@ -462,22 +462,22 @@ def get_dashboard_info(party_type, party):
doctype = "Sales Invoice" if party_type=="Customer" else "Purchase Invoice" doctype = "Sales Invoice" if party_type=="Customer" else "Purchase Invoice"
companies = frappe.db.sql(""" companies = frappe.get_all(doctype, filters={
select distinct company from `tab{0}` 'docstatus': 1,
where docstatus =1 and {1} = %s party_type.lower(): party
""" }, distinct=1, fields=['company'])
.format(doctype, party_type.lower()), (party), as_dict=1)
company_wise_info = [] company_wise_info = []
company_wise_grand_total = frappe.db.sql(""" company_wise_grand_total = frappe.get_all(doctype,
select company, sum(grand_total) as grand_total, sum(base_grand_total) as base_grand_total filters={
from `tab{0}` 'docstatus': 1,
where {1}=%s and docstatus=1 and posting_date between %s and %s party_type.lower(): party,
group by company 'posting_date': ('between', [current_fiscal_year.year_start_date, current_fiscal_year.year_end_date])
""" },
.format(doctype, party_type.lower()), group_by="company",
(party, current_fiscal_year.year_start_date, current_fiscal_year.year_end_date), as_dict=1) fields=["company", "sum(grand_total) as grand_total", "sum(base_grand_total) as base_grand_total"]
)
company_wise_billing_this_year = frappe._dict() company_wise_billing_this_year = frappe._dict()