[minor] added chart of accounts, cost centers buttons on Company

This commit is contained in:
Rushabh Mehta 2016-03-02 13:08:40 +05:30
parent fe6eadfe22
commit b0f0aaf5b1
3 changed files with 117 additions and 66 deletions

View File

@ -50,36 +50,31 @@ frappe.pages["Accounts Browser"].on_page_load = function(wrapper){
erpnext.account_chart && erpnext.account_chart.make_new();
}, "octicon octicon-plus");
var company_list = $.map(locals[':Company'], function(c) { return c.name; }).sort();
// company-select
wrapper.$company_select = wrapper.page.add_select("Company", [])
wrapper.$company_select = wrapper.page.add_select("Company", company_list)
.change(function() {
var ctype = frappe.get_route()[1] || 'Account';
erpnext.account_chart = new erpnext.AccountsChart(ctype, $(this).val(),
chart_area.get(0), wrapper.page);
})
// load up companies
return frappe.call({
method: 'erpnext.accounts.page.accounts_browser.accounts_browser.get_companies',
callback: function(r) {
wrapper.$company_select.empty();
$.each(r.message, function(i, v) {
$('<option>').html(v).attr('value', v).appendTo(wrapper.$company_select);
});
wrapper.$company_select.val(frappe.defaults.get_user_default("Company") || r.message[0]).change();
}
});
}
frappe.pages["Accounts Browser"].on_page_show = function(wrapper){
// set route
var ctype = frappe.get_route()[1] || 'Account';
if(erpnext.account_chart && erpnext.account_chart.ctype != ctype) {
if(frappe.route_options) {
if(frappe.route_options.company) {
wrapper.$company_select.val(frappe.route_options.company).change();
}
frappe.route_options = null;
} else if(erpnext.account_chart && erpnext.account_chart.ctype != ctype) {
wrapper.$company_select.change();
}
}
erpnext.AccountsChart = Class.extend({

View File

@ -6,8 +6,30 @@ frappe.provide("erpnext.company");
frappe.ui.form.on("Company", {
onload: function(frm) {
erpnext.company.setup_queries(frm);
},
},
refresh: function(frm) {
if(frm.doc.abbr && !frm.doc.__islocal) {
frm.set_df_property("abbr", "read_only", 1);
}
if(!frm.doc.__islocal) {
frm.toggle_enable("default_currency", (frm.doc.__onload &&
!frm.doc.__onload.transactions_exist));
frm.add_custom_button(__('Cost Centers'), function() {
frappe.set_route('Accounts Browser', 'Cost Center', {'company': frm.doc.name})
})
frm.add_custom_button(__('Chart of Accounts'), function() {
frappe.set_route('Accounts Browser', 'Account', {'company': frm.doc.name})
})
}
erpnext.company.set_chart_of_accounts_options(frm.doc);
},
onload_post_render: function(frm) {
frm.get_field("delete_company_transactions").$input.addClass("btn-danger");
},
@ -50,19 +72,6 @@ frappe.ui.form.on("Company", {
});
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
if(doc.abbr && !doc.__islocal) {
cur_frm.set_df_property("abbr", "read_only", 1);
}
if(!doc.__islocal) {
cur_frm.toggle_enable("default_currency", (cur_frm.doc.__onload &&
!cur_frm.doc.__onload.transactions_exist));
}
erpnext.company.set_chart_of_accounts_options(doc);
}
erpnext.company.set_chart_of_accounts_options = function(doc) {
var selected_value = doc.chart_of_accounts;
if(doc.country) {
@ -120,22 +129,22 @@ cur_frm.cscript.change_abbr = function() {
erpnext.company.setup_queries = function(frm) {
$.each([
["default_bank_account", {"account_type": "Bank"}],
["default_cash_account", {"account_type": "Cash"}],
["default_receivable_account", {"account_type": "Receivable"}],
["default_payable_account", {"account_type": "Payable"}],
["default_expense_account", {"root_type": "Expense"}],
["default_income_account", {"root_type": "Income"}],
["default_bank_account", {"account_type": "Bank"}],
["default_cash_account", {"account_type": "Cash"}],
["default_receivable_account", {"account_type": "Receivable"}],
["default_payable_account", {"account_type": "Payable"}],
["default_expense_account", {"root_type": "Expense"}],
["default_income_account", {"root_type": "Income"}],
["round_off_account", {"root_type": "Expense"}],
["cost_center", {}],
["round_off_cost_center", {}]
], function(i, v) {
erpnext.company.set_custom_query(frm, v);
});
if (sys_defaults.auto_accounting_for_stock) {
$.each([
["stock_adjustment_account", {"root_type": "Expense"}],
["stock_adjustment_account", {"root_type": "Expense"}],
["expenses_included_in_valuation", {"root_type": "Expense"}],
["stock_received_but_not_billed", {"report_type": "Balance Sheet"}]
], function(i, v) {
@ -149,7 +158,7 @@ erpnext.company.set_custom_query = function(frm, v) {
"company": frm.doc.name,
"is_group": 0
};
for (var key in v[1])
for (var key in v[1])
filters[key] = v[1][key];
frm.set_query(v[0], function() {
@ -157,4 +166,4 @@ erpnext.company.set_custom_query = function(frm, v) {
filters: filters
};
});
}
}

View File

@ -18,6 +18,7 @@
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "",
@ -42,6 +43,7 @@
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Company",
@ -68,6 +70,7 @@
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Abbr",
@ -94,6 +97,7 @@
"fieldtype": "Button",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Change Abbreviation",
@ -117,6 +121,7 @@
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
@ -131,6 +136,31 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "country",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Country",
"length": 0,
"no_copy": 0,
"options": "Country",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
@ -139,6 +169,7 @@
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Domain",
@ -163,6 +194,7 @@
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Default Values",
@ -186,6 +218,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Default Letter Head",
@ -211,6 +244,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Default Holiday List",
@ -228,30 +262,6 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "country",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Country",
"length": 0,
"no_copy": 0,
"options": "Country",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
@ -260,6 +270,7 @@
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
@ -283,6 +294,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Default Currency",
@ -307,6 +319,7 @@
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Chart of Accounts",
@ -331,6 +344,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Default Terms",
@ -356,6 +370,7 @@
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Accounts Settings",
@ -381,6 +396,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Default Bank Account",
@ -408,6 +424,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Default Cash Account",
@ -433,6 +450,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Default Receivable Account",
@ -459,6 +477,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Round Off Account",
@ -484,6 +503,7 @@
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
@ -509,6 +529,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Default Payable Account",
@ -536,6 +557,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Default Cost of Goods Sold Account",
@ -561,6 +583,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Default Income Account",
@ -585,6 +608,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Round Off Cost Center",
@ -610,6 +634,7 @@
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
@ -634,6 +659,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Cost Center",
@ -658,6 +684,7 @@
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Credit Days Based On",
@ -684,6 +711,7 @@
"fieldtype": "Int",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Credit Days",
@ -710,6 +738,7 @@
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Credit Limit",
@ -736,6 +765,7 @@
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
@ -760,6 +790,7 @@
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "If Yearly Budget Exceeded (for expense account)",
@ -787,6 +818,7 @@
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "If Monthly Budget Exceeded (for expense account)",
@ -814,6 +846,7 @@
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Stock Settings",
@ -837,6 +870,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Stock Received But Not Billed",
@ -861,6 +895,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Stock Adjustment Account",
@ -885,6 +920,7 @@
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
@ -908,6 +944,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Expenses Included In Valuation",
@ -933,6 +970,7 @@
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Company Info",
@ -956,6 +994,7 @@
"fieldtype": "Small Text",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Address",
@ -981,6 +1020,7 @@
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
@ -1005,6 +1045,7 @@
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Phone No",
@ -1031,6 +1072,7 @@
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Fax",
@ -1057,6 +1099,7 @@
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Email",
@ -1083,6 +1126,7 @@
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Website",
@ -1109,6 +1153,7 @@
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "",
@ -1135,6 +1180,7 @@
"fieldtype": "Code",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Registration Details",
@ -1160,6 +1206,7 @@
"fieldtype": "Button",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Delete Company Transactions",
@ -1188,7 +1235,7 @@
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
"modified": "2015-12-24 15:09:29.866621",
"modified": "2016-03-02 02:24:21.343229",
"modified_by": "Administrator",
"module": "Setup",
"name": "Company",
@ -1337,5 +1384,5 @@
],
"read_only": 0,
"read_only_onload": 0,
"version": 0
"sort_order": "ASC"
}