adding block list, part 1
This commit is contained in:
parent
4310fd6aa0
commit
2e8d078adf
@ -20,11 +20,11 @@ import webnotes
|
||||
from webnotes.utils import nowdate, cstr, flt
|
||||
from webnotes.model.doc import addchild
|
||||
from webnotes import msgprint, _
|
||||
from webnotes.utils import formatdate
|
||||
|
||||
class FiscalYearError(webnotes.ValidationError): pass
|
||||
|
||||
def get_fiscal_year(date, verbose=1):
|
||||
from webnotes.utils import formatdate
|
||||
# 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)
|
||||
@ -39,6 +39,15 @@ def get_fiscal_year(date, verbose=1):
|
||||
raise FiscalYearError, error_msg
|
||||
|
||||
return fy[0]
|
||||
|
||||
def validate_fiscal_year(date, fiscal_year, label="Date"):
|
||||
if get_fiscal_year(date)[0] != fiscal_year:
|
||||
msgprint(("%(label)s '%(posting_date)s': " + _("not within Fiscal Year") + \
|
||||
": '%(fiscal_year)s'") % {
|
||||
"label": label,
|
||||
"posting_date": formatdate(date),
|
||||
"fiscal_year": fiscal_year
|
||||
}, raise_exception=1)
|
||||
|
||||
@webnotes.whitelist()
|
||||
def get_balance_on(account=None, date=None):
|
||||
|
@ -2,7 +2,7 @@
|
||||
{
|
||||
"creation": "2013-01-10 16:34:13",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-01-22 14:46:41",
|
||||
"modified": "2013-02-04 15:34:55",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@ -57,6 +57,14 @@
|
||||
"oldfieldtype": "Data",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"description": "Days for which Holidays are blocked for this department.",
|
||||
"doctype": "DocField",
|
||||
"fieldname": "holiday_block_list",
|
||||
"fieldtype": "Link",
|
||||
"label": "Holiday Block List",
|
||||
"options": "Holiday Block List"
|
||||
},
|
||||
{
|
||||
"doctype": "DocPerm",
|
||||
"role": "System Manager"
|
||||
|
0
hr/doctype/holiday_block_list/__init__.py
Normal file
0
hr/doctype/holiday_block_list/__init__.py
Normal file
21
hr/doctype/holiday_block_list/holiday_block_list.py
Normal file
21
hr/doctype/holiday_block_list/holiday_block_list.py
Normal file
@ -0,0 +1,21 @@
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from accounts.utils import validate_fiscal_year
|
||||
from webnotes import _
|
||||
|
||||
class DocType:
|
||||
def __init__(self, d, dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
|
||||
def validate(self):
|
||||
dates = []
|
||||
for d in self.doclist.get({"doctype":"Holiday Block List Date"}):
|
||||
# validate fiscal year
|
||||
validate_fiscal_year(d.block_date, self.doc.year, _("Block Date"))
|
||||
|
||||
# date is not repeated
|
||||
if d.block_date in dates:
|
||||
webnotes.msgprint(_("Date is repeated") + ":" + d.block_date, raise_exception=1)
|
||||
dates.append(d.block_date)
|
66
hr/doctype/holiday_block_list/holiday_block_list.txt
Normal file
66
hr/doctype/holiday_block_list/holiday_block_list.txt
Normal file
@ -0,0 +1,66 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-02-04 15:31:29",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-02-04 15:38:57",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
{
|
||||
"autoname": "field:holiday_block_list_name",
|
||||
"description": "Block Holidays on important days.",
|
||||
"doctype": "DocType",
|
||||
"document_type": "Master",
|
||||
"module": "HR",
|
||||
"name": "__common__"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"name": "__common__",
|
||||
"parent": "Holiday Block List",
|
||||
"parentfield": "fields",
|
||||
"parenttype": "DocType",
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"create": 1,
|
||||
"doctype": "DocPerm",
|
||||
"name": "__common__",
|
||||
"parent": "Holiday Block List",
|
||||
"parentfield": "permissions",
|
||||
"parenttype": "DocType",
|
||||
"permlevel": 0,
|
||||
"read": 1,
|
||||
"role": "HR User",
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocType",
|
||||
"name": "Holiday Block List"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "holiday_block_list_name",
|
||||
"fieldtype": "Data",
|
||||
"label": "Holiday Block List Name",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "year",
|
||||
"fieldtype": "Link",
|
||||
"label": "Year",
|
||||
"options": "Fiscal Year",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "holiday_block_list_dates",
|
||||
"fieldtype": "Table",
|
||||
"label": "Holiday Block List Dates",
|
||||
"options": "Holiday Block List Date"
|
||||
},
|
||||
{
|
||||
"doctype": "DocPerm"
|
||||
}
|
||||
]
|
0
hr/doctype/holiday_block_list_date/__init__.py
Normal file
0
hr/doctype/holiday_block_list_date/__init__.py
Normal file
@ -0,0 +1,8 @@
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
|
||||
class DocType:
|
||||
def __init__(self, d, dl):
|
||||
self.doc, self.doclist = d, dl
|
@ -0,0 +1,40 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-02-04 15:33:14",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-02-04 15:36:10",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
{
|
||||
"doctype": "DocType",
|
||||
"istable": 1,
|
||||
"module": "HR",
|
||||
"name": "__common__"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"name": "__common__",
|
||||
"parent": "Holiday Block List Date",
|
||||
"parentfield": "fields",
|
||||
"parenttype": "DocType",
|
||||
"permlevel": 0,
|
||||
"width": "200px"
|
||||
},
|
||||
{
|
||||
"doctype": "DocType",
|
||||
"name": "Holiday Block List Date"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "block_date",
|
||||
"fieldtype": "Date",
|
||||
"label": "Block Date"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "reason",
|
||||
"fieldtype": "Text",
|
||||
"label": "Reason"
|
||||
}
|
||||
]
|
@ -80,6 +80,11 @@ wn.module_page["HR"] = [
|
||||
"description":wn._("List of holidays."),
|
||||
doctype: "Holiday List"
|
||||
},
|
||||
{
|
||||
"label":wn._("Holiday Block List"),
|
||||
"description":wn._("Block leave applications by department."),
|
||||
doctype: "Holiday Block List"
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -599,14 +599,8 @@ class DocType(TransactionBase):
|
||||
get_obj('Account',acc_head[0][0]).check_credit_limit(acc_head[0][0], obj.doc.company, exact_outstanding)
|
||||
|
||||
def validate_fiscal_year(self, fiscal_year, transaction_date, label):
|
||||
from accounts.utils import get_fiscal_year
|
||||
if get_fiscal_year(transaction_date)[0] != fiscal_year:
|
||||
msgprint(("%(label)s '%(posting_date)s': " + _("not within Fiscal Year") + \
|
||||
": '%(fiscal_year)s'") % {
|
||||
"label": label,
|
||||
"posting_date": formatdate(transaction_date),
|
||||
"fiscal_year": fiscal_year
|
||||
}, raise_exception=1)
|
||||
import accounts.utils
|
||||
accounts.utils.validate_fiscal_year(transaction_date, fiscal_year, label)
|
||||
|
||||
def get_prevdoc_date(self, obj):
|
||||
for d in getlist(obj.doclist, obj.fname):
|
||||
|
Loading…
x
Reference in New Issue
Block a user