mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-05 21:29:11 +00:00
[forms] cleanup, fixing usability and added form dashboard
This commit is contained in:
@@ -32,6 +32,7 @@ cur_frm.add_fetch('lead_name', 'company_name', 'customer_name');
|
||||
cur_frm.add_fetch('default_sales_partner','commission_rate','default_commission_rate');
|
||||
|
||||
cur_frm.cscript.refresh = function(doc,dt,dn) {
|
||||
cur_frm.layout.clear_dashboard();
|
||||
if(sys_defaults.cust_master_name == 'Customer Name')
|
||||
hide_field('naming_series');
|
||||
else
|
||||
@@ -39,7 +40,8 @@ cur_frm.cscript.refresh = function(doc,dt,dn) {
|
||||
|
||||
if(doc.__islocal){
|
||||
hide_field(['address_html','contact_html']);
|
||||
}else{
|
||||
}else{
|
||||
cur_frm.cscript.setup_dashboard(doc);
|
||||
unhide_field(['address_html','contact_html']);
|
||||
// make lists
|
||||
cur_frm.cscript.make_address(doc,dt,dn);
|
||||
@@ -53,6 +55,35 @@ cur_frm.cscript.refresh = function(doc,dt,dn) {
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.setup_dashboard = function(doc) {
|
||||
cur_frm.layout.dashboard.toggle(true);
|
||||
var headline = $('<div class="form-headline col col-lg-12">\
|
||||
<span class="text-muted">Loading...</span></div>')
|
||||
.appendTo(cur_frm.layout.dashboard);
|
||||
|
||||
cur_frm.layout.add_doctype_badge(wn._("Opportunities"), "Opportunity", "customer");
|
||||
cur_frm.layout.add_doctype_badge(wn._("Quotations"), "Quotation", "customer");
|
||||
cur_frm.layout.add_doctype_badge(wn._("Sales Orders"), "Sales Order", "customer");
|
||||
cur_frm.layout.add_doctype_badge(wn._("Delivery Notes"), "Delivery Note", "customer");
|
||||
cur_frm.layout.add_doctype_badge(wn._("Sales Invoices"), "Sales Invoice", "customer");
|
||||
|
||||
wn.call({
|
||||
type: "GET",
|
||||
method:"selling.doctype.customer.customer.get_dashboard_info",
|
||||
args: {
|
||||
customer: cur_frm.doc.name
|
||||
},
|
||||
callback: function(r) {
|
||||
cur_frm.layout.dashboard.find(".form-headline")
|
||||
.html(wn._("Total Billing This Year: ") + "<b>"
|
||||
+ format_currency(r.message.total_billing, cur_frm.doc.default_currency)
|
||||
+ '</b> / <span class="text-muted">' + wn._("Unpaid") + ": <b>" +
|
||||
format_currency(r.message.total_unpaid, cur_frm.doc.default_currency) + '</b></span>');
|
||||
cur_frm.layout.set_badge_count(r.message);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
cur_frm.cscript.make_address = function() {
|
||||
if(!cur_frm.address_list) {
|
||||
cur_frm.address_list = new wn.ui.Listing({
|
||||
@@ -95,4 +126,4 @@ cur_frm.fields_dict['customer_group'].get_query = function(doc,dt,dn) {
|
||||
}
|
||||
|
||||
|
||||
cur_frm.fields_dict.lead_name.get_query = erpnext.utils.lead_query;
|
||||
cur_frm.fields_dict.lead_name.get_query = erpnext.utils.lead_query;
|
||||
@@ -173,4 +173,25 @@ class DocType(TransactionBase):
|
||||
|
||||
#update master_name in doctype account
|
||||
webnotes.conn.sql("""update `tabAccount` set master_name = %s,
|
||||
master_type = 'Customer' where master_name = %s""", (new,old))
|
||||
master_type = 'Customer' where master_name = %s""", (new,old))
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_dashboard_info(customer):
|
||||
if not webnotes.has_permission("Customer", customer):
|
||||
webnotes.msgprint("No Permission", raise_exception=True)
|
||||
|
||||
out = {}
|
||||
for doctype in ["Opportunity", "Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]:
|
||||
out[doctype] = webnotes.conn.get_value(doctype,
|
||||
{"customer": customer, "docstatus": ["!=", 2] }, "count(*)")
|
||||
|
||||
billing = webnotes.conn.sql("""select sum(grand_total), sum(outstanding_amount)
|
||||
from `tabSales Invoice`
|
||||
where customer=%s
|
||||
and docstatus = 1
|
||||
and fiscal_year = %s""", (customer, webnotes.conn.get_default("fiscal_year")))
|
||||
|
||||
out["total_billing"] = billing[0][0]
|
||||
out["total_unpaid"] = billing[0][1]
|
||||
|
||||
return out
|
||||
Reference in New Issue
Block a user