From a8f6938556c764d8c26c284e7e46709bcac15782 Mon Sep 17 00:00:00 2001 From: Mitchy25 <42224026+Mitchy25@users.noreply.github.com> Date: Mon, 27 May 2019 20:27:56 +1200 Subject: [PATCH] Fix: Precision in Appraisals (#17673) * Update appraisal.js This fixes issues associated with 2 decimal places. Example: 4 questions (Each weighted 25%), will give a total result of 5.2 (If 5 achieved on every question). This is because 5*0.25 = 1.25 which is rounded to 1.3 for precision=2. When precision = 3, this is not an issue. * fix: score based on field's precisin --- erpnext/hr/doctype/appraisal/appraisal.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/erpnext/hr/doctype/appraisal/appraisal.js b/erpnext/hr/doctype/appraisal/appraisal.js index a71486af63..02f1557c4e 100644 --- a/erpnext/hr/doctype/appraisal/appraisal.js +++ b/erpnext/hr/doctype/appraisal/appraisal.js @@ -9,12 +9,14 @@ frappe.ui.form.on('Appraisal', { return{ query: "erpnext.controllers.queries.employee_query" } }; }, - onload: function(frm) { + + onload: function(frm) { if(!frm.doc.status) { frm.set_value('status', 'Draft'); } }, - kra_template: function(frm) { + + kra_template: function(frm) { frm.doc.goals = []; erpnext.utils.map_current_doc({ method: "erpnext.hr.doctype.appraisal.appraisal.fetch_appraisal_template", @@ -22,7 +24,8 @@ frappe.ui.form.on('Appraisal', { frm: frm }); }, - calculate_total: function(frm) { + + calculate_total: function(frm) { let goals = frm.doc.goals || []; let total =0; for(let i = 0; i 5) { frappe.msgprint(__("Score must be less than or equal to 5")); d.score = 0; refresh_field('score', d.name, 'goals'); } - var total = flt(d.per_weightage*d.score)/100; - d.score_earned = total.toPrecision(2); - refresh_field('score_earned', d.name, 'goals'); - } - else{ + d.score_earned = flt(d.per_weightage*d.score, precision("score_earned", d))/100; + } else { d.score_earned = 0; - refresh_field('score_earned', d.name, 'goals'); } - frm.trigger('calculate_total'); + refresh_field('score_earned', d.name, 'goals'); + frm.trigger('calculate_total'); } }); \ No newline at end of file