diff --git a/accounts/doctype/account/account.js b/accounts/doctype/account/account.js index db50ff6ac87..252b708fc0c 100644 --- a/accounts/doctype/account/account.js +++ b/accounts/doctype/account/account.js @@ -82,7 +82,7 @@ cur_frm.cscript.account_type = function(doc, cdt, cdn) { // ----------------------------------------- cur_frm.cscript.add_toolbar_buttons = function(doc) { cur_frm.add_custom_button('Chart of Accounts', - function() { wn.set_route("Accounts Browser", "Account"); }, 'icon-list') + function() { wn.set_route("Accounts Browser", "Account"); }, 'icon-sitemap') if (cstr(doc.group_or_ledger) == 'Group') { cur_frm.add_custom_button('Convert to Ledger', diff --git a/accounts/doctype/cost_center/cost_center.js b/accounts/doctype/cost_center/cost_center.js index e63fa042ea4..2a98a960c77 100644 --- a/accounts/doctype/cost_center/cost_center.js +++ b/accounts/doctype/cost_center/cost_center.js @@ -28,6 +28,9 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { cur_frm.toggle_display('sb1', doc.group_or_ledger=='Ledger') cur_frm.set_intro(intro_txt); + + cur_frm.add_custom_button('Chart of Cost Centers', + function() { wn.set_route("Accounts Browser", "Cost Center"); }, 'icon-sitemap') } //Account filtering for cost center diff --git a/accounts/doctype/journal_voucher/journal_voucher.js b/accounts/doctype/journal_voucher/journal_voucher.js index 78956bf11ea..7e2f22a738b 100644 --- a/accounts/doctype/journal_voucher/journal_voucher.js +++ b/accounts/doctype/journal_voucher/journal_voucher.js @@ -139,10 +139,21 @@ cur_frm.cscript.view_ledger_entry = function(doc,cdt,cdn){ cur_frm.cscript.voucher_type = function(doc, cdt, cdn) { 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(wn.model.get("Journal Voucher Detail", {"parent":doc.name}).length!===0 // too late + || !doc.company) // too early + return; - if(in_list(["Bank Voucher", "Cash Voucher"], doc.voucher_type) - && doc.company - && wn.model.get("Journal Voucher Detail", {"parent":doc.name}).length==0) { + var update_jv_details = function(doc, r) { + $.each(r.message, function(i, d) { + var jvdetail = wn.model.add_child(doc, "Journal Voucher Detail", "entries"); + jvdetail.account = d.account; + jvdetail.balance = d.balance; + }); + refresh_field("entries"); + } + + if(in_list(["Bank Voucher", "Cash Voucher"], doc.voucher_type)) { wn.call({ type: "GET", method: "accounts.doctype.journal_voucher.journal_voucher.get_default_bank_cash_account", @@ -152,14 +163,26 @@ cur_frm.cscript.voucher_type = function(doc, cdt, cdn) { }, callback: function(r) { if(r.message) { - var jvdetail = wn.model.add_child(doc, "Journal Voucher Detail", "entries"); - jvdetail.account = r.message.account; - // this is a data field???? - jvdetail.balance = format_currency(r.message.balance); - refresh_field("entries"); + update_jv_details(doc, r); } } }) + } else if(doc.voucher_type=="Opening Entry") { + wn.call({ + type:"GET", + method: "accounts.doctype.journal_voucher.journal_voucher.get_opening_accounts", + args: { + "company": doc.company + }, + callback: function(r) { + wn.model.clear_table("Journal Voucher Detail", "Journal Voucher", + doc.name, "entries"); + if(r.message) { + update_jv_details(doc, r); + } + cur_frm.set_value("is_opening", "Yes") + } + }) } } diff --git a/accounts/doctype/journal_voucher/journal_voucher.py b/accounts/doctype/journal_voucher/journal_voucher.py index 2c5cd4fd804..77fec8ee8bd 100644 --- a/accounts/doctype/journal_voucher/journal_voucher.py +++ b/accounts/doctype/journal_voucher/journal_voucher.py @@ -352,11 +352,20 @@ def get_default_bank_cash_account(company, voucher_type): account = webnotes.conn.get_value("Company", company, voucher_type=="Bank Voucher" and "default_bank_account" or "default_cash_account") if account: - return { + return [{ "account": account, "balance": get_balance_on(account) - } + }] +@webnotes.whitelist() +def get_opening_accounts(company): + """get all balance sheet accounts for opening entry""" + from accounts.utils import get_balance_on + accounts = webnotes.conn.sql_list("""select name from tabAccount + where group_or_ledger='Ledger' and is_pl_account='No' and company=%s""", company) + + return [{"account": a, "balance": get_balance_on(a)} for a in accounts] + 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 from `tabPurchase Invoice` where credit_to = %s and docstatus = 1 diff --git a/accounts/doctype/journal_voucher/journal_voucher.txt b/accounts/doctype/journal_voucher/journal_voucher.txt index d0163e69b95..603eb99fc04 100644 --- a/accounts/doctype/journal_voucher/journal_voucher.txt +++ b/accounts/doctype/journal_voucher/journal_voucher.txt @@ -2,7 +2,7 @@ { "creation": "2013-03-25 10:53:52", "docstatus": 0, - "modified": "2013-06-11 16:04:20", + "modified": "2013-06-28 14:27:11", "modified_by": "Administrator", "owner": "Administrator" }, @@ -68,7 +68,7 @@ "label": "Voucher Type", "oldfieldname": "voucher_type", "oldfieldtype": "Select", - "options": "\nJournal Entry\nBank Voucher\nCash Voucher\nCredit Card Voucher\nDebit Note\nCredit Note\nContra Voucher\nExcise Voucher\nWrite Off Voucher", + "options": "\nJournal Entry\nBank Voucher\nCash Voucher\nCredit Card Voucher\nDebit Note\nCredit Note\nContra Voucher\nExcise Voucher\nWrite Off Voucher\nOpening Entry", "print_hide": 0, "read_only": 0, "search_index": 1 diff --git a/accounts/page/voucher_import_tool/voucher_import_tool.js b/accounts/page/voucher_import_tool/voucher_import_tool.js index bf6b065b0f4..48216b83ee6 100644 --- a/accounts/page/voucher_import_tool/voucher_import_tool.js +++ b/accounts/page/voucher_import_tool/voucher_import_tool.js @@ -9,11 +9,11 @@ wn.pages['voucher-import-tool'].onload = function(wrapper) {
Import multiple accounting entries via CSV (spreadsheet) file:
\Import multiple vouchers with one debit and one credit entry
\Import multiple vouchers with multiple accounts
\