[enhance] show customer, supplier billing and outstanding, fixes #6078
This commit is contained in:
parent
5a58d8a11e
commit
559aa3ab7c
@ -30,6 +30,7 @@ frappe.ui.form.on("Supplier", {
|
||||
unhide_field(['address_html','contact_html']);
|
||||
erpnext.utils.render_address_and_contact(frm);
|
||||
|
||||
// custom buttons
|
||||
frm.add_custom_button(__('Accounting Ledger'), function() {
|
||||
frappe.set_route('query-report', 'General Ledger',
|
||||
{party_type:'Supplier', party:frm.doc.name});
|
||||
@ -37,6 +38,9 @@ frappe.ui.form.on("Supplier", {
|
||||
frm.add_custom_button(__('Accounts Payable'), function() {
|
||||
frappe.set_route('query-report', 'Accounts Payable', {supplier:frm.doc.name});
|
||||
});
|
||||
|
||||
// indicators
|
||||
erpnext.utils.set_party_dashboard_indicators(frm);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
@ -18,6 +18,26 @@ class Supplier(TransactionBase):
|
||||
def onload(self):
|
||||
"""Load address and contacts in `__onload`"""
|
||||
load_address_and_contact(self, "supplier")
|
||||
self.load_dashboard_info()
|
||||
|
||||
def load_dashboard_info(self):
|
||||
billing_this_year = frappe.db.sql("""
|
||||
select sum(credit_in_account_currency) - sum(debit_in_account_currency)
|
||||
from `tabGL Entry`
|
||||
where voucher_type='Purchase Invoice' and party_type = 'Supplier'
|
||||
and party=%s and fiscal_year = %s""",
|
||||
(self.name, frappe.db.get_default("fiscal_year")))
|
||||
|
||||
total_unpaid = frappe.db.sql("""select sum(outstanding_amount)
|
||||
from `tabPurchase Invoice`
|
||||
where supplier=%s and docstatus = 1""", self.name)
|
||||
|
||||
|
||||
info = {}
|
||||
info["billing_this_year"] = billing_this_year[0][0] if billing_this_year else 0
|
||||
info["total_unpaid"] = total_unpaid[0][0] if total_unpaid else 0
|
||||
|
||||
self.set_onload('dashboard_info', info)
|
||||
|
||||
def autoname(self):
|
||||
supp_master_name = frappe.defaults.get_global_default('supp_master_name')
|
||||
|
@ -108,6 +108,17 @@ $.extend(erpnext.utils, {
|
||||
}
|
||||
},
|
||||
|
||||
set_party_dashboard_indicators: function(frm) {
|
||||
if(frm.doc.__onload && frm.doc.__onload.dashboard_info) {
|
||||
var info = frm.doc.__onload.dashboard_info;
|
||||
frm.dashboard.add_indicator(__('Annual Billing: {0}',
|
||||
[format_currency(info.billing_this_year, frm.doc.default_currency)]), 'blue');
|
||||
frm.dashboard.add_indicator(__('Total Unpaid: {0}',
|
||||
[format_currency(info.total_unpaid, frm.doc.default_currency)]),
|
||||
info.total_unpaid ? 'orange' : 'green');
|
||||
}
|
||||
},
|
||||
|
||||
copy_value_in_all_row: function(doc, dt, dn, table_fieldname, fieldname) {
|
||||
var d = locals[dt][dn];
|
||||
if(d[fieldname]){
|
||||
|
@ -37,13 +37,19 @@ frappe.ui.form.on("Customer", {
|
||||
if(!frm.doc.__islocal) {
|
||||
erpnext.utils.render_address_and_contact(frm);
|
||||
|
||||
// custom buttons
|
||||
frm.add_custom_button(__('Accounting Ledger'), function() {
|
||||
frappe.set_route('query-report', 'General Ledger',
|
||||
{party_type:'Customer', party:frm.doc.name});
|
||||
});
|
||||
|
||||
frm.add_custom_button(__('Accounts Receivable'), function() {
|
||||
frappe.set_route('query-report', 'Accounts Receivable', {customer:frm.doc.name});
|
||||
});
|
||||
|
||||
// indicator
|
||||
erpnext.utils.set_party_dashboard_indicators(frm);
|
||||
|
||||
} else {
|
||||
erpnext.utils.clear_address_and_contact(frm);
|
||||
}
|
||||
|
@ -20,6 +20,26 @@ class Customer(TransactionBase):
|
||||
def onload(self):
|
||||
"""Load address and contacts in `__onload`"""
|
||||
load_address_and_contact(self, "customer")
|
||||
self.load_dashboard_info()
|
||||
|
||||
def load_dashboard_info(self):
|
||||
billing_this_year = frappe.db.sql("""
|
||||
select sum(debit_in_account_currency) - sum(credit_in_account_currency)
|
||||
from `tabGL Entry`
|
||||
where voucher_type='Sales Invoice' and party_type = 'Customer'
|
||||
and party=%s and fiscal_year = %s""",
|
||||
(self.name, frappe.db.get_default("fiscal_year")))
|
||||
|
||||
total_unpaid = frappe.db.sql("""select sum(outstanding_amount)
|
||||
from `tabSales Invoice`
|
||||
where customer=%s and docstatus = 1""", self.name)
|
||||
|
||||
info = {}
|
||||
info["billing_this_year"] = billing_this_year[0][0] if billing_this_year else 0
|
||||
info["total_unpaid"] = total_unpaid[0][0] if total_unpaid else 0
|
||||
|
||||
self.set_onload('dashboard_info', info)
|
||||
|
||||
|
||||
def autoname(self):
|
||||
cust_master_name = frappe.defaults.get_global_default('cust_master_name')
|
||||
|
Loading…
Reference in New Issue
Block a user