blob: 89b1d43ac55a91855874b5ce8440f861673d2be7 [file] [log] [blame]
Rushabh Mehta37982a62013-06-14 13:29:20 +05301cur_frm.cscript.onload = function(doc, cdt, cdn) {
2 cur_frm.add_fetch('customer', 'customer_name', 'customer_name');
3 cur_frm.add_fetch('supplier', 'supplier_name', 'supplier_name');
4
5 cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;
6 cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query;
7
8 if(doc.__islocal) {
9 var last_route = wn.route_history.slice(-2, -1)[0];
10 if(last_route && last_route[0]==="Form") {
11 if(["Customer", "Quotation", "Sales Order", "Sales Invoice", "Delivery Note",
12 "Installation Note", "Opportunity", "Customer Issue", "Maintenance Visit",
13 "Maintenance Schedule"]
14 .indexOf(last_route[1])!==-1) {
15 var refdoc = wn.model.get_doc(last_route[1], last_route[2]);
16 cur_frm.set_value("customer", refdoc.customer || refdoc.name);
17 cur_frm.set_value("customer_name", refdoc.customer_name);
Rushabh Mehta65d12922013-06-26 22:31:22 +053018 if(cur_frm.doc.doctype==="Address")
19 cur_frm.set_value("address_title", cur_frm.doc.customer)
Rushabh Mehta37982a62013-06-14 13:29:20 +053020 }
21 if(["Supplier", "Supplier Quotation", "Purchase Order", "Purchase Invoice", "Purchase Receipt"]
22 .indexOf(last_route[1])!==-1) {
Rushabh Mehta65d12922013-06-26 22:31:22 +053023 var refdoc = wn.model.get_doc(last_route[1], last_route[2]);
Rushabh Mehta37982a62013-06-14 13:29:20 +053024 cur_frm.set_value("supplier", refdoc.supplier || refdoc.name);
25 cur_frm.set_value("supplier_name", refdoc.supplier_name);
Rushabh Mehta65d12922013-06-26 22:31:22 +053026 if(cur_frm.doc.doctype==="Address")
27 cur_frm.set_value("address_title", cur_frm.doc.supplier)
Rushabh Mehta37982a62013-06-14 13:29:20 +053028 }
29 }
30 }
31}