@@ -24,9 +24,12 @@ def validate(self):
24
24
if not self .get ("payroll_cost_centers" ):
25
25
self .set_payroll_cost_centers ()
26
26
27
- self .validate_cost_center_distribution ()
27
+ self .validate_cost_centers ()
28
28
self .warn_about_missing_opening_entries ()
29
29
30
+ def on_update_after_submit (self ):
31
+ self .validate_cost_centers ()
32
+
30
33
def validate_dates (self ):
31
34
joining_date , relieving_date = frappe .db .get_value (
32
35
"Employee" , self .employee , ["date_of_joining" , "relieving_date" ]
@@ -124,11 +127,25 @@ def get_payroll_cost_center(self):
124
127
125
128
return payroll_cost_center
126
129
127
- def validate_cost_center_distribution (self ):
128
- if self .get ("payroll_cost_centers" ):
129
- total_percentage = sum ([flt (d .percentage ) for d in self .get ("payroll_cost_centers" , [])])
130
- if total_percentage != 100 :
131
- frappe .throw (_ ("Total percentage against cost centers should be 100" ))
130
+ def validate_cost_centers (self ):
131
+ if not self .get ("payroll_cost_centers" ):
132
+ return
133
+
134
+ total_percentage = 0
135
+ for entry in self .payroll_cost_centers :
136
+ company = frappe .db .get_value ("Cost Center" , entry .cost_center , "company" )
137
+ if company != self .company :
138
+ frappe .throw (
139
+ _ ("Row {0}: Cost Center {1} does not belong to Company {2}" ).format (
140
+ entry .idx , frappe .bold (entry .cost_center ), frappe .bold (self .company )
141
+ ),
142
+ title = _ ("Invalid Cost Center" ),
143
+ )
144
+
145
+ total_percentage += flt (entry .percentage )
146
+
147
+ if total_percentage != 100 :
148
+ frappe .throw (_ ("Total percentage against cost centers should be 100" ))
132
149
133
150
def warn_about_missing_opening_entries (self ):
134
151
if (
0 commit comments