-
Notifications
You must be signed in to change notification settings - Fork 780
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: validate total weightage in all appraisal forms (backport #…
…1976) (#1978) (cherry picked from commit bb1b916) Co-authored-by: Rucha Mahabal <[email protected]>
- Loading branch information
1 parent
b6783d8
commit 7795e27
Showing
4 changed files
with
33 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import frappe | ||
from frappe import _ | ||
from frappe.utils import flt | ||
|
||
|
||
class AppraisalMixin: | ||
"""Mixin class for common validations in Appraisal doctypes""" | ||
|
||
def validate_total_weightage(self, table_name: str, table_label: str) -> None: | ||
if not self.get(table_name): | ||
return | ||
|
||
total_weightage = sum(flt(d.per_weightage) for d in self.get(table_name)) | ||
|
||
if flt(total_weightage, 2) != 100.0: | ||
frappe.throw( | ||
_("Total weightage for all {0} must add up to 100. Currently, it is {1}%").format( | ||
frappe.bold(_(table_label)), total_weightage | ||
), | ||
title=_("Incorrect Weightage Allocation"), | ||
) |