From 157c3347376c15ad36b65ac53a89a6e5089088e1 Mon Sep 17 00:00:00 2001 From: Makarand Bauskar Date: Fri, 26 May 2017 21:32:33 +0530 Subject: [PATCH] [minor] added get_terms methods to erpnext.utils so that it can be used in non transactional documents (#9037) --- .../hr/doctype/offer_letter/offer_letter.js | 6 ++++-- erpnext/public/js/controllers/transaction.js | 20 ++++++------------- erpnext/public/js/utils.js | 15 ++++++++++++++ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/erpnext/hr/doctype/offer_letter/offer_letter.js b/erpnext/hr/doctype/offer_letter/offer_letter.js index 643eaa88e7..125a425b6c 100755 --- a/erpnext/hr/doctype/offer_letter/offer_letter.js +++ b/erpnext/hr/doctype/offer_letter/offer_letter.js @@ -5,8 +5,10 @@ frappe.provide("erpnext.offer_letter"); frappe.ui.form.on("Offer Letter", { select_terms: function(frm) { - frappe.model.get_value("Terms and Conditions", frm.doc.select_terms, "terms", function(value) { - frm.set_value("terms", value.terms); + erpnext.utils.get_terms(frm.doc.select_terms, frm.doc, function(r) { + if(!r.exc) { + me.frm.set_value("terms", r.message); + } }); }, diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 2d0d83b125..6357a52102 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -993,20 +993,12 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ get_terms: function() { var me = this; - if(this.frm.doc.tc_name) { - return frappe.call({ - method: 'erpnext.setup.doctype.terms_and_conditions.terms_and_conditions.get_terms_and_conditions', - args: { - template_name: this.frm.doc.tc_name, - doc: this.frm.doc - }, - callback: function(r) { - if(!r.exc) { - me.frm.set_value("terms", r.message); - } - } - }); - } + + erpnext.utils.get_terms(this.frm.doc.tc_name, this.frm.doc, function(r) { + if(!r.exc) { + me.frm.set_value("terms", r.message); + } + }); }, taxes_and_charges: function() { diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index 3a2254e24c..d618fbe5dd 100644 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -104,6 +104,21 @@ $.extend(erpnext.utils, { } } refresh_field(table_fieldname); + }, + + get_terms: function(tc_name, doc, callback) { + if(tc_name) { + return frappe.call({ + method: 'erpnext.setup.doctype.terms_and_conditions.terms_and_conditions.get_terms_and_conditions', + args: { + template_name: tc_name, + doc: doc + }, + callback: function(r) { + callback(r) + } + }); + } } });