From 30299c6f499ff810a99160f8ddb7e29f67b1e473 Mon Sep 17 00:00:00 2001 From: Anurag Mishra Date: Fri, 14 Aug 2020 16:44:22 +0530 Subject: [PATCH] feat: validating and ordeing the rule slabr --- .../doctype/gratuity_rule/gratuity_rule.js | 33 +++++++++++++++++ .../doctype/gratuity_rule/gratuity_rule.py | 14 ++++++-- .../gratuity_rule_slab.json | 35 +++++++++++-------- 3 files changed, 65 insertions(+), 17 deletions(-) diff --git a/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.js b/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.js index 929370fb17..feaf6a8e18 100644 --- a/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.js +++ b/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.js @@ -6,3 +6,36 @@ frappe.ui.form.on('Gratuity Rule', { // } }); + +frappe.ui.form.on('Gratuity Rule Slab', { + + /* + Slabs should be in order like + + from | to | fraction + 0 | 4 | 0.5 + 4 | 6 | 0.7 + + So, on row addition setting current_row.from = previous row.to. + On to_year insert we have to check that it is not less than from_year + + */ + + + gratuity_rule_slabs_add(frm, cdt, cdn) { + let row = locals[cdt][cdn]; + let array_idx = row.idx - 1 + if(array_idx > 0){ + row.from_year = cur_frm.doc.gratuity_rule_slabs[array_idx-1].to_year; + frm.refresh(); + } + }, + + to_year(frm, cdt, cdn) { + let row = locals[cdt][cdn]; + if (row.to_year <= row.from_year){ + frappe.throw(__("To(Year) year can not be less than From(year) ")); + } + } +}); + diff --git a/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.py b/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.py index 10b2a87b97..71adbe5b31 100644 --- a/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.py +++ b/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.py @@ -3,8 +3,18 @@ # For license information, please see license.txt from __future__ import unicode_literals -# import frappe +import frappe from frappe.model.document import Document +from frappe import _ class GratuityRule(Document): - pass + + def validate(self): + for current_slab in self.gratuity_rule_slabs: + if current_slab.from_year > current_slab.to_year: + frappe(_("Row {0}: From (Year) can not be greater than To (Year)").format(slab.idx)) + + if current_slab.to_year == 0 and current_slab.from_year == 0 and len(self.gratuity_rule_slabs) > 1: + frappe.throw(_("You can not define multiple slabs if you have a slab with no lower and upper limits.")) + + diff --git a/erpnext/payroll/doctype/gratuity_rule_slab/gratuity_rule_slab.json b/erpnext/payroll/doctype/gratuity_rule_slab/gratuity_rule_slab.json index 615829f45a..dd642f4cd0 100644 --- a/erpnext/payroll/doctype/gratuity_rule_slab/gratuity_rule_slab.json +++ b/erpnext/payroll/doctype/gratuity_rule_slab/gratuity_rule_slab.json @@ -5,34 +5,39 @@ "editable_grid": 1, "engine": "InnoDB", "field_order": [ - "from", - "to", + "from_year", + "to_year", "fraction_of_applicable_earnings" ], "fields": [ - { - "fieldname": "from", - "fieldtype": "Int", - "in_list_view": 1, - "label": "From(Year)" - }, - { - "fieldname": "to", - "fieldtype": "Int", - "in_list_view": 1, - "label": "To(Year)" - }, { "fieldname": "fraction_of_applicable_earnings", "fieldtype": "Float", "in_list_view": 1, "label": "Fraction of Applicable Earnings ", "reqd": 1 + }, + { + "default": "0", + "fieldname": "from_year", + "fieldtype": "Int", + "in_list_view": 1, + "label": "From(Year)", + "read_only": 1, + "reqd": 1 + }, + { + "default": "0", + "fieldname": "to_year", + "fieldtype": "Int", + "in_list_view": 1, + "label": "To(Year)", + "reqd": 1 } ], "istable": 1, "links": [], - "modified": "2020-08-05 20:03:25.955448", + "modified": "2020-08-14 15:23:12.041375", "modified_by": "Administrator", "module": "Payroll", "name": "Gratuity Rule Slab",