[accounts] [feature] added default_cash_account in company and gets set in Journal Voucher
diff --git a/accounts/__init__.py b/accounts/__init__.py
index 145ad6b..e69de29 100644
--- a/accounts/__init__.py
+++ b/accounts/__init__.py
@@ -1,34 +0,0 @@
-# ERPNext - web based ERP (http://erpnext.com)
-# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-from __future__ import unicode_literals
-import webnotes
-from webnotes.utils import flt
-from webnotes.model.code import get_obj
-from accounts.utils import get_balance_on
-
-@webnotes.whitelist()
-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/accounts/doctype/journal_voucher/journal_voucher.js b/accounts/doctype/journal_voucher/journal_voucher.js
index 80c46ca..811bc50 100644
--- a/accounts/doctype/journal_voucher/journal_voucher.js
+++ b/accounts/doctype/journal_voucher/journal_voucher.js
@@ -137,23 +137,27 @@
cur_frm.cscript.voucher_type = function(doc, cdt, cdn) {
- if(doc.voucher_type == 'Bank Voucher' && cstr(doc.company)) {
- cur_frm.set_df_property("cheque_no", "reqd", true);
- cur_frm.set_df_property("cheque_date", "reqd", true);
-
- 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 = wn.model.add_child(doc, 'Journal Voucher Detail', 'entries');
- jvd.account = cstr(r.message);
- refresh_field('entries');
+ cur_frm.set_df_property("cheque_no", "reqd", doc.voucher_type=="Bank Voucher");
+ cur_frm.set_df_property("cheque_date", "reqd", doc.voucher_type=="Bank Voucher");
+
+ if(in_list(["Bank Voucher", "Cash Voucher"], doc.voucher_type)
+ && doc.company
+ && wn.model.get("Journal Voucher Detail", {"parent":doc.name}).length==0) {
+ wn.call({
+ type: "GET",
+ method: "accounts.doctype.journal_voucher.journal_voucher.get_default_bank_cash_account",
+ args: {
+ "voucher_type": doc.voucher_type,
+ "company": doc.company
+ },
+ callback: function(r) {
+ if(r.message) {
+ var jvdetail = wn.model.add_child(doc, "Journal Voucher Detail", "entries");
+ jvdetail.account = r.message || "";
+ refresh_field("entries");
}
- });
- }
- } else {
- cur_frm.set_df_property("cheque_no", "reqd", false);
- cur_frm.set_df_property("cheque_date", "reqd", false);
+ }
+ })
}
}
diff --git a/accounts/doctype/journal_voucher/journal_voucher.py b/accounts/doctype/journal_voucher/journal_voucher.py
index c58e9ba..4078701 100644
--- a/accounts/doctype/journal_voucher/journal_voucher.py
+++ b/accounts/doctype/journal_voucher/journal_voucher.py
@@ -349,6 +349,10 @@
from `tabPurchase Invoice` where docstatus = 1 and company = %s
and outstanding_amount > 0 %s""" % ('%s', cond), self.doc.company)
+@webnotes.whitelist()
+def get_default_bank_cash_account(company, voucher_type):
+ return webnotes.conn.get_value("Company", company,
+ voucher_type=="Bank Voucher" and "default_bank_account" or "default_cash_account")
def get_against_purchase_invoice(doctype, txt, searchfield, start, page_len, filters):
return webnotes.conn.sql("""select name, credit_to, outstanding_amount, bill_no, bill_date
diff --git a/setup/doctype/company/company.js b/setup/doctype/company/company.js
index a898823..97fc5c7 100644
--- a/setup/doctype/company/company.js
+++ b/setup/doctype/company/company.js
@@ -49,6 +49,10 @@
return 'SELECT `tabAccount`.name, `tabAccount`.debit_or_credit, `tabAccount`.group_or_ledger FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Ledger" AND `tabAccount`.docstatus != 2 AND `tabAccount`.account_type = "Bank or Cash" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50';
}
+cur_frm.fields_dict.default_cash_account.get_query = function(doc) {
+ return 'SELECT `tabAccount`.name, `tabAccount`.debit_or_credit, `tabAccount`.group_or_ledger FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Ledger" AND `tabAccount`.docstatus != 2 AND `tabAccount`.account_type = "Bank or Cash" AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50';
+}
+
cur_frm.fields_dict.receivables_group.get_query = function(doc) {
return 'SELECT `tabAccount`.name FROM `tabAccount` WHERE `tabAccount`.company = "'+doc.name+'" AND `tabAccount`.group_or_ledger = "Group" AND `tabAccount`.docstatus != 2 AND `tabAccount`.%(key)s LIKE "%s" ORDER BY `tabAccount`.name LIMIT 50';
diff --git a/setup/doctype/company/company.txt b/setup/doctype/company/company.txt
index 4d2dcda..1dfbe2f 100644
--- a/setup/doctype/company/company.txt
+++ b/setup/doctype/company/company.txt
@@ -1,8 +1,8 @@
[
{
- "creation": "2013-02-27 09:38:05",
+ "creation": "2013-03-21 17:41:00",
"docstatus": 0,
- "modified": "2013-03-19 12:52:00",
+ "modified": "2013-03-25 15:35:34",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -25,19 +25,14 @@
},
{
"amend": 0,
- "cancel": 1,
- "create": 1,
"doctype": "DocPerm",
"name": "__common__",
"parent": "Company",
"parentfield": "permissions",
"parenttype": "DocType",
- "permlevel": 0,
"read": 1,
"report": 1,
- "role": "System Manager",
- "submit": 0,
- "write": 1
+ "submit": 0
},
{
"doctype": "DocType",
@@ -103,6 +98,13 @@
"options": "Account"
},
{
+ "doctype": "DocField",
+ "fieldname": "default_cash_account",
+ "fieldtype": "Link",
+ "label": "Default Cash Account",
+ "options": "Account"
+ },
+ {
"depends_on": "eval:!doc.__islocal",
"doctype": "DocField",
"fieldname": "receivables_group",
@@ -307,6 +309,19 @@
"read_only": 1
},
{
- "doctype": "DocPerm"
+ "cancel": 1,
+ "create": 1,
+ "doctype": "DocPerm",
+ "permlevel": 0,
+ "role": "System Manager",
+ "write": 1
+ },
+ {
+ "cancel": 0,
+ "create": 0,
+ "doctype": "DocPerm",
+ "permlevel": 1,
+ "role": "All",
+ "write": 0
}
]
\ No newline at end of file