From 3d1ecf5254c5887a48c04003c7dce8a218136ddd Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 14 Aug 2013 17:22:14 +0530 Subject: [PATCH] [fix] [minor] take correct docname when creating contact/address from a previous document --- controllers/js/contact_address_common.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/controllers/js/contact_address_common.js b/controllers/js/contact_address_common.js index 82dad0e83e8..7589947d242 100644 --- a/controllers/js/contact_address_common.js +++ b/controllers/js/contact_address_common.js @@ -16,11 +16,14 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { if(doc.__islocal) { var last_route = wn.route_history.slice(-2, -1)[0]; if(last_route && last_route[0]==="Form") { + var doctype = last_route[1], + docname = last_route.slice(2).join("/"); + if(["Customer", "Quotation", "Sales Order", "Sales Invoice", "Delivery Note", "Installation Note", "Opportunity", "Customer Issue", "Maintenance Visit", "Maintenance Schedule"] - .indexOf(last_route[1])!==-1) { - var refdoc = wn.model.get_doc(last_route[1], last_route[2]); + .indexOf(doctype)!==-1) { + var refdoc = wn.model.get_doc(doctype, docname); if(refdoc.doctype == "Quotation" ? refdoc.quotation_to=="Customer" : true) { cur_frm.set_value("customer", refdoc.customer || refdoc.name); @@ -30,16 +33,16 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { } } if(["Supplier", "Supplier Quotation", "Purchase Order", "Purchase Invoice", "Purchase Receipt"] - .indexOf(last_route[1])!==-1) { - var refdoc = wn.model.get_doc(last_route[1], last_route[2]); + .indexOf(doctype)!==-1) { + var refdoc = wn.model.get_doc(doctype, docname); cur_frm.set_value("supplier", refdoc.supplier || refdoc.name); cur_frm.set_value("supplier_name", refdoc.supplier_name); if(cur_frm.doc.doctype==="Address") cur_frm.set_value("address_title", cur_frm.doc.supplier_name); } if(["Lead", "Quotation"] - .indexOf(last_route[1])!==-1) { - var refdoc = wn.model.get_doc(last_route[1], last_route[2]); + .indexOf(doctype)!==-1) { + var refdoc = wn.model.get_doc(doctype, docname); if(refdoc.doctype == "Quotation" ? refdoc.quotation_to=="Lead" : true) { cur_frm.set_value("lead", refdoc.lead || refdoc.name);