mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 08:24:47 +00:00
Merge pull request #16065 from deepeshgarg007/supplier-customer-dashboard-fix
Customer/Supplier dashboard fix for multi company setup
This commit is contained in:
@@ -459,38 +459,65 @@ def get_timeline_data(doctype, name):
|
|||||||
|
|
||||||
def get_dashboard_info(party_type, party):
|
def get_dashboard_info(party_type, party):
|
||||||
current_fiscal_year = get_fiscal_year(nowdate(), as_dict=True)
|
current_fiscal_year = get_fiscal_year(nowdate(), as_dict=True)
|
||||||
company = frappe.db.get_default("company") or frappe.get_all("Company")[0].name
|
|
||||||
party_account_currency = get_party_account_currency(party_type, party, company)
|
|
||||||
company_default_currency = get_default_currency() \
|
|
||||||
or frappe.get_cached_value('Company', company, 'default_currency')
|
|
||||||
|
|
||||||
if party_account_currency==company_default_currency:
|
|
||||||
total_field = "base_grand_total"
|
|
||||||
else:
|
|
||||||
total_field = "grand_total"
|
|
||||||
|
|
||||||
doctype = "Sales Invoice" if party_type=="Customer" else "Purchase Invoice"
|
doctype = "Sales Invoice" if party_type=="Customer" else "Purchase Invoice"
|
||||||
|
|
||||||
billing_this_year = frappe.db.sql("""
|
companies = frappe.get_all(doctype, filters={
|
||||||
select sum({0})
|
'docstatus': 1,
|
||||||
from `tab{1}`
|
party_type.lower(): party
|
||||||
where {2}=%s and docstatus=1 and posting_date between %s and %s
|
}, distinct=1, fields=['company'])
|
||||||
""".format(total_field, doctype, party_type.lower()),
|
|
||||||
(party, current_fiscal_year.year_start_date, current_fiscal_year.year_end_date))
|
|
||||||
|
|
||||||
total_unpaid = frappe.db.sql("""
|
company_wise_info = []
|
||||||
select sum(debit_in_account_currency) - sum(credit_in_account_currency)
|
|
||||||
|
company_wise_grand_total = frappe.get_all(doctype,
|
||||||
|
filters={
|
||||||
|
'docstatus': 1,
|
||||||
|
party_type.lower(): party,
|
||||||
|
'posting_date': ('between', [current_fiscal_year.year_start_date, current_fiscal_year.year_end_date])
|
||||||
|
},
|
||||||
|
group_by="company",
|
||||||
|
fields=["company", "sum(grand_total) as grand_total", "sum(base_grand_total) as base_grand_total"]
|
||||||
|
)
|
||||||
|
|
||||||
|
company_wise_billing_this_year = frappe._dict()
|
||||||
|
|
||||||
|
for d in company_wise_grand_total:
|
||||||
|
company_wise_billing_this_year.setdefault(
|
||||||
|
d.company,{
|
||||||
|
"grand_total": d.grand_total,
|
||||||
|
"base_grand_total": d.base_grand_total
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
company_wise_total_unpaid = frappe._dict(frappe.db.sql("""
|
||||||
|
select company, sum(debit_in_account_currency) - sum(credit_in_account_currency)
|
||||||
from `tabGL Entry`
|
from `tabGL Entry`
|
||||||
where party_type = %s and party=%s""", (party_type, party))
|
where party_type = %s and party=%s
|
||||||
|
group by company""", (party_type, party)))
|
||||||
|
|
||||||
info = {}
|
for d in companies:
|
||||||
info["billing_this_year"] = flt(billing_this_year[0][0]) if billing_this_year else 0
|
company_default_currency = frappe.db.get_value("Company", d.company, 'default_currency')
|
||||||
info["currency"] = party_account_currency
|
party_account_currency = get_party_account_currency(party_type, party, d.company)
|
||||||
info["total_unpaid"] = flt(total_unpaid[0][0]) if total_unpaid else 0
|
|
||||||
if party_type == "Supplier":
|
|
||||||
info["total_unpaid"] = -1 * info["total_unpaid"]
|
|
||||||
|
|
||||||
return info
|
if party_account_currency==company_default_currency:
|
||||||
|
billing_this_year = flt(company_wise_billing_this_year.get(d.company,{}).get("base_grand_total"))
|
||||||
|
else:
|
||||||
|
billing_this_year = flt(company_wise_billing_this_year.get(d.company,{}).get("grand_total"))
|
||||||
|
|
||||||
|
total_unpaid = flt(company_wise_total_unpaid.get(d.company))
|
||||||
|
|
||||||
|
info = {}
|
||||||
|
info["billing_this_year"] = flt(billing_this_year) if billing_this_year else 0
|
||||||
|
info["currency"] = party_account_currency
|
||||||
|
info["total_unpaid"] = flt(total_unpaid) if total_unpaid else 0
|
||||||
|
info["company"] = d.company
|
||||||
|
|
||||||
|
if party_type == "Supplier":
|
||||||
|
info["total_unpaid"] = -1 * info["total_unpaid"]
|
||||||
|
|
||||||
|
company_wise_info.append(info)
|
||||||
|
|
||||||
|
return company_wise_info
|
||||||
|
|
||||||
def get_party_shipping_address(doctype, name):
|
def get_party_shipping_address(doctype, name):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -103,12 +103,32 @@ $.extend(erpnext, {
|
|||||||
$.extend(erpnext.utils, {
|
$.extend(erpnext.utils, {
|
||||||
set_party_dashboard_indicators: function(frm) {
|
set_party_dashboard_indicators: function(frm) {
|
||||||
if(frm.doc.__onload && frm.doc.__onload.dashboard_info) {
|
if(frm.doc.__onload && frm.doc.__onload.dashboard_info) {
|
||||||
var info = frm.doc.__onload.dashboard_info;
|
var company_wise_info = frm.doc.__onload.dashboard_info;
|
||||||
frm.dashboard.add_indicator(__('Annual Billing: {0}',
|
if(company_wise_info.length > 1) {
|
||||||
[format_currency(info.billing_this_year, info.currency)]), 'blue');
|
frm.dashboard.stats_area.removeClass('hidden');
|
||||||
frm.dashboard.add_indicator(__('Total Unpaid: {0}',
|
frm.dashboard.stats_area_row.addClass('flex');
|
||||||
[format_currency(info.total_unpaid, info.currency)]),
|
frm.dashboard.stats_area_row.css('flex-wrap', 'wrap');
|
||||||
info.total_unpaid ? 'orange' : 'green');
|
company_wise_info.forEach(function(info) {
|
||||||
|
frm.dashboard.stats_area_row.append(
|
||||||
|
'<div class="flex-column col-xs-6">'+
|
||||||
|
'<div style="margin-bottom:20px"><h6>'+info.company+'</h6></div>'+
|
||||||
|
'<div class="badge-link small" style="margin-bottom:10px">Annual Billing: '
|
||||||
|
+format_currency(info.billing_this_year, info.currency)+'</div>'+
|
||||||
|
'<div class="badge-link small" style="margin-bottom:20px">Total Unpaid: '
|
||||||
|
+format_currency(info.total_unpaid, info.currency)+'</div>'+
|
||||||
|
'</div>'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
frm.dashboard.stats_area.removeClass('hidden');
|
||||||
|
frm.dashboard.stats_area_row.append(
|
||||||
|
'</div><div class="col-xs-6 small" style="margin-bottom:10px">Annual Billing: <b>'
|
||||||
|
+format_currency(company_wise_info[0].billing_this_year, company_wise_info[0].currency)+'</b></div>' +
|
||||||
|
'<div class="col-xs-6 small" style="margin-bottom:10px">Total Unpaid: <b>'
|
||||||
|
+format_currency(company_wise_info[0].billing_this_year, company_wise_info[0].currency)+'</b></div>'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user