mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-12 17:51:20 +00:00
Merge pull request #1097 from akhileshdarjee/master
[fix] fiscal year fix in setup wizard
This commit is contained in:
@@ -1,18 +1,36 @@
|
||||
// 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("");
|
||||
},
|
||||
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;
|
||||
|
||||
cur_frm.cscript.set_as_default = function() {
|
||||
return wn.call({
|
||||
doc: cur_frm.doc,
|
||||
method: "set_as_default"
|
||||
});
|
||||
}
|
||||
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])
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -17,4 +17,22 @@ 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(_("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)
|
||||
@@ -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.",
|
||||
|
||||
@@ -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"
|
||||
}],
|
||||
]
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class DocType(AccountsController):
|
||||
|
||||
def validate_posting_date(self):
|
||||
from accounts.utils import get_fiscal_year
|
||||
self.year_start_date = get_fiscal_year(self.doc.posting_date)[1]
|
||||
self.year_start_date = get_fiscal_year(self.doc.posting_date, self.doc.fiscal_year)[1]
|
||||
|
||||
pce = webnotes.conn.sql("""select name from `tabPeriod Closing Voucher`
|
||||
where posting_date > %s and fiscal_year = %s and docstatus = 1""",
|
||||
|
||||
@@ -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))
|
||||
@@ -372,4 +368,4 @@ def get_account_for(account_for_doctype, account_for):
|
||||
account_for_field = "account_type"
|
||||
|
||||
return webnotes.conn.get_value("Account", {account_for_field: account_for_doctype,
|
||||
"master_name": account_for})
|
||||
"master_name": account_for})
|
||||
|
||||
Reference in New Issue
Block a user