Skip to content

Commit

Permalink
Merge pull request #2456 from frappe/version-14-hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal authored Nov 26, 2024
2 parents 7775da5 + 51831cb commit 89b5752
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
2 changes: 1 addition & 1 deletion hrms/hr/doctype/employee_advance/employee_advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def validate(self):
self.set_pending_amount()

def on_cancel(self):
self.ignore_linked_doctypes = "GL Entry"
self.ignore_linked_doctypes = ("GL Entry", "Payment Ledger Entry")
self.set_status(update=True)

def set_status(self, update=False):
Expand Down
23 changes: 20 additions & 3 deletions hrms/hr/report/vehicle_expenses/vehicle_expenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ frappe.query_reports["Vehicle Expenses"] = {
options: ["Fiscal Year", "Date Range"],
default: ["Fiscal Year"],
reqd: 1,
on_change: () => {
let filter_based_on = frappe.query_report.get_filter_value("filter_based_on");

if (filter_based_on == "Fiscal Year") {
set_reqd_filter("fiscal_year", true);
set_reqd_filter("from_date", false);
set_reqd_filter("to_date", false);
}
if (filter_based_on == "Date Range") {
set_reqd_filter("fiscal_year", false);
set_reqd_filter("from_date", true);
set_reqd_filter("to_date", true);
}
},
},
{
fieldname: "fiscal_year",
Expand All @@ -17,21 +31,18 @@ frappe.query_reports["Vehicle Expenses"] = {
options: "Fiscal Year",
default: frappe.defaults.get_user_default("fiscal_year"),
depends_on: "eval: doc.filter_based_on == 'Fiscal Year'",
reqd: 1,
},
{
fieldname: "from_date",
label: __("From Date"),
fieldtype: "Date",
reqd: 1,
depends_on: "eval: doc.filter_based_on == 'Date Range'",
default: frappe.datetime.add_months(frappe.datetime.nowdate(), -12),
},
{
fieldname: "to_date",
label: __("To Date"),
fieldtype: "Date",
reqd: 1,
depends_on: "eval: doc.filter_based_on == 'Date Range'",
default: frappe.datetime.nowdate(),
},
Expand All @@ -49,3 +60,9 @@ frappe.query_reports["Vehicle Expenses"] = {
},
],
};

function set_reqd_filter(fieldname, is_reqd) {
let filter = frappe.query_report.get_filter(fieldname);
filter.df.reqd = is_reqd;
filter.refresh();
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def validate(self):
if not self.get("payroll_cost_centers"):
self.set_payroll_cost_centers()

self.validate_cost_center_distribution()
self.validate_cost_centers()

def on_update_after_submit(self):
self.validate_cost_centers()

def validate_dates(self):
joining_date, relieving_date = frappe.db.get_value(
Expand Down Expand Up @@ -146,11 +149,25 @@ def get_payroll_cost_center(self):

return payroll_cost_center

def validate_cost_center_distribution(self):
if self.get("payroll_cost_centers"):
total_percentage = sum([flt(d.percentage) for d in self.get("payroll_cost_centers", [])])
if total_percentage != 100:
frappe.throw(_("Total percentage against cost centers should be 100"))
def validate_cost_centers(self):
if not self.get("payroll_cost_centers"):
return

total_percentage = 0
for entry in self.payroll_cost_centers:
company = frappe.db.get_value("Cost Center", entry.cost_center, "company")
if company != self.company:
frappe.throw(
_("Row {0}: Cost Center {1} does not belong to Company {2}").format(
entry.idx, frappe.bold(entry.cost_center), frappe.bold(self.company)
),
title=_("Invalid Cost Center"),
)

total_percentage += flt(entry.percentage)

if total_percentage != 100:
frappe.throw(_("Total percentage against cost centers should be 100"))

@frappe.whitelist()
def earning_and_deduction_entries_does_not_exists(self):
Expand Down

0 comments on commit 89b5752

Please sign in to comment.