Skip to content

Commit

Permalink
Merge pull request #435 from frappe/version-14-hotfix
Browse files Browse the repository at this point in the history
Co-authored-by: Rucha Mahabal <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
fix: format currency/float as per number format in work history (backport #429) (#430)
fix(patch): run payroll entry status patch for null status only (backport #431) (#432)
fix: scroll to error message on payroll entry failure (backport #433) (#434)
  • Loading branch information
ruchamahabal and mergify[bot] authored Apr 6, 2023
2 parents 66f7fb6 + 0ef09c2 commit 512fb9a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 26 deletions.
2 changes: 1 addition & 1 deletion hrms/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "14.2.0"
__version__ = "14.2.1"
11 changes: 11 additions & 0 deletions hrms/hr/doctype/employee_transfer/test_employee_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest

import frappe
from frappe.tests.utils import change_settings
from frappe.utils import add_days, getdate

from erpnext.setup.doctype.employee.test_employee import make_employee
Expand Down Expand Up @@ -99,6 +100,16 @@ def test_employee_history(self):
self.assertEqual(data.from_date, dt[0])
self.assertEqual(data.to_date, None)

@change_settings("System Settings", {"number_format": "#.###,##"})
def test_data_formatting_in_history(self):
from hrms.hr.utils import get_formatted_value

value = get_formatted_value("12.500,00", "Float")
self.assertEqual(value, 12500.0)

value = get_formatted_value("12.500,00", "Currency")
self.assertEqual(value, 12500.0)


def create_company():
if not frappe.db.exists("Company", "Test Company"):
Expand Down
41 changes: 34 additions & 7 deletions hrms/hr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
get_first_day,
get_last_day,
get_link_to_form,
get_number_format_info,
getdate,
nowdate,
)
Expand Down Expand Up @@ -56,13 +57,11 @@ def update_employee_work_history(employee, details, date=None, cancel=False):
field = frappe.get_meta("Employee").get_field(item.fieldname)
if not field:
continue
fieldtype = field.fieldtype
new_data = item.new if not cancel else item.current
if fieldtype == "Date" and new_data:
new_data = getdate(new_data)
elif fieldtype == "Datetime" and new_data:
new_data = get_datetime(new_data)
setattr(employee, item.fieldname, new_data)

new_value = item.new if not cancel else item.current
new_value = get_formatted_value(new_value, field.fieldtype)
setattr(employee, item.fieldname, new_value)

if item.fieldname in ["department", "designation", "branch"]:
internal_work_history[item.fieldname] = item.new

Expand All @@ -78,6 +77,34 @@ def update_employee_work_history(employee, details, date=None, cancel=False):
return employee


def get_formatted_value(value, fieldtype):
"""
Since the fields in Internal Work History table are `Data` fields
format them as per relevant field types
"""
if not value:
return

if fieldtype == "Date":
value = getdate(value)
elif fieldtype == "Datetime":
value = get_datetime(value)
elif fieldtype in ["Currency", "Float"]:
# in case of currency/float, the value might be in user's prefered number format
# instead of machine readable format. Convert it into a machine readable format
number_format = frappe.db.get_default("number_format") or "#,###.##"
decimal_str, comma_str, _number_format_precision = get_number_format_info(number_format)

if comma_str == "." and decimal_str == ",":
value = value.replace(",", "#$")
value = value.replace(".", ",")
value = value.replace("#$", ".")

value = flt(value)

return value


def delete_employee_work_history(details, employee, date):
filters = {}
for d in details:
Expand Down
3 changes: 2 additions & 1 deletion hrms/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
hrms.patches.v14_0.update_performance_module_changes

[post_model_sync]
hrms.patches.post_install.set_payroll_entry_status
hrms.patches.v1_0.rearrange_employee_fields
hrms.patches.v1_0.update_allocate_on_in_leave_type
hrms.patches.v14_0.create_custom_field_for_appraisal_template
hrms.patches.v14_0.create_custom_field_for_appraisal_template
20 changes: 8 additions & 12 deletions hrms/patches/post_install/set_payroll_entry_status.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import frappe
from frappe.query_builder import Case


def execute():
PayrollEntry = frappe.qb.DocType("Payroll Entry")

(
frappe.qb.update(PayrollEntry)
.set(
"status",
Case()
.when(PayrollEntry.docstatus == 0, "Draft")
.when(PayrollEntry.docstatus == 1, "Submitted")
.else_("Cancelled"),
)
.where((PayrollEntry.status.notin(["Queued", "Failed"])))
).run()
status = (
frappe.qb.terms.Case()
.when(PayrollEntry.docstatus == 0, "Draft")
.when(PayrollEntry.docstatus == 1, "Submitted")
.else_("Cancelled")
)

(frappe.qb.update(PayrollEntry).set("status", status).where(PayrollEntry.status.isnull())).run()
6 changes: 1 addition & 5 deletions hrms/payroll/doctype/payroll_entry/payroll_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ frappe.ui.form.on('Payroll Entry', {

$("#jump_to_error").on("click", (e) => {
e.preventDefault();
frappe.utils.scroll_to(
frm.get_field("error_message").$wrapper,
true,
30
);
frm.scroll_to_field("error_message");
});
}

Expand Down

0 comments on commit 512fb9a

Please sign in to comment.