[fix] [setup_wizard] fiscal year fix for setup wizard

This commit is contained in:
Akhilesh Darjee
2013-11-25 19:51:18 +05:30
parent 8991ad719c
commit ec0da0b177
16 changed files with 140 additions and 95 deletions

View File

@@ -1,18 +1,39 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
cur_frm.cscript.refresh = function(doc, dt, dn) {
cur_frm.toggle_enable('year_start_date', doc.__islocal)
$.extend(cur_frm.cscript, {
refresh: function (doc, dt, dn) {
var me = this;
this.frm.toggle_enable('year_start_date', doc.__islocal)
this.frm.toggle_enable('year_end_date', doc.__islocal)
if (!doc.__islocal && (doc.name != sys_defaults.fiscal_year)) {
cur_frm.add_custom_button(wn._("Set as Default"), cur_frm.cscript.set_as_default);
cur_frm.set_intro(wn._("To set this Fiscal Year as Deafult, click on 'Set as Default'"));
} else cur_frm.set_intro("");
}
if (!doc.__islocal && (doc.name != sys_defaults.fiscal_year)) {
this.frm.add_custom_button(wn._("Set as Default"), this.frm.cscript.set_as_default);
this.frm.set_intro(wn._("To set this Fiscal Year as Default, click on 'Set as Default'"));
} else this.frm.set_intro("");
cur_frm.cscript.set_as_default = function() {
return wn.call({
doc: cur_frm.doc,
method: "set_as_default"
});
}
if (doc.__islocal && this.frm.doc.year_start_date)
this.frm.script_manager.trigger("year_start_date", dt, dn);
},
set_as_default: function() {
return wn.call({
doc: cur_frm.doc,
method: "set_as_default"
});
},
year_start_date: function(doc, dt, dn) {
var me = this;
wn.call({
method: 'controllers.trends.get_period_date_ranges',
args: {
period: "Yearly",
year_start_date: this.frm.doc.year_start_date
},
callback: function(r) {
if (!r.exc)
me.frm.set_value("year_end_date", r.message[0][1])
}
});
},
});

View File

@@ -17,4 +17,24 @@ class DocType:
webnotes.clear_cache()
msgprint(self.doc.name + _(""" is now the default Fiscal Year. \
Please refresh your browser for the change to take effect."""))
Please refresh your browser for the change to take effect."""))
def on_update(self):
from webnotes.utils import getdate
# validate year start date and year end date
if getdate(self.doc.year_start_date) > getdate(self.doc.year_end_date):
webnotes.throw(_("Year Start Date should not be greater than Year End Date"))
if (getdate(self.doc.year_end_date) - getdate(self.doc.year_start_date)).days > 366:
webnotes.throw([getdate(self.doc.year_end_date), getdate(self.doc.year_start_date)])
webnotes.throw((getdate(self.doc.year_end_date) - getdate(self.doc.year_start_date)).days)
webnotes.throw(_("Year Start Date and Year End Date are not within Fiscal Year."))
year_start_end_dates = webnotes.conn.sql("""select name, year_start_date, year_end_date
from `tabFiscal Year` where name!=%s""", (self.doc.name))
for fiscal_year, ysd, yed in year_start_end_dates:
if getdate(self.doc.year_start_date) == ysd and getdate(self.doc.year_end_date) == yed:
webnotes.throw(_("Year Start Date and Year End Date are already \
set in Fiscal Year: ") + fiscal_year)

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-01-22 16:50:25",
"docstatus": 0,
"modified": "2013-07-23 11:59:11",
"modified": "2013-11-25 11:40:02",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -56,6 +56,14 @@
"oldfieldtype": "Date",
"reqd": 1
},
{
"doctype": "DocField",
"fieldname": "year_end_date",
"fieldtype": "Date",
"label": "Year End Date",
"no_copy": 1,
"reqd": 1
},
{
"default": "No",
"description": "Entries are not allowed against this Fiscal Year if the year is closed.",

View File

@@ -7,26 +7,31 @@ test_records = [
[{
"doctype": "Fiscal Year",
"year": "_Test Fiscal Year 2012",
"year_start_date": "2012-01-01"
"year_start_date": "2012-01-01",
"year_end_date": "2012-12-31"
}],
[{
"doctype": "Fiscal Year",
"year": "_Test Fiscal Year 2013",
"year_start_date": "2013-01-01"
"year_start_date": "2013-01-01",
"year_end_date": "2013-12-31"
}],
[{
"doctype": "Fiscal Year",
"year": "_Test Fiscal Year 2014",
"year_start_date": "2014-01-01"
"year_start_date": "2014-01-01",
"year_end_date": "2014-12-31"
}],
[{
"doctype": "Fiscal Year",
"year": "_Test Fiscal Year 2015",
"year_start_date": "2015-01-01"
"year_start_date": "2015-01-01",
"year_end_date": "2015-12-31"
}],
[{
"doctype": "Fiscal Year",
"year": "_Test Fiscal Year 2016",
"year_start_date": "2016-01-01"
"year_start_date": "2016-01-01",
"year_end_date": "2016-12-31"
}],
]

View File

@@ -254,7 +254,6 @@ class DocType:
for i in range(4):
pn = 'Q'+str(i+1)
self.period_list.append(pn)
self.period_start_date[pn] = get_first_day(ysd,0,i*3)
self.period_end_date[pn] = get_last_day(get_first_day(ysd,0,((i+1)*3)-1))

View File

@@ -24,14 +24,10 @@ def get_fiscal_years(date=None, fiscal_year=None, label="Date", verbose=1):
if fiscal_year:
cond = "name = '%s'" % fiscal_year
else:
cond = "'%s' >= year_start_date and '%s' < adddate(year_start_date, interval 1 year)" % \
cond = "'%s' >= year_start_date and '%s' <= year_end_date" % \
(date, date)
fy = webnotes.conn.sql("""select name, year_start_date,
subdate(adddate(year_start_date, interval 1 year), interval 1 day)
as year_end_date
from `tabFiscal Year`
where %s
order by year_start_date desc""" % cond)
fy = webnotes.conn.sql("""select name, year_start_date, year_end_date
from `tabFiscal Year` where %s order by year_start_date desc""" % cond)
if not fy:
error_msg = """%s %s not in any Fiscal Year""" % (label, formatdate(date))