fixes to chart_of_accounts, added opening + pl condition
This commit is contained in:
parent
aeb5c0fe70
commit
588a98a10f
@ -41,7 +41,8 @@ wn.pages['chart-of-accounts'].onload = function(wrapper) {
|
||||
page: "chart_of_accounts",
|
||||
method: "get_companies",
|
||||
callback: function(r) {
|
||||
erpnext.coa.company_select.empty().add_options(r.message).change();
|
||||
erpnext.coa.company_select.empty().add_options(r.message.companies).change();
|
||||
erpnext.coa.fiscal_years = r.message.fiscal_years;
|
||||
}
|
||||
});
|
||||
|
||||
@ -100,6 +101,7 @@ erpnext.coa = {
|
||||
"credit": 0,
|
||||
"closing": 0,
|
||||
"debit_or_credit": v[2],
|
||||
"is_pl": v[3]
|
||||
};
|
||||
|
||||
data.push(d);
|
||||
@ -118,18 +120,27 @@ erpnext.coa = {
|
||||
var gl = erpnext.coa.gl;
|
||||
var opening_date = dateutil.user_to_obj(erpnext.coa.opening_date.val());
|
||||
var closing_date = dateutil.user_to_obj(erpnext.coa.closing_date.val());
|
||||
var fiscal_year = erpnext.coa.get_fiscal_year(opening_date, closing_date);
|
||||
if (!fiscal_year) return;
|
||||
|
||||
$.each(erpnext.coa.data, function(i, v) {
|
||||
v.opening = v.debit = v.credit = v.closing = 0;
|
||||
});
|
||||
|
||||
$.each(gl, function(i, v) {
|
||||
var posting_date = dateutil.str_to_obj(v[0]);
|
||||
var account = erpnext.coa.data_by_name[v[1]];
|
||||
// opening
|
||||
if (posting_date < opening_date) {
|
||||
if (account.debit_or_credit === "Debit") {
|
||||
account.opening += (v[2] - v[3]);
|
||||
if (posting_date < opening_date || v[4] === "Yes") {
|
||||
if (account.is_pl === "Yes" && posting_date <= dateutil.str_to_obj(fiscal_year[1])) {
|
||||
// balance of previous fiscal_year should
|
||||
// not be part of opening of pl account balance
|
||||
} else {
|
||||
account.opening += (v[3] - v[2]);
|
||||
if (account.debit_or_credit === "Debit") {
|
||||
account.opening += (v[2] - v[3]);
|
||||
} else {
|
||||
account.opening += (v[3] - v[2]);
|
||||
}
|
||||
}
|
||||
} else if (opening_date <= posting_date && posting_date <= closing_date) {
|
||||
// in between
|
||||
@ -152,6 +163,26 @@ erpnext.coa = {
|
||||
v.closing = fmt_money(v.closing);
|
||||
});
|
||||
},
|
||||
get_fiscal_year: function(opening_date, closing_date) {
|
||||
if (opening_date > closing_date) {
|
||||
msgprint("Opening Date should be before Closing Date");
|
||||
return;
|
||||
}
|
||||
|
||||
var fiscal_year = null;
|
||||
$.each(erpnext.coa.fiscal_years, function(i, v) {
|
||||
if (opening_date >= dateutil.str_to_obj(v[1]) &&
|
||||
closing_date <= dateutil.str_to_obj(v[2])) {
|
||||
fiscal_year = v;
|
||||
}
|
||||
});
|
||||
|
||||
if (!fiscal_year) {
|
||||
msgprint("Opening Date and Closing Date should be within same Fiscal Year");
|
||||
return;
|
||||
}
|
||||
return fiscal_year;
|
||||
},
|
||||
set_indent: function(data, parent_map) {
|
||||
$.each(data, function(i, d) {
|
||||
var indent = 0;
|
||||
|
@ -4,9 +4,10 @@ import webnotes
|
||||
def get_chart():
|
||||
company = webnotes.form_dict.get('company')
|
||||
res = {}
|
||||
res["chart"] = webnotes.conn.sql("""select name, parent_account, debit_or_credit from
|
||||
res["chart"] = webnotes.conn.sql("""select name, parent_account, debit_or_credit, is_pl_account from
|
||||
tabAccount where company=%s and docstatus < 2 order by lft""", (company, ))
|
||||
res["gl"] = webnotes.conn.sql("""select posting_date, account, ifnull(debit, 0), ifnull(credit, 0)
|
||||
res["gl"] = webnotes.conn.sql("""select posting_date, account, ifnull(debit, 0),
|
||||
ifnull(credit, 0), ifnull(is_opening, 'No')
|
||||
from `tabGL Entry` where company=%s and ifnull(is_cancelled, "No") = "No"
|
||||
order by posting_date""", (company, ))
|
||||
return res
|
||||
@ -23,8 +24,14 @@ def get_companies():
|
||||
if r["role"] in webnotes.user.roles and r["match"]=="company"))
|
||||
|
||||
# if match == company is specified and companies are specified in user defaults
|
||||
res = {}
|
||||
if match and webnotes.user.get_defaults().get("company"):
|
||||
return webnotes.user.get_defaults().get("company")
|
||||
res["companies"] = webnotes.user.get_defaults().get("company")
|
||||
else:
|
||||
return [r[0] for r in webnotes.conn.sql("""select name from tabCompany
|
||||
res["companies"] = [r[0] for r in webnotes.conn.sql("""select name from tabCompany
|
||||
where docstatus!=2""")]
|
||||
res["fiscal_years"] = webnotes.conn.sql("""select name, year_start_date,
|
||||
adddate(year_start_date, interval 1 year)
|
||||
from `tabFiscal Year` where docstatus!=2
|
||||
order by year_start_date asc""")
|
||||
return res
|
||||
|
@ -856,7 +856,7 @@ wn.ui.AppFrame=Class.extend({init:function(parent,title){this.buttons={};this.$w
|
||||
</div>').appendTo(this.$w);this.$w.find('.close').click(function(){window.history.back();})
|
||||
if(title)this.title(title);},title:function(txt){this.$titlebar.find('.appframe-title').html(txt);},add_button:function(label,click,icon){this.add_toolbar();args={label:label,icon:''};if(icon){args.icon='<i class="'+icon+'"></i>';}
|
||||
this.buttons[label]=$(repl('<button class="btn btn-small">\
|
||||
%(icon)s %(label)s</button>',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},clear_buttons:function(){this.toolbar.empty();},add_toolbar:function(){if(!this.toolbar)
|
||||
%(icon)s %(label)s</button>',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},clear_buttons:function(){this.toolbar&&this.toolbar.empty();},add_toolbar:function(){if(!this.toolbar)
|
||||
this.$w.append('<div class="appframe-toolbar"></div>');this.toolbar=this.$w.find('.appframe-toolbar');},add_select:function(label,options){this.add_toolbar();return $("<select style='width: 160px;'>").add_options(options).appendTo(this.add_label(label));},add_label:function(label){return $("<span style='margin-right: 12px;'>"+label+" </span>").appendTo(this.toolbar);},add_date:function(label,date){this.add_toolbar();return $("<input style='width: 80px;'>").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),changeYear:true,}).val(dateutil.str_to_user(date)||"").appendTo(this.add_label(label));},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('<div class="layout-wrapper layout-wrapper-appframe">\
|
||||
<div class="layout-appframe"></div>\
|
||||
<div class="layout-main"></div>\
|
||||
|
@ -515,7 +515,7 @@ wn.ui.AppFrame=Class.extend({init:function(parent,title){this.buttons={};this.$w
|
||||
</div>').appendTo(this.$w);this.$w.find('.close').click(function(){window.history.back();})
|
||||
if(title)this.title(title);},title:function(txt){this.$titlebar.find('.appframe-title').html(txt);},add_button:function(label,click,icon){this.add_toolbar();args={label:label,icon:''};if(icon){args.icon='<i class="'+icon+'"></i>';}
|
||||
this.buttons[label]=$(repl('<button class="btn btn-small">\
|
||||
%(icon)s %(label)s</button>',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},clear_buttons:function(){this.toolbar.empty();},add_toolbar:function(){if(!this.toolbar)
|
||||
%(icon)s %(label)s</button>',args)).click(click).appendTo(this.toolbar);return this.buttons[label];},clear_buttons:function(){this.toolbar&&this.toolbar.empty();},add_toolbar:function(){if(!this.toolbar)
|
||||
this.$w.append('<div class="appframe-toolbar"></div>');this.toolbar=this.$w.find('.appframe-toolbar');},add_select:function(label,options){this.add_toolbar();return $("<select style='width: 160px;'>").add_options(options).appendTo(this.add_label(label));},add_label:function(label){return $("<span style='margin-right: 12px;'>"+label+" </span>").appendTo(this.toolbar);},add_date:function(label,date){this.add_toolbar();return $("<input style='width: 80px;'>").datepicker({dateFormat:sys_defaults.date_format.replace("yyyy","yy"),changeYear:true,}).val(dateutil.str_to_user(date)||"").appendTo(this.add_label(label));},});wn.ui.make_app_page=function(opts){if(opts.single_column){$(opts.parent).html('<div class="layout-wrapper layout-wrapper-appframe">\
|
||||
<div class="layout-appframe"></div>\
|
||||
<div class="layout-main"></div>\
|
||||
|
Loading…
x
Reference in New Issue
Block a user