Merge branch 'edge' of github.com:webnotes/erpnext into edge
This commit is contained in:
commit
042233d836
@ -25,6 +25,8 @@ from webnotes import msgprint
|
|||||||
sql = webnotes.conn.sql
|
sql = webnotes.conn.sql
|
||||||
get_value = webnotes.conn.get_value
|
get_value = webnotes.conn.get_value
|
||||||
|
|
||||||
|
test_records = []
|
||||||
|
|
||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self,d,dl):
|
def __init__(self,d,dl):
|
||||||
self.doc, self.doclist = d,dl
|
self.doc, self.doclist = d,dl
|
||||||
|
@ -31,3 +31,6 @@ class DocType:
|
|||||||
|
|
||||||
msgprint(self.doc.name + _(""" is now the default Fiscal Year. \
|
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."""))
|
||||||
|
|
||||||
|
test_records = [[{"doctype":"Fiscal Year", "year":"_Test Fiscal Year",
|
||||||
|
"year_start_date":"2013-01-01"}]]
|
@ -25,6 +25,9 @@ from webnotes.utils import formatdate
|
|||||||
class FiscalYearError(webnotes.ValidationError): pass
|
class FiscalYearError(webnotes.ValidationError): pass
|
||||||
|
|
||||||
def get_fiscal_year(date, verbose=1):
|
def get_fiscal_year(date, verbose=1):
|
||||||
|
return get_fiscal_years(date, verbose=1)[0]
|
||||||
|
|
||||||
|
def get_fiscal_years(date, verbose=1):
|
||||||
# if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate)
|
# if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate)
|
||||||
fy = webnotes.conn.sql("""select name, year_start_date,
|
fy = webnotes.conn.sql("""select name, year_start_date,
|
||||||
subdate(adddate(year_start_date, interval 1 year), interval 1 day)
|
subdate(adddate(year_start_date, interval 1 year), interval 1 day)
|
||||||
@ -38,10 +41,11 @@ def get_fiscal_year(date, verbose=1):
|
|||||||
if verbose: webnotes.msgprint(error_msg)
|
if verbose: webnotes.msgprint(error_msg)
|
||||||
raise FiscalYearError, error_msg
|
raise FiscalYearError, error_msg
|
||||||
|
|
||||||
return fy[0]
|
return fy
|
||||||
|
|
||||||
def validate_fiscal_year(date, fiscal_year, label="Date"):
|
def validate_fiscal_year(date, fiscal_year, label="Date"):
|
||||||
if get_fiscal_year(date)[0] != fiscal_year:
|
years = [f[0] for f in get_fiscal_years(date)]
|
||||||
|
if fiscal_year not in years:
|
||||||
webnotes.msgprint(("%(label)s '%(posting_date)s': " + _("not within Fiscal Year") + \
|
webnotes.msgprint(("%(label)s '%(posting_date)s': " + _("not within Fiscal Year") + \
|
||||||
": '%(fiscal_year)s'") % {
|
": '%(fiscal_year)s'") % {
|
||||||
"label": label,
|
"label": label,
|
||||||
|
@ -20,3 +20,5 @@ import webnotes
|
|||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
self.doc, self.doclist = d, dl
|
self.doc, self.doclist = d, dl
|
||||||
|
|
||||||
|
test_records = [[{"doctype":"Branch", "branch":"_Test Branch"}]]
|
@ -20,3 +20,9 @@ import webnotes
|
|||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
self.doc, self.doclist = d, dl
|
self.doc, self.doclist = d, dl
|
||||||
|
|
||||||
|
test_records = [
|
||||||
|
[{"doctype":"Department", "department_name":"_Test Department"}],
|
||||||
|
[{"doctype":"Department", "department_name":"_Test Department with Block List",
|
||||||
|
"holiday_block_list": "_Test Holiday Block List"}],
|
||||||
|
]
|
||||||
|
@ -20,3 +20,5 @@ import webnotes
|
|||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
self.doc, self.doclist = d, dl
|
self.doc, self.doclist = d, dl
|
||||||
|
|
||||||
|
test_records = [[{"doctype":"Designation", "designation_name":"_Test Designation"}]]
|
@ -123,3 +123,15 @@ class DocType:
|
|||||||
if self.doc.status == 'Left' and not self.doc.relieving_date:
|
if self.doc.status == 'Left' and not self.doc.relieving_date:
|
||||||
msgprint("Please enter relieving date.")
|
msgprint("Please enter relieving date.")
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
|
test_records = [[{
|
||||||
|
"doctype":"Employee",
|
||||||
|
"employee_name": "_Test Employee",
|
||||||
|
"naming_series": "_T-Employee-",
|
||||||
|
"date_of_joining": "2010-01-01",
|
||||||
|
"date_of_birth": "1980-01-01",
|
||||||
|
"gender": "Female",
|
||||||
|
"status": "Active",
|
||||||
|
"company": "_Test Company",
|
||||||
|
"user_id": "test@erpnext.com"
|
||||||
|
}]]
|
@ -20,3 +20,6 @@ import webnotes
|
|||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
self.doc, self.doclist = d, dl
|
self.doc, self.doclist = d, dl
|
||||||
|
|
||||||
|
test_records = [[{"doctype":"Employment Type",
|
||||||
|
"employee_type_name": "_Test Employment Type"}]]
|
@ -20,3 +20,5 @@ import webnotes
|
|||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
self.doc, self.doclist = d, dl
|
self.doc, self.doclist = d, dl
|
||||||
|
|
||||||
|
test_records = [[{"doctype":"Grade", "grade_name":"Test Grade"}]]
|
@ -19,3 +19,16 @@ class DocType:
|
|||||||
if d.block_date in dates:
|
if d.block_date in dates:
|
||||||
webnotes.msgprint(_("Date is repeated") + ":" + d.block_date, raise_exception=1)
|
webnotes.msgprint(_("Date is repeated") + ":" + d.block_date, raise_exception=1)
|
||||||
dates.append(d.block_date)
|
dates.append(d.block_date)
|
||||||
|
|
||||||
|
test_records = [[{
|
||||||
|
"doctype":"Holiday Block List",
|
||||||
|
"holiday_block_list_name": "_Test Holiday Block List",
|
||||||
|
"year": "_Test Fiscal Year"
|
||||||
|
}, {
|
||||||
|
"doctype": "Holiday Block List Date",
|
||||||
|
"parent": "_Test Holiday Block List",
|
||||||
|
"parenttype": "Holiday Block List",
|
||||||
|
"parentfield": "holiday_block_list_dates",
|
||||||
|
"block_date": "2013-01-02",
|
||||||
|
"reason": "First work day"
|
||||||
|
}]]
|
@ -90,3 +90,15 @@ class DocType:
|
|||||||
webnotes.conn.sql("""update `tabHoliday List` set is_default = 0
|
webnotes.conn.sql("""update `tabHoliday List` set is_default = 0
|
||||||
where ifnull(is_default, 0) = 1 and fiscal_year = %s""", (self.doc.fiscal_year,))
|
where ifnull(is_default, 0) = 1 and fiscal_year = %s""", (self.doc.fiscal_year,))
|
||||||
|
|
||||||
|
test_records = [[{
|
||||||
|
"doctype": "Holiday List",
|
||||||
|
"holiday_list_name": "_Test Holiday List",
|
||||||
|
"fiscal_year": "_Test Fiscal Year"
|
||||||
|
}, {
|
||||||
|
"doctype": "Holiday",
|
||||||
|
"parent": "_Test Holiday List",
|
||||||
|
"parenttype": "Holiday List",
|
||||||
|
"parentfield": "holiday_list_details",
|
||||||
|
"holiday_date": "2013-01-01",
|
||||||
|
"description": "New Year"
|
||||||
|
}]]
|
||||||
|
@ -23,7 +23,6 @@ from webnotes.model import db_exists
|
|||||||
from webnotes.model.wrapper import copy_doclist
|
from webnotes.model.wrapper import copy_doclist
|
||||||
from webnotes import form, msgprint
|
from webnotes import form, msgprint
|
||||||
|
|
||||||
sql = webnotes.conn.sql
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
class LeaveDayBlockedError(Exception): pass
|
class LeaveDayBlockedError(Exception): pass
|
||||||
@ -39,7 +38,7 @@ class DocType:
|
|||||||
self.validate_balance_leaves()
|
self.validate_balance_leaves()
|
||||||
self.validate_leave_overlap()
|
self.validate_leave_overlap()
|
||||||
self.validate_max_days()
|
self.validate_max_days()
|
||||||
#self.validate_block_days()
|
self.validate_block_days()
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
if self.doc.status != "Approved":
|
if self.doc.status != "Approved":
|
||||||
@ -55,7 +54,7 @@ class DocType:
|
|||||||
block_list = webnotes.conn.get_value("Department", department, "holiday_block_list")
|
block_list = webnotes.conn.get_value("Department", department, "holiday_block_list")
|
||||||
if block_list:
|
if block_list:
|
||||||
for d in webnotes.conn.sql("""select block_date, reason from
|
for d in webnotes.conn.sql("""select block_date, reason from
|
||||||
`tabHoliday Block List Date` where parent=%s""", block_list):
|
`tabHoliday Block List Date` where parent=%s""", block_list, as_dict=1):
|
||||||
block_date = getdate(d.block_date)
|
block_date = getdate(d.block_date)
|
||||||
if block_date > from_date and block_date < to_date:
|
if block_date > from_date and block_date < to_date:
|
||||||
webnotes.msgprint(_("You cannot apply for a leave on the following date because it is blocked")
|
webnotes.msgprint(_("You cannot apply for a leave on the following date because it is blocked")
|
||||||
@ -63,11 +62,11 @@ class DocType:
|
|||||||
raise LeaveDayBlockedError
|
raise LeaveDayBlockedError
|
||||||
|
|
||||||
def get_holidays(self):
|
def get_holidays(self):
|
||||||
tot_hol = sql("""select count(*) from `tabHoliday` h1, `tabHoliday List` h2, `tabEmployee` e1
|
tot_hol = webnotes.conn.sql("""select count(*) from `tabHoliday` h1, `tabHoliday List` h2, `tabEmployee` e1
|
||||||
where e1.name = %s and h1.parent = h2.name and e1.holiday_list = h2.name
|
where e1.name = %s and h1.parent = h2.name and e1.holiday_list = h2.name
|
||||||
and h1.holiday_date between %s and %s""", (self.doc.employee, self.doc.from_date, self.doc.to_date))
|
and h1.holiday_date between %s and %s""", (self.doc.employee, self.doc.from_date, self.doc.to_date))
|
||||||
if not tot_hol:
|
if not tot_hol:
|
||||||
tot_hol = sql("""select count(*) from `tabHoliday` h1, `tabHoliday List` h2
|
tot_hol = webnotes.conn.sql("""select count(*) from `tabHoliday` h1, `tabHoliday List` h2
|
||||||
where h1.parent = h2.name and h1.holiday_date between %s and %s
|
where h1.parent = h2.name and h1.holiday_date between %s and %s
|
||||||
and ifnull(h2.is_default,0) = 1 and h2.fiscal_year = %s""",
|
and ifnull(h2.is_default,0) = 1 and h2.fiscal_year = %s""",
|
||||||
(self.doc.from_date, self.doc.to_date, self.doc.fiscal_year))
|
(self.doc.from_date, self.doc.to_date, self.doc.fiscal_year))
|
||||||
@ -101,7 +100,7 @@ class DocType:
|
|||||||
(self.doc.leave_type,), raise_exception=1)
|
(self.doc.leave_type,), raise_exception=1)
|
||||||
|
|
||||||
def validate_leave_overlap(self):
|
def validate_leave_overlap(self):
|
||||||
for d in sql("""select name, leave_type, posting_date, from_date, to_date
|
for d in webnotes.conn.sql("""select name, leave_type, posting_date, from_date, to_date
|
||||||
from `tabLeave Application`
|
from `tabLeave Application`
|
||||||
where
|
where
|
||||||
(from_date <= %(to_date)s and to_date >= %(from_date)s)
|
(from_date <= %(to_date)s and to_date >= %(from_date)s)
|
||||||
@ -112,7 +111,7 @@ class DocType:
|
|||||||
msgprint("Employee : %s has already applied for %s between %s and %s on %s. Please refer Leave Application : %s" % (self.doc.employee, cstr(d['leave_type']), formatdate(d['from_date']), formatdate(d['to_date']), formatdate(d['posting_date']), d['name']), raise_exception = 1)
|
msgprint("Employee : %s has already applied for %s between %s and %s on %s. Please refer Leave Application : %s" % (self.doc.employee, cstr(d['leave_type']), formatdate(d['from_date']), formatdate(d['to_date']), formatdate(d['posting_date']), d['name']), raise_exception = 1)
|
||||||
|
|
||||||
def validate_max_days(self):
|
def validate_max_days(self):
|
||||||
max_days = sql("select max_days_allowed from `tabLeave Type` where name = '%s'" %(self.doc.leave_type))
|
max_days = webnotes.conn.sql("select max_days_allowed from `tabLeave Type` where name = '%s'" %(self.doc.leave_type))
|
||||||
max_days = max_days and flt(max_days[0][0]) or 0
|
max_days = max_days and flt(max_days[0][0]) or 0
|
||||||
if max_days and self.doc.total_leave_days > max_days:
|
if max_days and self.doc.total_leave_days > max_days:
|
||||||
msgprint("Sorry ! You cannot apply for %s for more than %s days" % (self.doc.leave_type, max_days))
|
msgprint("Sorry ! You cannot apply for %s for more than %s days" % (self.doc.leave_type, max_days))
|
||||||
@ -147,5 +146,24 @@ def get_approver_list():
|
|||||||
return roles
|
return roles
|
||||||
|
|
||||||
def is_lwp(leave_type):
|
def is_lwp(leave_type):
|
||||||
lwp = sql("select is_lwp from `tabLeave Type` where name = %s", leave_type)
|
lwp = webnotes.conn.sql("select is_lwp from `tabLeave Type` where name = %s", leave_type)
|
||||||
return lwp and cint(lwp[0][0]) or 0
|
return lwp and cint(lwp[0][0]) or 0
|
||||||
|
|
||||||
|
test_records = [
|
||||||
|
[{
|
||||||
|
"doctype": "Leave Allocation",
|
||||||
|
"leave_type": "_Test Leave Type",
|
||||||
|
"fiscal_year": "_Test Fiscal Year",
|
||||||
|
"employee":"_T-Employee-0001",
|
||||||
|
"new_leaves_allocated": 15,
|
||||||
|
"docstatus": 1
|
||||||
|
}],
|
||||||
|
[{
|
||||||
|
"doctype": "Leave Application",
|
||||||
|
"leave_type": "_Test Leave Type",
|
||||||
|
"from_date": "2013-05-01",
|
||||||
|
"to_date": "2013-05-05",
|
||||||
|
"posting_date": "2013-01-02",
|
||||||
|
"fiscal_year": "_Test Fiscal Year",
|
||||||
|
"employee": "_T-Employee-0001"
|
||||||
|
}]]
|
26
hr/doctype/leave_application/test_leave_application.py
Normal file
26
hr/doctype/leave_application/test_leave_application.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from hr.doctype.leave_application.leave_application import test_records, LeaveDayBlockedError
|
||||||
|
|
||||||
|
class TestLeaveApplication(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
from webnotes.test_runner import make_test_records
|
||||||
|
make_test_records("Leave Application")
|
||||||
|
|
||||||
|
def test_block_list(self):
|
||||||
|
import webnotes
|
||||||
|
webnotes.conn.set_value("Employee", "_T-Employee-0001", "department",
|
||||||
|
"_Test Department with Block List")
|
||||||
|
|
||||||
|
application = webnotes.model_wrapper(test_records[1])
|
||||||
|
application.doc.from_date = "2013-01-01"
|
||||||
|
application.doc.to_date = "2013-01-05"
|
||||||
|
self.assertRaises(LeaveDayBlockedError, application.insert)
|
||||||
|
|
||||||
|
if __name__=="__main__":
|
||||||
|
sys.path.extend(["app", "lib"])
|
||||||
|
import webnotes
|
||||||
|
webnotes.connect()
|
||||||
|
unittest.main()
|
||||||
|
|
@ -20,3 +20,10 @@ import webnotes
|
|||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
self.doc, self.doclist = d, dl
|
self.doc, self.doclist = d, dl
|
||||||
|
|
||||||
|
test_records = [
|
||||||
|
[{
|
||||||
|
"leave_type_name": "_Test Leave Type",
|
||||||
|
"doctype": "Leave Type"
|
||||||
|
}]
|
||||||
|
]
|
@ -51,7 +51,8 @@ erpnext.toolbar.setup = function() {
|
|||||||
erpnext.toolbar.add_modules = function() {
|
erpnext.toolbar.add_modules = function() {
|
||||||
$('<li class="dropdown">\
|
$('<li class="dropdown">\
|
||||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#"\
|
<a class="dropdown-toggle" data-toggle="dropdown" href="#"\
|
||||||
onclick="return false;">'+wn._('Modules')+'<b class="caret"></b></a>\
|
title="'+wn._("Modules")+'"\
|
||||||
|
onclick="return false;"><i class="icon-th"></i> <b class="caret"></b></a>\
|
||||||
<ul class="dropdown-menu modules">\
|
<ul class="dropdown-menu modules">\
|
||||||
</ul>\
|
</ul>\
|
||||||
</li>').prependTo('.navbar .nav:first');
|
</li>').prependTo('.navbar .nav:first');
|
||||||
|
@ -165,8 +165,6 @@ class DocType:
|
|||||||
ac_obj.validate()
|
ac_obj.validate()
|
||||||
ac_obj.doc.save(1)
|
ac_obj.doc.save(1)
|
||||||
ac_obj.on_update()
|
ac_obj.on_update()
|
||||||
sql("commit")
|
|
||||||
sql("start transaction")
|
|
||||||
|
|
||||||
|
|
||||||
# Set letter head
|
# Set letter head
|
||||||
@ -257,3 +255,12 @@ class DocType:
|
|||||||
sql("update `tabSingles` set value = %s where doctype='Global Defaults' and field = 'default_company' and value = %s", (newdn, olddn))
|
sql("update `tabSingles` set value = %s where doctype='Global Defaults' and field = 'default_company' and value = %s", (newdn, olddn))
|
||||||
if get_defaults('company') == olddn:
|
if get_defaults('company') == olddn:
|
||||||
set_default('company', newdn)
|
set_default('company', newdn)
|
||||||
|
|
||||||
|
test_records = [
|
||||||
|
[{
|
||||||
|
"company_name": "_Test Company",
|
||||||
|
"abbr": "TC",
|
||||||
|
"default_currency": "INR",
|
||||||
|
"doctype": "Company"
|
||||||
|
}]
|
||||||
|
]
|
@ -20,3 +20,5 @@ import webnotes
|
|||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
self.doc, self.doclist = d, dl
|
self.doc, self.doclist = d, dl
|
||||||
|
|
||||||
|
test_records = []
|
Loading…
x
Reference in New Issue
Block a user