blob: deec64420939deb76e64d68abfa49f9127db38e6 [file] [log] [blame]
Anand Doshi885e0742015-03-03 14:55:30 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302# License: GNU General Public License v3. See license.txt
Anand Doshi60666a22013-04-12 20:19:53 +05303
Rohandb2d1962021-03-09 21:03:45 +05304import frappe
Rohandb2d1962021-03-09 21:03:45 +05305from frappe import _
Chillar Anand915b3432021-09-02 16:44:59 +05306from frappe.utils import (
7 add_days,
8 cstr,
9 flt,
10 format_datetime,
11 formatdate,
12 get_datetime,
13 get_link_to_form,
14 getdate,
15 nowdate,
16 today,
17)
18
19import erpnext
20from erpnext.hr.doctype.employee.employee import (
21 InactiveEmployeeStatusError,
22 get_holiday_list_for_employee,
23)
24
Manas Solankib6988462018-05-10 18:07:20 +053025
Nabin Hait58ee6c12020-04-26 17:45:57 +053026class DuplicateDeclarationError(frappe.ValidationError): pass
27
Anand Doshic280d062014-05-30 14:43:36 +053028def set_employee_name(doc):
29 if doc.employee and not doc.employee_name:
30 doc.employee_name = frappe.db.get_value("Employee", doc.employee, "employee_name")
Ranjithfddfffd2018-05-05 13:27:26 +053031
Ranjith Kurungadame46639f2018-06-11 11:24:44 +053032def update_employee(employee, details, date=None, cancel=False):
33 internal_work_history = {}
Manas Solankib6988462018-05-10 18:07:20 +053034 for item in details:
35 fieldtype = frappe.get_meta("Employee").get_field(item.fieldname).fieldtype
36 new_data = item.new if not cancel else item.current
37 if fieldtype == "Date" and new_data:
38 new_data = getdate(new_data)
39 elif fieldtype =="Datetime" and new_data:
40 new_data = get_datetime(new_data)
41 setattr(employee, item.fieldname, new_data)
Ranjith Kurungadame46639f2018-06-11 11:24:44 +053042 if item.fieldname in ["department", "designation", "branch"]:
43 internal_work_history[item.fieldname] = item.new
44 if internal_work_history and not cancel:
45 internal_work_history["from_date"] = date
46 employee.append("internal_work_history", internal_work_history)
Manas Solankib6988462018-05-10 18:07:20 +053047 return employee
48
Ranjithfddfffd2018-05-05 13:27:26 +053049@frappe.whitelist()
50def get_employee_fields_label():
51 fields = []
52 for df in frappe.get_meta("Employee").get("fields"):
Ranjith Kurungadamc1030a32018-06-20 12:42:58 +053053 if df.fieldname in ["salutation", "user_id", "employee_number", "employment_type",
Nabin Hait6b9d64c2019-05-16 11:23:04 +053054 "holiday_list", "branch", "department", "designation", "grade",
55 "notice_number_of_days", "reports_to", "leave_policy", "company_email"]:
56 fields.append({"value": df.fieldname, "label": df.label})
Ranjithfddfffd2018-05-05 13:27:26 +053057 return fields
58
59@frappe.whitelist()
60def get_employee_field_property(employee, fieldname):
61 if employee and fieldname:
62 field = frappe.get_meta("Employee").get_field(fieldname)
63 value = frappe.db.get_value("Employee", employee, fieldname)
64 options = field.options
65 if field.fieldtype == "Date":
66 value = formatdate(value)
67 elif field.fieldtype == "Datetime":
68 value = format_datetime(value)
69 return {
70 "value" : value,
71 "datatype" : field.fieldtype,
72 "label" : field.label,
73 "options" : options
74 }
75 else:
76 return False
77
Jamsheer0e2cc552018-05-08 11:48:25 +053078def validate_dates(doc, from_date, to_date):
79 date_of_joining, relieving_date = frappe.db.get_value("Employee", doc.employee, ["date_of_joining", "relieving_date"])
80 if getdate(from_date) > getdate(to_date):
81 frappe.throw(_("To date can not be less than from date"))
82 elif getdate(from_date) > getdate(nowdate()):
83 frappe.throw(_("Future dates not allowed"))
84 elif date_of_joining and getdate(from_date) < getdate(date_of_joining):
85 frappe.throw(_("From date can not be less than employee's joining date"))
86 elif relieving_date and getdate(to_date) > getdate(relieving_date):
87 frappe.throw(_("To date can not greater than employee's relieving date"))
88
89def validate_overlap(doc, from_date, to_date, company = None):
90 query = """
91 select name
92 from `tab{0}`
93 where name != %(name)s
94 """
95 query += get_doc_condition(doc.doctype)
96
97 if not doc.name:
98 # hack! if name is null, it could cause problems with !=
99 doc.name = "New "+doc.doctype
100
101 overlap_doc = frappe.db.sql(query.format(doc.doctype),{
Nabin Haitd53c2c02018-07-30 20:16:48 +0530102 "employee": doc.get("employee"),
Jamsheer0e2cc552018-05-08 11:48:25 +0530103 "from_date": from_date,
104 "to_date": to_date,
105 "name": doc.name,
106 "company": company
107 }, as_dict = 1)
108
109 if overlap_doc:
deepeshgarg00778b273a2018-10-31 18:12:03 +0530110 if doc.get("employee"):
111 exists_for = doc.employee
Jamsheer0e2cc552018-05-08 11:48:25 +0530112 if company:
113 exists_for = company
114 throw_overlap_error(doc, exists_for, overlap_doc[0].name, from_date, to_date)
115
116def get_doc_condition(doctype):
117 if doctype == "Compensatory Leave Request":
118 return "and employee = %(employee)s and docstatus < 2 \
119 and (work_from_date between %(from_date)s and %(to_date)s \
120 or work_end_date between %(from_date)s and %(to_date)s \
121 or (work_from_date < %(from_date)s and work_end_date > %(to_date)s))"
122 elif doctype == "Leave Period":
123 return "and company = %(company)s and (from_date between %(from_date)s and %(to_date)s \
124 or to_date between %(from_date)s and %(to_date)s \
125 or (from_date < %(from_date)s and to_date > %(to_date)s))"
126
127def throw_overlap_error(doc, exists_for, overlap_doc, from_date, to_date):
128 msg = _("A {0} exists between {1} and {2} (").format(doc.doctype,
129 formatdate(from_date), formatdate(to_date)) \
Rushabh Mehta542bc012020-11-18 15:00:34 +0530130 + """ <b><a href="/app/Form/{0}/{1}">{1}</a></b>""".format(doc.doctype, overlap_doc) \
Jamsheer0e2cc552018-05-08 11:48:25 +0530131 + _(") for {0}").format(exists_for)
132 frappe.throw(msg)
133
Nabin Hait58ee6c12020-04-26 17:45:57 +0530134def validate_duplicate_exemption_for_payroll_period(doctype, docname, payroll_period, employee):
135 existing_record = frappe.db.exists(doctype, {
136 "payroll_period": payroll_period,
137 "employee": employee,
138 'docstatus': ['<', 2],
139 'name': ['!=', docname]
140 })
141 if existing_record:
142 frappe.throw(_("{0} already exists for employee {1} and period {2}")
143 .format(doctype, employee, payroll_period), DuplicateDeclarationError)
144
Ranjith5a8e6422018-05-10 15:06:49 +0530145def validate_tax_declaration(declarations):
146 subcategories = []
Nabin Hait04e7bf42019-04-25 18:44:10 +0530147 for d in declarations:
148 if d.exemption_sub_category in subcategories:
149 frappe.throw(_("More than one selection for {0} not allowed").format(d.exemption_sub_category))
150 subcategories.append(d.exemption_sub_category)
151
152def get_total_exemption_amount(declarations):
Nabin Hait04e7bf42019-04-25 18:44:10 +0530153 exemptions = frappe._dict()
154 for d in declarations:
155 exemptions.setdefault(d.exemption_category, frappe._dict())
156 category_max_amount = exemptions.get(d.exemption_category).max_amount
157 if not category_max_amount:
158 category_max_amount = frappe.db.get_value("Employee Tax Exemption Category", d.exemption_category, "max_amount")
159 exemptions.get(d.exemption_category).max_amount = category_max_amount
160 sub_category_exemption_amount = d.max_amount \
161 if (d.max_amount and flt(d.amount) > flt(d.max_amount)) else d.amount
162
163 exemptions.get(d.exemption_category).setdefault("total_exemption_amount", 0.0)
164 exemptions.get(d.exemption_category).total_exemption_amount += flt(sub_category_exemption_amount)
165
166 if category_max_amount and exemptions.get(d.exemption_category).total_exemption_amount > category_max_amount:
167 exemptions.get(d.exemption_category).total_exemption_amount = category_max_amount
168
169 total_exemption_amount = sum([flt(d.total_exemption_amount) for d in exemptions.values()])
170 return total_exemption_amount
rohitwaghchaure3f0c7352018-05-14 20:47:35 +0530171
Jannat Patel1175e062021-06-01 10:53:00 +0530172@frappe.whitelist()
Jamsheer0e2cc552018-05-08 11:48:25 +0530173def get_leave_period(from_date, to_date, company):
174 leave_period = frappe.db.sql("""
175 select name, from_date, to_date
176 from `tabLeave Period`
177 where company=%(company)s and is_active=1
178 and (from_date between %(from_date)s and %(to_date)s
179 or to_date between %(from_date)s and %(to_date)s
180 or (from_date < %(from_date)s and to_date > %(to_date)s))
181 """, {
182 "from_date": from_date,
183 "to_date": to_date,
184 "company": company
185 }, as_dict=1)
186
187 if leave_period:
188 return leave_period
Ranjithb485b1e2018-05-16 23:01:40 +0530189
Mangesh-Khairnarf281f002019-08-05 14:47:02 +0530190def generate_leave_encashment():
191 ''' Generates a draft leave encashment on allocation expiry '''
192 from erpnext.hr.doctype.leave_encashment.leave_encashment import create_leave_encashment
Mangesh-Khairnar3662ed52019-08-08 19:47:17 +0530193
Mangesh-Khairnarf281f002019-08-05 14:47:02 +0530194 if frappe.db.get_single_value('HR Settings', 'auto_leave_encashment'):
Mangesh-Khairnar3662ed52019-08-08 19:47:17 +0530195 leave_type = frappe.get_all('Leave Type', filters={'allow_encashment': 1}, fields=['name'])
196 leave_type=[l['name'] for l in leave_type]
Mangesh-Khairnarf281f002019-08-05 14:47:02 +0530197
198 leave_allocation = frappe.get_all("Leave Allocation", filters={
199 'to_date': add_days(today(), -1),
200 'leave_type': ('in', leave_type)
201 }, fields=['employee', 'leave_period', 'leave_type', 'to_date', 'total_leaves_allocated', 'new_leaves_allocated'])
202
203 create_leave_encashment(leave_allocation=leave_allocation)
204
Ranjith Kurungadam375db612018-06-01 16:09:28 +0530205def allocate_earned_leaves():
206 '''Allocate earned leaves to Employees'''
Anurag Mishra755b7732020-11-25 16:05:17 +0530207 e_leave_types = get_earned_leaves()
Ranjith Kurungadam375db612018-06-01 16:09:28 +0530208 today = getdate()
Ranjith Kurungadam375db612018-06-01 16:09:28 +0530209
Mangesh-Khairnar3863fc52019-06-06 20:34:10 +0530210 for e_leave_type in e_leave_types:
Anurag Mishra755b7732020-11-25 16:05:17 +0530211
212 leave_allocations = get_leave_allocations(today, e_leave_type.name)
213
Mangesh-Khairnar3863fc52019-06-06 20:34:10 +0530214 for allocation in leave_allocations:
Anurag Mishra755b7732020-11-25 16:05:17 +0530215
216 if not allocation.leave_policy_assignment and not allocation.leave_policy:
Mangesh-Khairnar3863fc52019-06-06 20:34:10 +0530217 continue
Anurag Mishra755b7732020-11-25 16:05:17 +0530218
219 leave_policy = allocation.leave_policy if allocation.leave_policy else frappe.db.get_value(
220 "Leave Policy Assignment", allocation.leave_policy_assignment, ["leave_policy"])
221
Mangesh-Khairnar261d1322019-08-09 13:18:52 +0530222 annual_allocation = frappe.db.get_value("Leave Policy Detail", filters={
Anurag Mishra755b7732020-11-25 16:05:17 +0530223 'parent': leave_policy,
Mangesh-Khairnar3662ed52019-08-08 19:47:17 +0530224 'leave_type': e_leave_type.name
Mangesh-Khairnar261d1322019-08-09 13:18:52 +0530225 }, fieldname=['annual_allocation'])
Mangesh-Khairnar3863fc52019-06-06 20:34:10 +0530226
Anurag Mishra755b7732020-11-25 16:05:17 +0530227 from_date=allocation.from_date
Mangesh-Khairnar5d5f5b42020-02-20 13:25:55 +0530228
Anurag Mishra755b7732020-11-25 16:05:17 +0530229 if e_leave_type.based_on_date_of_joining_date:
230 from_date = frappe.db.get_value("Employee", allocation.employee, "date_of_joining")
Mangesh-Khairnar3863fc52019-06-06 20:34:10 +0530231
Anurag Mishra755b7732020-11-25 16:05:17 +0530232 if check_effective_date(from_date, today, e_leave_type.earned_leave_frequency, e_leave_type.based_on_date_of_joining_date):
233 update_previous_leave_allocation(allocation, annual_allocation, e_leave_type)
234
235def update_previous_leave_allocation(allocation, annual_allocation, e_leave_type):
Nabin Hait190106a2021-03-02 13:38:14 +0530236 earned_leaves = get_monthly_earned_leave(annual_allocation, e_leave_type.earned_leave_frequency, e_leave_type.rounding)
Anurag Mishra755b7732020-11-25 16:05:17 +0530237
238 allocation = frappe.get_doc('Leave Allocation', allocation.name)
239 new_allocation = flt(allocation.total_leaves_allocated) + flt(earned_leaves)
240
241 if new_allocation > e_leave_type.max_leaves_allowed and e_leave_type.max_leaves_allowed > 0:
242 new_allocation = e_leave_type.max_leaves_allowed
243
244 if new_allocation != allocation.total_leaves_allocated:
245 allocation.db_set("total_leaves_allocated", new_allocation, update_modified=False)
246 today_date = today()
247 create_additional_leave_ledger_entry(allocation, earned_leaves, today_date)
248
Nabin Hait190106a2021-03-02 13:38:14 +0530249def get_monthly_earned_leave(annual_leaves, frequency, rounding):
250 earned_leaves = 0.0
251 divide_by_frequency = {"Yearly": 1, "Half-Yearly": 6, "Quarterly": 4, "Monthly": 12}
252 if annual_leaves:
253 earned_leaves = flt(annual_leaves) / divide_by_frequency[frequency]
254 if rounding:
255 if rounding == "0.25":
256 earned_leaves = round(earned_leaves * 4) / 4
257 elif rounding == "0.5":
258 earned_leaves = round(earned_leaves * 2) / 2
259 else:
260 earned_leaves = round(earned_leaves)
261
262 return earned_leaves
263
Anurag Mishra755b7732020-11-25 16:05:17 +0530264
265def get_leave_allocations(date, leave_type):
266 return frappe.db.sql("""select name, employee, from_date, to_date, leave_policy_assignment, leave_policy
267 from `tabLeave Allocation`
268 where
269 %s between from_date and to_date and docstatus=1
270 and leave_type=%s""",
271 (date, leave_type), as_dict=1)
272
273
274def get_earned_leaves():
275 return frappe.get_all("Leave Type",
276 fields=["name", "max_leaves_allowed", "earned_leave_frequency", "rounding", "based_on_date_of_joining"],
277 filters={'is_earned_leave' : 1})
Mangesh-Khairnar3863fc52019-06-06 20:34:10 +0530278
Mangesh-Khairnar43508462019-12-09 14:27:38 +0530279def create_additional_leave_ledger_entry(allocation, leaves, date):
280 ''' Create leave ledger entry for leave types '''
281 allocation.new_leaves_allocated = leaves
Mangesh-Khairnar3863fc52019-06-06 20:34:10 +0530282 allocation.from_date = date
Mangesh-Khairnar5cbe6162019-08-08 17:06:15 +0530283 allocation.unused_leaves = 0
Mangesh-Khairnar3863fc52019-06-06 20:34:10 +0530284 allocation.create_leave_ledger_entry()
Ranjith Kurungadam375db612018-06-01 16:09:28 +0530285
Anurag Mishra755b7732020-11-25 16:05:17 +0530286def check_effective_date(from_date, to_date, frequency, based_on_date_of_joining_date):
287 import calendar
Chillar Anand915b3432021-09-02 16:44:59 +0530288
Ranjith Kurungadam375db612018-06-01 16:09:28 +0530289 from dateutil import relativedelta
Anurag Mishra755b7732020-11-25 16:05:17 +0530290
291 from_date = get_datetime(from_date)
292 to_date = get_datetime(to_date)
293 rd = relativedelta.relativedelta(to_date, from_date)
294 #last day of month
295 last_day = calendar.monthrange(to_date.year, to_date.month)[1]
296
297 if (from_date.day == to_date.day and based_on_date_of_joining_date) or (not based_on_date_of_joining_date and to_date.day == last_day):
298 if frequency == "Monthly":
Ranjith Kurungadam375db612018-06-01 16:09:28 +0530299 return True
Anurag Mishra755b7732020-11-25 16:05:17 +0530300 elif frequency == "Quarterly" and rd.months % 3:
Joyce Babu3d012132019-03-06 13:04:45 +0530301 return True
Anurag Mishra755b7732020-11-25 16:05:17 +0530302 elif frequency == "Half-Yearly" and rd.months % 6:
Ranjith Kurungadam375db612018-06-01 16:09:28 +0530303 return True
Anurag Mishra755b7732020-11-25 16:05:17 +0530304 elif frequency == "Yearly" and rd.months % 12:
305 return True
306
307 if frappe.flags.in_test:
308 return True
309
Ranjith Kurungadam375db612018-06-01 16:09:28 +0530310 return False
Nabin Hait8c7af492018-06-04 11:23:36 +0530311
Anurag Mishra755b7732020-11-25 16:05:17 +0530312
Ranjith155ecc12018-05-30 13:37:15 +0530313def get_salary_assignment(employee, date):
314 assignment = frappe.db.sql("""
315 select * from `tabSalary Structure Assignment`
316 where employee=%(employee)s
317 and docstatus = 1
Ranjith Kurungadamb4ad3c32018-06-25 10:29:54 +0530318 and %(on_date)s >= from_date order by from_date desc limit 1""", {
Ranjith155ecc12018-05-30 13:37:15 +0530319 'employee': employee,
320 'on_date': date,
321 }, as_dict=1)
322 return assignment[0] if assignment else None
Ranjith793f8e82018-05-30 20:50:48 +0530323
Jamsheer8d66f1e2018-06-12 11:30:59 +0530324def get_sal_slip_total_benefit_given(employee, payroll_period, component=False):
325 total_given_benefit_amount = 0
326 query = """
327 select sum(sd.amount) as 'total_amount'
328 from `tabSalary Slip` ss, `tabSalary Detail` sd
329 where ss.employee=%(employee)s
330 and ss.docstatus = 1 and ss.name = sd.parent
331 and sd.is_flexible_benefit = 1 and sd.parentfield = "earnings"
332 and sd.parenttype = "Salary Slip"
333 and (ss.start_date between %(start_date)s and %(end_date)s
334 or ss.end_date between %(start_date)s and %(end_date)s
335 or (ss.start_date < %(start_date)s and ss.end_date > %(end_date)s))
336 """
337
338 if component:
339 query += "and sd.salary_component = %(component)s"
340
341 sum_of_given_benefit = frappe.db.sql(query, {
342 'employee': employee,
343 'start_date': payroll_period.start_date,
344 'end_date': payroll_period.end_date,
345 'component': component
346 }, as_dict=True)
347
Rushabh Mehtadf23c7d2018-07-05 15:19:28 +0530348 if sum_of_given_benefit and flt(sum_of_given_benefit[0].total_amount) > 0:
Jamsheer8d66f1e2018-06-12 11:30:59 +0530349 total_given_benefit_amount = sum_of_given_benefit[0].total_amount
350 return total_given_benefit_amount
Jamsheercc25eb02018-06-13 15:14:24 +0530351
Frappe PR Bot255b99e2021-08-24 20:19:22 +0530352def get_holiday_dates_for_employee(employee, start_date, end_date):
353 """return a list of holiday dates for the given employee between start_date and end_date"""
Ankush Menatb147b852021-09-01 16:45:57 +0530354 # return only date
355 holidays = get_holidays_for_employee(employee, start_date, end_date)
356
Frappe PR Bot255b99e2021-08-24 20:19:22 +0530357 return [cstr(h.holiday_date) for h in holidays]
Mangesh-Khairnar43508462019-12-09 14:27:38 +0530358
Jamsheercc25eb02018-06-13 15:14:24 +0530359
Frappe PR Bot255b99e2021-08-24 20:19:22 +0530360def get_holidays_for_employee(employee, start_date, end_date, raise_exception=True, only_non_weekly=False):
361 """Get Holidays for a given employee
Jamsheercc25eb02018-06-13 15:14:24 +0530362
Frappe PR Bot255b99e2021-08-24 20:19:22 +0530363 `employee` (str)
364 `start_date` (str or datetime)
365 `end_date` (str or datetime)
366 `raise_exception` (bool)
367 `only_non_weekly` (bool)
368
Ankush Menatb147b852021-09-01 16:45:57 +0530369 return: list of dicts with `holiday_date` and `description`
Frappe PR Bot255b99e2021-08-24 20:19:22 +0530370 """
371 holiday_list = get_holiday_list_for_employee(employee, raise_exception=raise_exception)
372
373 if not holiday_list:
374 return []
375
376 filters = {
377 'parent': holiday_list,
378 'holiday_date': ('between', [start_date, end_date])
379 }
380
381 if only_non_weekly:
382 filters['weekly_off'] = False
383
384 holidays = frappe.get_all(
Ankush Menatb147b852021-09-01 16:45:57 +0530385 'Holiday',
Frappe PR Bot255b99e2021-08-24 20:19:22 +0530386 fields=['description', 'holiday_date'],
387 filters=filters
388 )
Ankush Menatb147b852021-09-01 16:45:57 +0530389
Jamsheercc25eb02018-06-13 15:14:24 +0530390 return holidays
Ranjith Kurungadama8e047a2018-06-14 17:56:16 +0530391
392@erpnext.allow_regional
393def calculate_annual_eligible_hra_exemption(doc):
394 # Don't delete this method, used for localization
395 # Indian HRA Exemption Calculation
396 return {}
397
398@erpnext.allow_regional
399def calculate_hra_exemption_for_period(doc):
400 # Don't delete this method, used for localization
401 # Indian HRA Exemption Calculation
402 return {}
Jamsheer55a2f4d2018-06-20 11:04:21 +0530403
404def get_previous_claimed_amount(employee, payroll_period, non_pro_rata=False, component=False):
405 total_claimed_amount = 0
406 query = """
407 select sum(claimed_amount) as 'total_amount'
408 from `tabEmployee Benefit Claim`
409 where employee=%(employee)s
410 and docstatus = 1
411 and (claim_date between %(start_date)s and %(end_date)s)
412 """
413 if non_pro_rata:
414 query += "and pay_against_benefit_claim = 1"
415 if component:
416 query += "and earning_component = %(component)s"
417
418 sum_of_claimed_amount = frappe.db.sql(query, {
419 'employee': employee,
420 'start_date': payroll_period.start_date,
421 'end_date': payroll_period.end_date,
422 'component': component
423 }, as_dict=True)
Rushabh Mehtadf23c7d2018-07-05 15:19:28 +0530424 if sum_of_claimed_amount and flt(sum_of_claimed_amount[0].total_amount) > 0:
Jamsheer55a2f4d2018-06-20 11:04:21 +0530425 total_claimed_amount = sum_of_claimed_amount[0].total_amount
426 return total_claimed_amount
Anurag Mishra755b7732020-11-25 16:05:17 +0530427
Rucha Mahabalba10ef42021-04-04 17:16:48 +0530428def share_doc_with_approver(doc, user):
429 # if approver does not have permissions, share
430 if not frappe.has_permission(doc=doc, ptype="submit", user=user):
Rucha Mahabal8c055b52021-04-04 18:45:06 +0530431 frappe.share.add(doc.doctype, doc.name, user, submit=1,
432 flags={"ignore_share_permission": True})
433
Rucha Mahabalba10ef42021-04-04 17:16:48 +0530434 frappe.msgprint(_("Shared with the user {0} with {1} access").format(
435 user, frappe.bold("submit"), alert=True))
436
437 # remove shared doc if approver changes
438 doc_before_save = doc.get_doc_before_save()
439 if doc_before_save:
440 approvers = {
441 "Leave Application": "leave_approver",
442 "Expense Claim": "expense_approver",
443 "Shift Request": "approver"
444 }
445
446 approver = approvers.get(doc.doctype)
447 if doc_before_save.get(approver) != doc.get(approver):
448 frappe.share.remove(doc.doctype, doc.name, doc_before_save.get(approver))
Rucha Mahabal821db5c2021-07-30 10:21:42 +0530449
450def validate_active_employee(employee):
451 if frappe.db.get_value("Employee", employee, "status") == "Inactive":
452 frappe.throw(_("Transactions cannot be created for an Inactive Employee {0}.").format(
Ankush Menat4551d7d2021-08-19 13:41:10 +0530453 get_link_to_form("Employee", employee)), InactiveEmployeeStatusError)