[fix] Check Salary Structure validity

This commit is contained in:
Nabin Hait 2015-11-15 11:06:43 +05:30
parent 834b3e6f83
commit cd87e76d88
3 changed files with 35 additions and 26 deletions

View File

@ -19,7 +19,7 @@
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Series",
"label": "Series",
"no_copy": 1,
"options": "EXP",
"permlevel": 0,
@ -44,7 +44,7 @@
"ignore_user_permissions": 0,
"in_filter": 1,
"in_list_view": 0,
"label": "Approval Status",
"label": "Approval Status",
"no_copy": 1,
"oldfieldname": "approval_status",
"oldfieldtype": "Select",
@ -536,7 +536,7 @@
"is_submittable": 1,
"issingle": 0,
"istable": 0,
"modified": "2015-10-02 07:38:50.191920",
"modified": "2015-11-14 12:11:13.213073",
"modified_by": "Administrator",
"module": "HR",
"name": "Expense Claim",
@ -564,7 +564,7 @@
},
{
"amend": 0,
"apply_user_permissions": 0,
"apply_user_permissions": 1,
"cancel": 0,
"create": 1,
"delete": 0,
@ -580,6 +580,7 @@
"set_user_permissions": 0,
"share": 1,
"submit": 0,
"user_permission_doctypes": "[\"Employee\"]",
"write": 1
},
{

View File

@ -41,7 +41,7 @@ class ProcessPayroll(Document):
def get_joining_releiving_condition(self):
m = self.get_month_details(self.fiscal_year, self.month)
m = get_month_details(self.fiscal_year, self.month)
cond = """
and ifnull(t1.date_of_joining, '0000-00-00') <= '%(month_end_date)s'
and ifnull(t1.relieving_date, '2199-12-31') >= '%(month_start_date)s'
@ -54,24 +54,6 @@ class ProcessPayroll(Document):
if not self.get(f):
frappe.throw(_("Please set {0}").format(f))
def get_month_details(self, year, month):
ysd = frappe.db.get_value("Fiscal Year", year, "year_start_date")
if ysd:
from dateutil.relativedelta import relativedelta
import calendar, datetime
diff_mnt = cint(month)-cint(ysd.month)
if diff_mnt<0:
diff_mnt = 12-int(ysd.month)+cint(month)
msd = ysd + relativedelta(months=diff_mnt) # month start date
month_days = cint(calendar.monthrange(cint(msd.year) ,cint(month))[1]) # days in month
med = datetime.date(msd.year, cint(month), month_days) # month end date
return {
'year': msd.year,
'month_start_date': msd,
'month_end_date': med,
'month_days': month_days
}
def create_sal_slip(self):
"""
Creates salary slip for selected employees if already not created
@ -205,3 +187,22 @@ class ProcessPayroll(Document):
])
return journal_entry.as_dict()
def get_month_details(year, month):
ysd = frappe.db.get_value("Fiscal Year", year, "year_start_date")
if ysd:
from dateutil.relativedelta import relativedelta
import calendar, datetime
diff_mnt = cint(month)-cint(ysd.month)
if diff_mnt<0:
diff_mnt = 12-int(ysd.month)+cint(month)
msd = ysd + relativedelta(months=diff_mnt) # month start date
month_days = cint(calendar.monthrange(cint(msd.year) ,cint(month))[1]) # days in month
med = datetime.date(msd.year, cint(month), month_days) # month end date
return frappe._dict({
'year': msd.year,
'month_start_date': msd,
'month_end_date': med,
'month_days': month_days
})

View File

@ -10,6 +10,7 @@ from frappe.model.naming import make_autoname
from frappe import msgprint, _
from erpnext.setup.utils import get_company_currency
from erpnext.hr.utils import set_employee_name
from erpnext.hr.doctype.process_payroll.process_payroll import get_month_details
from erpnext.utilities.transaction_base import TransactionBase
@ -25,11 +26,17 @@ class SalarySlip(TransactionBase):
self.pull_sal_struct(struct)
def check_sal_struct(self):
m = get_month_details(self.fiscal_year, self.month)
struct = frappe.db.sql("""select name from `tabSalary Structure`
where employee=%s and is_active = 'Yes'""", self.employee)
where employee=%s and is_active = 'Yes'
and from_date <= %s and (to_date is null or to_date >= %s)""",
(self.employee, m.month_start_date, m.month_end_date))
if not struct:
msgprint(_("Please create Salary Structure for employee {0}").format(self.employee))
msgprint(_("No active Salary Structure found for employee {0} and the month")
.format(self.employee))
self.employee = None
return struct and struct[0][0] or ''
def pull_sal_struct(self, struct):
@ -49,7 +56,7 @@ class SalarySlip(TransactionBase):
if not self.month:
self.month = "%02d" % getdate(nowdate()).month
m = frappe.get_doc('Process Payroll').get_month_details(self.fiscal_year, self.month)
m = get_month_details(self.fiscal_year, self.month)
holidays = self.get_holidays_for_employee(m)
if not cint(frappe.db.get_value("HR Settings", "HR Settings",