Auto fetch default bank account for jv of type Bank Voucher
diff --git a/erpnext/accounts/__init__.py b/erpnext/accounts/__init__.py
index e69de29..0f98d2b 100644
--- a/erpnext/accounts/__init__.py
+++ b/erpnext/accounts/__init__.py
@@ -0,0 +1,13 @@
+import webnotes
+
+def get_default_bank_account():
+ """
+ Get default bank account for a company
+ """
+ company = webnotes.form_dict.get('company')
+ if not company: return
+ res = webnotes.conn.sql("""\
+ SELECT default_bank_account FROM `tabCompany`
+ WHERE name=%s AND docstatus<2""", company)
+
+ if res: return res[0][0]
diff --git a/erpnext/accounts/doctype/journal_voucher/journal_voucher.js b/erpnext/accounts/doctype/journal_voucher/journal_voucher.js
index f65ee31..99fb10a 100644
--- a/erpnext/accounts/doctype/journal_voucher/journal_voucher.js
+++ b/erpnext/accounts/doctype/journal_voucher/journal_voucher.js
@@ -152,3 +152,19 @@
}
loadreport('GL Entry','General Ledger', callback);
}
+
+
+cur_frm.cscript.voucher_type = function(doc, cdt, cdn) {
+ if(doc.voucher_type == 'Bank Voucher' && cstr(doc.company)) {
+ var children = getchildren('Journal Voucher Detail', doc.name, 'entries');
+ if(!children || children.length==0) {
+ $c('accounts.get_default_bank_account', {company: doc.company }, function(r, rt) {
+ if(!r.exc) {
+ var jvd = LocalDB.add_child(doc, 'Journal Voucher Detail', 'entries');
+ jvd.account = cstr(r.message);
+ refresh_field('entries');
+ }
+ });
+ }
+ }
+}
diff --git a/erpnext/accounts/doctype/payable_voucher/payable_voucher.js b/erpnext/accounts/doctype/payable_voucher/payable_voucher.js
index ce26865..b3cbd63 100644
--- a/erpnext/accounts/doctype/payable_voucher/payable_voucher.js
+++ b/erpnext/accounts/doctype/payable_voucher/payable_voucher.js
@@ -200,8 +200,12 @@
// Make Journal Voucher
// --------------------
-cur_frm.cscript['Make Bank Voucher'] = function(doc, dt, dn) {
- cur_frm.cscript.make_jv(cur_frm.doc);
+cur_frm.cscript['Make Bank Voucher'] = function() {
+ $c('accounts.get_default_bank_account', { company: cur_frm.doc.company }, function(r, rt) {
+ if(!r.exc) {
+ cur_frm.cscript.make_jv(cur_frm.doc, null, null, r.message);
+ }
+ });
}
@@ -324,7 +328,7 @@
// Make JV
// --------
-cur_frm.cscript.make_jv = function(doc, dt, dn, det) {
+cur_frm.cscript.make_jv = function(doc, dt, dn, bank_account) {
var jv = LocalDB.create('Journal Voucher');
jv = locals['Journal Voucher'][jv];
jv.voucher_type = 'Bank Voucher';
@@ -342,6 +346,7 @@
// credit to bank
var d1 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries');
+ d1.account = bank_account;
d1.credit = doc.outstanding_amount;
loaddoc('Journal Voucher', jv.name);
diff --git a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js
index ed47257..e56b16c 100644
--- a/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js
+++ b/erpnext/accounts/doctype/receivable_voucher/receivable_voucher.js
@@ -277,7 +277,11 @@
// Make Bank Voucher Button
// -------------------------
cur_frm.cscript['Make Bank Voucher'] = function(doc, dt, dn) {
- cur_frm.cscript.make_jv(cur_frm.doc);
+ $c('accounts.get_default_bank_account', { company: cur_frm.doc.company }, function(r, rt) {
+ if(!r.exc) {
+ cur_frm.cscript.make_jv(cur_frm.doc, null, null, r.message);
+ }
+ });
}
@@ -402,7 +406,7 @@
// Make Journal Voucher
// --------------------
-cur_frm.cscript.make_jv = function(doc, dt, dn) {
+cur_frm.cscript.make_jv = function(doc, dt, dn, bank_account) {
var jv = LocalDB.create('Journal Voucher');
jv = locals['Journal Voucher'][jv];
jv.voucher_type = 'Bank Voucher';
@@ -420,6 +424,7 @@
// credit to bank
var d1 = LocalDB.add_child(jv, 'Journal Voucher Detail', 'entries');
+ d1.account = bank_account;
d1.debit = doc.outstanding_amount;
loaddoc('Journal Voucher', jv.name);