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
|
||||
get_value = webnotes.conn.get_value
|
||||
|
||||
test_records = []
|
||||
|
||||
class DocType:
|
||||
def __init__(self,d,dl):
|
||||
self.doc, self.doclist = d,dl
|
||||
|
@ -30,4 +30,7 @@ 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."""))
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
fy = webnotes.conn.sql("""select name, year_start_date,
|
||||
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)
|
||||
raise FiscalYearError, error_msg
|
||||
|
||||
return fy[0]
|
||||
return fy
|
||||
|
||||
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") + \
|
||||
": '%(fiscal_year)s'") % {
|
||||
"label": label,
|
||||
|
@ -19,4 +19,6 @@ import webnotes
|
||||
|
||||
class DocType:
|
||||
def __init__(self, d, dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
self.doc, self.doclist = d, dl
|
||||
|
||||
test_records = [[{"doctype":"Branch", "branch":"_Test Branch"}]]
|
@ -19,4 +19,10 @@ import webnotes
|
||||
|
||||
class DocType:
|
||||
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"}],
|
||||
]
|
||||
|
@ -19,4 +19,6 @@ import webnotes
|
||||
|
||||
class DocType:
|
||||
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:
|
||||
msgprint("Please enter relieving date.")
|
||||
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"
|
||||
}]]
|
@ -19,4 +19,7 @@ import webnotes
|
||||
|
||||
class DocType:
|
||||
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"}]]
|
@ -19,4 +19,6 @@ import webnotes
|
||||
|
||||
class DocType:
|
||||
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:
|
||||
webnotes.msgprint(_("Date is repeated") + ":" + d.block_date, raise_exception=1)
|
||||
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
|
||||
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 import form, msgprint
|
||||
|
||||
sql = webnotes.conn.sql
|
||||
import datetime
|
||||
|
||||
class LeaveDayBlockedError(Exception): pass
|
||||
@ -39,7 +38,7 @@ class DocType:
|
||||
self.validate_balance_leaves()
|
||||
self.validate_leave_overlap()
|
||||
self.validate_max_days()
|
||||
#self.validate_block_days()
|
||||
self.validate_block_days()
|
||||
|
||||
def on_submit(self):
|
||||
if self.doc.status != "Approved":
|
||||
@ -55,7 +54,7 @@ class DocType:
|
||||
block_list = webnotes.conn.get_value("Department", department, "holiday_block_list")
|
||||
if block_list:
|
||||
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)
|
||||
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")
|
||||
@ -63,11 +62,11 @@ class DocType:
|
||||
raise LeaveDayBlockedError
|
||||
|
||||
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
|
||||
and h1.holiday_date between %s and %s""", (self.doc.employee, self.doc.from_date, self.doc.to_date))
|
||||
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
|
||||
and ifnull(h2.is_default,0) = 1 and h2.fiscal_year = %s""",
|
||||
(self.doc.from_date, self.doc.to_date, self.doc.fiscal_year))
|
||||
@ -95,13 +94,13 @@ class DocType:
|
||||
self.doc.leave_balance = get_leave_balance(self.doc.employee,
|
||||
self.doc.leave_type, self.doc.fiscal_year)["leave_balance"]
|
||||
self.doc.total_leave_days = self.get_total_leave_days()["total_leave_days"]
|
||||
|
||||
|
||||
if self.doc.leave_balance - self.doc.total_leave_days < 0:
|
||||
msgprint("There is not enough leave balance for Leave Type: %s" % \
|
||||
(self.doc.leave_type,), raise_exception=1)
|
||||
|
||||
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`
|
||||
where
|
||||
(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)
|
||||
|
||||
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
|
||||
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))
|
||||
@ -120,12 +119,12 @@ class DocType:
|
||||
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_leave_balance(employee, leave_type, fiscal_year):
|
||||
def get_leave_balance(employee, leave_type, fiscal_year):
|
||||
leave_all = webnotes.conn.sql("""select total_leaves_allocated
|
||||
from `tabLeave Allocation` where employee = %s and leave_type = %s
|
||||
and fiscal_year = %s and docstatus = 1""", (employee,
|
||||
leave_type, fiscal_year))
|
||||
|
||||
|
||||
leave_all = leave_all and flt(leave_all[0][0]) or 0
|
||||
|
||||
leave_app = webnotes.conn.sql("""select SUM(total_leave_days)
|
||||
@ -147,5 +146,24 @@ def get_approver_list():
|
||||
return roles
|
||||
|
||||
def is_lwp(leave_type):
|
||||
lwp = sql("select is_lwp from `tabLeave Type` where name = %s", leave_type)
|
||||
return lwp and cint(lwp[0][0]) or 0
|
||||
lwp = webnotes.conn.sql("select is_lwp from `tabLeave Type` where name = %s", leave_type)
|
||||
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()
|
||||
|
@ -19,4 +19,11 @@ import webnotes
|
||||
|
||||
class DocType:
|
||||
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() {
|
||||
$('<li class="dropdown">\
|
||||
<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>\
|
||||
</li>').prependTo('.navbar .nav:first');
|
||||
|
@ -165,8 +165,6 @@ class DocType:
|
||||
ac_obj.validate()
|
||||
ac_obj.doc.save(1)
|
||||
ac_obj.on_update()
|
||||
sql("commit")
|
||||
sql("start transaction")
|
||||
|
||||
|
||||
# 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))
|
||||
if get_defaults('company') == olddn:
|
||||
set_default('company', newdn)
|
||||
|
||||
test_records = [
|
||||
[{
|
||||
"company_name": "_Test Company",
|
||||
"abbr": "TC",
|
||||
"default_currency": "INR",
|
||||
"doctype": "Company"
|
||||
}]
|
||||
]
|
@ -19,4 +19,6 @@ import webnotes
|
||||
|
||||
class DocType:
|
||||
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