Skip to content

Commit

Permalink
Merge pull request #1169 from frappe/mergify/bp/version-14-hotfix/pr-…
Browse files Browse the repository at this point in the history
…1113

feat: add Amount Based on Formula to list view & fix UX (backport #1113)
  • Loading branch information
ruchamahabal authored Dec 12, 2023
2 parents a9d2fe0 + 4b9120e commit dfeaf91
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
5 changes: 3 additions & 2 deletions hrms/payroll/doctype/salary_detail/salary_detail.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
],
"fields": [
{
"columns": 2,
"fieldname": "salary_component",
"fieldtype": "Link",
"in_list_view": 1,
Expand Down Expand Up @@ -64,7 +65,6 @@
"fetch_from": "salary_component.statistical_component",
"fieldname": "statistical_component",
"fieldtype": "Check",
"in_list_view": 1,
"label": "Statistical Component"
},
{
Expand Down Expand Up @@ -135,6 +135,7 @@
"depends_on": "eval:doc.parenttype=='Salary Structure'",
"fieldname": "amount_based_on_formula",
"fieldtype": "Check",
"in_list_view": 1,
"label": "Amount based on formula"
},
{
Expand Down Expand Up @@ -250,7 +251,7 @@
],
"istable": 1,
"links": [],
"modified": "2023-01-17 13:04:44.167515",
"modified": "2023-12-12 13:52:30.726505",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Salary Detail",
Expand Down
33 changes: 19 additions & 14 deletions hrms/payroll/doctype/salary_structure/salary_structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@
// License: GNU General Public License v3. See license.txt
{% include "erpnext/public/js/controllers/accounts.js" %}

cur_frm.add_fetch('company', 'default_letter_head', 'letter_head');


cur_frm.cscript.onload = function(doc, dt, dn){
var e_tbl = doc.earnings || [];
var d_tbl = doc.deductions || [];
if (e_tbl.length == 0 && d_tbl.length == 0)
return function(r, rt) { refresh_many(['earnings', 'deductions']);};
}

frappe.ui.form.on('Salary Structure', {
frappe.ui.form.on("Salary Structure", {
onload: function(frm) {
frm.alerted_rows = []

let help_button = $(`<a class = 'control-label'>
${__("Condition and Formula Help")}
Expand Down Expand Up @@ -305,6 +296,19 @@ frappe.ui.form.on('Salary Detail', {
calculate_totals(frm.doc);
},

formula: function(frm, cdt, cdn) {
const row = locals[cdt][cdn];
if (row.formula && !row?.amount_based_on_formula && !frm.alerted_rows.includes(cdn)) {
frappe.msgprint({
message: __("{0} Row #{1}: {2} needs to be enabled for the formula to be considered.",
[toTitle(row.parentfield), row.idx, __("Amount based on formula").bold()]),
title: __("Warning"),
indicator: "orange",
});
frm.alerted_rows.push(cdn)
}
},

salary_component: function(frm, cdt, cdn) {
var child = locals[cdt][cdn];
if(child.salary_component){
Expand Down Expand Up @@ -341,10 +345,11 @@ frappe.ui.form.on('Salary Detail', {

amount_based_on_formula: function(frm, cdt, cdn) {
var child = locals[cdt][cdn];
if(child.amount_based_on_formula == 1){
if (child.amount_based_on_formula == 1) {
frappe.model.set_value(cdt, cdn, 'amount', null);
}
else{
const index = frm.alerted_rows.indexOf(cdn);
if (index > -1) frm.alerted_rows.splice(index, 1);
} else {
frappe.model.set_value(cdt, cdn, 'formula', null);
}
}
Expand Down
3 changes: 2 additions & 1 deletion hrms/payroll/doctype/salary_structure/salary_structure.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"reqd": 1
},
{
"fetch_from": "company.default_letter_head",
"fieldname": "letter_head",
"fieldtype": "Link",
"label": "Letter Head",
Expand Down Expand Up @@ -235,7 +236,7 @@
"idx": 1,
"is_submittable": 1,
"links": [],
"modified": "2023-06-13 18:02:31.779947",
"modified": "2023-12-12 14:11:22.774017",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Salary Structure",
Expand Down
16 changes: 16 additions & 0 deletions hrms/payroll/doctype/salary_structure/salary_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ def validate(self):
self.validate_component_based_on_tax_slab()
self.validate_payment_days_based_dependent_component()
self.validate_timesheet_component()
self.validate_formula_setup()

def validate_formula_setup(self):
for table in ["earnings", "deductions"]:
for row in self.get(table):
if not row.amount_based_on_formula and row.formula:
frappe.msgprint(
_("{0} Row #{1}: Formula is set but {2} is disabled for the Salary Component {3}.").format(
table.capitalize(),
row.idx,
frappe.bold(_("Amount Based on Formula")),
frappe.bold(row.salary_component),
),
title=_("Warning"),
indicator="orange",
)

def set_missing_values(self):
overwritten_fields = [
Expand Down

0 comments on commit dfeaf91

Please sign in to comment.