15
15
16
16
class Gratuity (AccountsController ):
17
17
def validate (self ):
18
- data = calculate_work_experience_and_amount ( self .employee , self . gratuity_rule )
18
+ data = self .calculate_work_experience_and_amount ( )
19
19
self .current_work_experience = data ["current_work_experience" ]
20
20
self .amount = data ["amount" ]
21
21
self .set_status ()
22
22
23
+ @frappe .whitelist ()
24
+ def calculate_work_experience_and_amount (self ):
25
+ rule = get_gratuity_rule_config (self .gratuity_rule )
26
+
27
+ if rule .method == "Manual" :
28
+ current_work_experience = flt (self .current_work_experience )
29
+ else :
30
+ current_work_experience = calculate_work_experience (self .employee , self .gratuity_rule ) or 0
31
+
32
+ gratuity_amount = (
33
+ calculate_gratuity_amount (self .employee , self .gratuity_rule , current_work_experience ) or 0
34
+ )
35
+
36
+ return {"current_work_experience" : current_work_experience , "amount" : gratuity_amount }
37
+
23
38
def set_status (self , update = False ):
24
39
precision = self .precision ("paid_amount" )
25
40
status = None
@@ -130,19 +145,21 @@ def set_total_advance_paid(self):
130
145
self .set_status (update = True )
131
146
132
147
133
- @frappe .whitelist ()
134
- def calculate_work_experience_and_amount (employee , gratuity_rule ):
135
- current_work_experience = calculate_work_experience (employee , gratuity_rule ) or 0
136
- gratuity_amount = calculate_gratuity_amount (employee , gratuity_rule , current_work_experience ) or 0
137
-
138
- return {"current_work_experience" : current_work_experience , "amount" : gratuity_amount }
148
+ def get_gratuity_rule_config (gratuity_rule : str ) -> dict :
149
+ return frappe .db .get_value (
150
+ "Gratuity Rule" ,
151
+ gratuity_rule ,
152
+ [
153
+ "work_experience_calculation_function as method" ,
154
+ "total_working_days_per_year" ,
155
+ "minimum_year_for_gratuity" ,
156
+ ],
157
+ as_dict = True ,
158
+ )
139
159
140
160
141
161
def calculate_work_experience (employee , gratuity_rule ):
142
-
143
- total_working_days_per_year , minimum_year_for_gratuity = frappe .db .get_value (
144
- "Gratuity Rule" , gratuity_rule , ["total_working_days_per_year" , "minimum_year_for_gratuity" ]
145
- )
162
+ rule = get_gratuity_rule_config (gratuity_rule )
146
163
147
164
date_of_joining , relieving_date = frappe .db .get_value (
148
165
"Employee" , employee , ["date_of_joining" , "relieving_date" ]
@@ -154,16 +171,13 @@ def calculate_work_experience(employee, gratuity_rule):
154
171
)
155
172
)
156
173
157
- method = frappe .db .get_value (
158
- "Gratuity Rule" , gratuity_rule , "work_experience_calculation_function"
159
- )
160
174
employee_total_workings_days = calculate_employee_total_workings_days (
161
175
employee , date_of_joining , relieving_date
162
176
)
163
177
164
- current_work_experience = employee_total_workings_days / total_working_days_per_year or 1
178
+ current_work_experience = employee_total_workings_days / rule . total_working_days_per_year or 1
165
179
current_work_experience = get_work_experience_using_method (
166
- method , current_work_experience , minimum_year_for_gratuity , employee
180
+ rule . method , current_work_experience , rule . minimum_year_for_gratuity , employee
167
181
)
168
182
return current_work_experience
169
183
0 commit comments