@@ -47,7 +47,10 @@ def validate(self):
47
47
if not self .get ("payroll_cost_centers" ):
48
48
self .set_payroll_cost_centers ()
49
49
50
- self .validate_cost_center_distribution ()
50
+ self .validate_cost_centers ()
51
+
52
+ def on_update_after_submit (self ):
53
+ self .validate_cost_centers ()
51
54
52
55
def validate_dates (self ):
53
56
joining_date , relieving_date = frappe .db .get_value (
@@ -146,11 +149,25 @@ def get_payroll_cost_center(self):
146
149
147
150
return payroll_cost_center
148
151
149
- def validate_cost_center_distribution (self ):
150
- if self .get ("payroll_cost_centers" ):
151
- total_percentage = sum ([flt (d .percentage ) for d in self .get ("payroll_cost_centers" , [])])
152
- if total_percentage != 100 :
153
- frappe .throw (_ ("Total percentage against cost centers should be 100" ))
152
+ def validate_cost_centers (self ):
153
+ if not self .get ("payroll_cost_centers" ):
154
+ return
155
+
156
+ total_percentage = 0
157
+ for entry in self .payroll_cost_centers :
158
+ company = frappe .db .get_value ("Cost Center" , entry .cost_center , "company" )
159
+ if company != self .company :
160
+ frappe .throw (
161
+ _ ("Row {0}: Cost Center {1} does not belong to Company {2}" ).format (
162
+ entry .idx , frappe .bold (entry .cost_center ), frappe .bold (self .company )
163
+ ),
164
+ title = _ ("Invalid Cost Center" ),
165
+ )
166
+
167
+ total_percentage += flt (entry .percentage )
168
+
169
+ if total_percentage != 100 :
170
+ frappe .throw (_ ("Total percentage against cost centers should be 100" ))
154
171
155
172
@frappe .whitelist ()
156
173
def earning_and_deduction_entries_does_not_exists (self ):
0 commit comments