chart of account fixes, added delete, rename

This commit is contained in:
Rushabh Mehta 2012-12-03 14:11:24 +05:30
parent 833f070991
commit 7dd13a45f6
5 changed files with 672 additions and 780 deletions

View File

@ -23,6 +23,11 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
// Refresh
// -----------------------------------------
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
if(doc.__islocal) {
msgprint("Please create new account from Chart of Accounts.");
throw "cannot create";
}
cur_frm.toggle_display('account_name', doc.__islocal);
// hide fields if group
@ -34,7 +39,7 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
'is_pl_account', 'company'], false);
// read-only for root accounts
root_acc = ['Application of Funds (Assets)','Expenses','Income','Source of Funds (Liabilities)'];
root_acc = doc.parent ? false : true;
if(in_list(root_acc, doc.account_name)) {
cur_frm.perm = [[1,0,0], [1,0,0]];
cur_frm.set_intro("This is a root account and cannot be edited.");
@ -48,7 +53,7 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
cur_frm.cscript.account_type(doc, cdt, cdn);
// show / hide convert buttons
cur_frm.cscript.hide_unhide_group_ledger(doc);
cur_frm.cscript.add_toolbar_buttons(doc);
}
}
@ -76,7 +81,10 @@ cur_frm.cscript.account_type = function(doc, cdt, cdn) {
// Hide/unhide group or ledger
// -----------------------------------------
cur_frm.cscript.hide_unhide_group_ledger = function(doc) {
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')
if (cstr(doc.group_or_ledger) == 'Group') {
cur_frm.add_custom_button('Convert to Ledger',
function() { cur_frm.cscript.convert_to_ledger(); }, 'icon-retweet')

View File

@ -61,10 +61,13 @@ class DocType:
elif par and not self.doc.is_pl_account:
self.doc.is_pl_account = par[0][2]
self.doc.debit_or_credit = par[0][3]
elif self.doc.account_name not in ['Income','Source of Funds (Liabilities)',\
'Expenses','Application of Funds (Assets)']:
msgprint("Parent Account is mandatory", raise_exception=1)
def validate_max_root_accounts(self):
if webnotes.conn.sql("""select count(*) from tabAccount where
company=%s and ifnull(parent_account,'')='' and docstatus != 2""",
self.doc.company)[0][0] > 4:
webnotes.msgprint("One company cannot have more than 4 root Accounts",
raise_exception=1)
# Account name must be unique
def validate_duplicate_account(self):
@ -74,21 +77,10 @@ class DocType:
def validate_root_details(self):
#does not exists parent
if self.doc.account_name in ['Income','Source of Funds', 'Expenses','Application of Funds'] and self.doc.parent_account:
msgprint("You can not assign parent for root account", raise_exception=1)
# Debit / Credit
if self.doc.account_name in ['Income','Source of Funds']:
self.doc.debit_or_credit = 'Credit'
elif self.doc.account_name in ['Expenses','Application of Funds']:
self.doc.debit_or_credit = 'Debit'
# Is PL Account
if self.doc.account_name in ['Income','Expenses']:
self.doc.is_pl_account = 'Yes'
elif self.doc.account_name in ['Source of Funds','Application of Funds']:
self.doc.is_pl_account = 'No'
if webnotes.conn.exists("Account", self.doc.name):
if not self.doc.get_value("Account", self.doc.name, "parent_account"):
webnotes.msgprint("Root cannot be edited.", raise_exception=1)
def convert_group_to_ledger(self):
if self.check_if_child_exists():
msgprint("Account: %s has existing child. You can not convert this account to ledger" % (self.doc.name), raise_exception=1)
@ -144,6 +136,7 @@ class DocType:
def on_update(self):
# update nsm
self.validate_max_root_accounts()
self.update_nsm_model()
# Check user role for approval process

View File

@ -52,6 +52,12 @@ pscript['onload_Accounts Browser'] = function(wrapper){
wrapper.$company_select.val(sys_defaults.company || r[0]).change();
}
});
// refresh on rename
$(document).bind('rename', function(event, dt, old_name, new_name) {
if(erpnext.account_chart.ctype==dt)
wrapper.$company_select.change();
});
}
pscript['onshow_Accounts Browser'] = function(wrapper){
@ -71,6 +77,11 @@ erpnext.AccountsChart = Class.extend({
$(wrapper).find('.tree-area').empty();
var me = this;
me.ctype = ctype;
me.can_create = wn.boot.profile.can_create.indexOf(this.ctype);
me.can_delete = wn.model.can_delete(this.ctype);
me.can_write = wn.boot.profile.can_write.indexOf(this.ctype);
me.company = company;
this.tree = new wn.ui.Tree({
parent: $(wrapper).find('.tree-area'),
@ -116,17 +127,24 @@ erpnext.AccountsChart = Class.extend({
var node_links = [];
// edit
if (wn.boot.profile.can_read.indexOf(this.ctype) !== -1) {
node_links.push('<a href="#!Form/'+encodeURIComponent(this.ctype)+'/'
node_links.push('<a href="#Form/'+encodeURIComponent(this.ctype)+'/'
+encodeURIComponent(data.value)+'">Edit</a>');
}
if (data.expandable) {
if((wn.boot.profile.can_create.indexOf(this.ctype) !== -1) ||
(wn.boot.profile.in_create.indexOf(this.ctype) !== -1)) {
if(this.can_create) {
node_links.push('<a onclick="erpnext.account_chart.new_node();">Add Child</a>');
}
} else if (this.ctype === 'Account' && wn.boot.profile.can_read.indexOf("GL Entry") !== -1) {
node_links.push('<a onclick="erpnext.account_chart.show_ledger();">View Ledger</a>');
}
if (this.can_write !== -1) {
node_links.push('<a onclick="erpnext.account_chart.rename()">Rename</a>');
};
if (this.can_delete !== -1) {
node_links.push('<a onclick="erpnext.account_chart.delete()">Delete</a>');
};
link.toolbar.append(node_links.join(" | "));
},
@ -135,6 +153,18 @@ erpnext.AccountsChart = Class.extend({
var node = me.selected_node();
wn.set_route("general-ledger", "account=" + node.data('label'));
},
rename: function() {
var me = this;
var node = me.selected_node();
wn.model.rename_doc("Account", node.data('label'));
},
delete: function() {
var me = this;
var node = me.selected_node();
wn.model.delete_doc("Account", node.data('label'), function() {
node.parent().remove();
});
},
new_node: function() {
if(this.ctype=='Account') {
this.new_account();
@ -216,6 +246,8 @@ erpnext.AccountsChart = Class.extend({
$(fd.group_or_ledger.input).change();
$(fd.account_type.input).change();
}
$(fd.group_or_ledger.input).val("Ledger").change();
d.show();
},

View File

@ -2,19 +2,20 @@
{
"owner": "Administrator",
"docstatus": 0,
"creation": "2012-11-24 17:21:44",
"creation": "2012-12-03 10:31:06",
"modified_by": "Administrator",
"modified": "2012-11-30 10:54:00"
"modified": "2012-12-03 13:57:32"
},
{
"is_submittable": 1,
"autoname": "naming_series:",
"name": "__common__",
"description": "Potential Sales Deal",
"default_print_format": "Standard",
"search_fields": "status,transaction_date,customer,lead,enquiry_type,territory,company",
"module": "Selling",
"doctype": "DocType",
"document_type": "Transaction"
"document_type": "Transaction",
"name": "__common__"
},
{
"name": "__common__",
@ -35,16 +36,6 @@
"name": "Opportunity",
"doctype": "DocType"
},
{
"description": "Enter customer enquiry for which you might raise a quotation in future",
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Basic Info",
"fieldname": "basic_info",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"description": "To manage multiple series please go to Setup > Manage Series",
"no_copy": 1,
@ -474,14 +465,24 @@
"fieldtype": "Date",
"permlevel": 1
},
{
"amend": 0,
"create": 0,
"doctype": "DocPerm",
"submit": 0,
"write": 0,
"cancel": 0,
"role": "Sales Manager",
"permlevel": 1
},
{
"amend": 1,
"create": 1,
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"role": "System Manager",
"cancel": 1,
"role": "System Manager",
"permlevel": 0
},
{
@ -495,8 +496,8 @@
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"role": "Sales User",
"cancel": 1,
"role": "Sales User",
"permlevel": 0
},
{
@ -505,8 +506,8 @@
"doctype": "DocPerm",
"submit": 0,
"write": 0,
"role": "Sales User",
"cancel": 0,
"role": "Sales User",
"permlevel": 1
},
{
@ -515,18 +516,8 @@
"doctype": "DocPerm",
"submit": 1,
"write": 1,
"role": "Sales Manager",
"cancel": 1,
"permlevel": 0
},
{
"amend": 0,
"create": 0,
"doctype": "DocPerm",
"submit": 0,
"write": 0,
"role": "Sales Manager",
"cancel": 0,
"permlevel": 1
"permlevel": 0
}
]

File diff suppressed because it is too large Load Diff