diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index e2e8340a83..4578f308b3 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -1,5 +1,6 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt +{% include "erpnext/public/js/controllers/accounts.js" %} frappe.ui.form.on('Payment Entry', { onload: function(frm) { @@ -257,22 +258,6 @@ frappe.ui.form.on('Payment Entry', { } }, - mode_of_payment: function(frm) { - return frappe.call({ - method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account", - args: { - "mode_of_payment": frm.doc.mode_of_payment, - "company": frm.doc.company - }, - callback: function(r, rt) { - if(r.message) { - var payment_account_field = frm.doc.payment_type == "Receive" ? "paid_to" : "paid_from"; - frm.set_value(payment_account_field, r.message['account']); - } - } - }); - }, - paid_from: function(frm) { if(frm.set_party_account_based_on_party) return; diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.js b/erpnext/accounts/doctype/pos_profile/pos_profile.js index 99438a6a5f..c1aa0c3cb5 100755 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.js +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.js @@ -1,6 +1,8 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt +{% include "erpnext/public/js/controllers/accounts.js" %} + frappe.ui.form.on("POS Profile", "onload", function(frm) { frm.set_query("selling_price_list", function() { return { filters: { selling: 1 } }; diff --git a/erpnext/public/js/controllers/accounts.js b/erpnext/public/js/controllers/accounts.js index 202000fbe2..37ce5de6cf 100644 --- a/erpnext/public/js/controllers/accounts.js +++ b/erpnext/public/js/controllers/accounts.js @@ -55,6 +55,48 @@ frappe.ui.form.on(cur_frm.doctype, { } }); +frappe.ui.form.on('Sales Invoice Payment', { + mode_of_payment: function(frm, cdt, cdn) { + var d = locals[cdt][cdn]; + get_payment_mode_account(frm, d.mode_of_payment, function(account){ + frappe.model.set_value(cdt, cdn, 'account', account) + }) + } +}) + +frappe.ui.form.on('Purchase Invoice', { + mode_of_payment: function(frm) { + get_payment_mode_account(frm, frm.doc.mode_of_payment, function(account){ + frm.set_value('cash_bank_account', account); + }) + } +}) + +frappe.ui.form.on('Payment Entry', { + mode_of_payment: function(frm) { + get_payment_mode_account(frm, frm.doc.mode_of_payment, function(account){ + var payment_account_field = frm.doc.payment_type == "Receive" ? "paid_to" : "paid_from"; + frm.set_value(payment_account_field, account); + }) + } +}) + +get_payment_mode_account = function(frm, mode_of_payment, callback){ + return frappe.call({ + method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account", + args: { + "mode_of_payment": mode_of_payment, + "company": frm.doc.company + }, + callback: function(r, rt) { + if(r.message) { + callback(r.message.account) + } + } + }); +} + + cur_frm.cscript.account_head = function(doc, cdt, cdn) { var d = locals[cdt][cdn]; if(!d.charge_type && d.account_head){