Skip to content

Commit

Permalink
Merge pull request #2159 from frappe/version-15-hotfix
Browse files Browse the repository at this point in the history
chore: release v15
  • Loading branch information
ruchamahabal authored Sep 4, 2024
2 parents f79cfec + 3598ae9 commit b84909e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
1 change: 1 addition & 0 deletions hrms/hr/doctype/employee_checkin/employee_checkin.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ frappe.ui.form.on("Employee Checkin", {
frm.set_value("longitude", position.coords.longitude);

await frm.call("set_geolocation_from_coordinates");
frm.dirty();
frappe.dom.unfreeze();
},
(error) => {
Expand Down
13 changes: 7 additions & 6 deletions hrms/payroll/doctype/salary_slip/salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,12 +813,11 @@ def is_var_updated(var: str | list[str]) -> bool:
other_component_type = "deductions" if component_type == "earnings" else "earnings"

for d in self._salary_structure_doc.get(component_type):
if not d.amount_based_on_formula:
continue
for var in get_variables_from_formula(d.formula):
if is_var_updated(var):
self.add_structure_component(d, component_type)
self.update_dependent_components_recursively(other_component_type, d.abbr)
if d.amount_based_on_formula and d.formula:
for var in get_variables_from_formula(d.formula):
if is_var_updated(var):
self.add_structure_component(d, component_type)
self.update_dependent_components_recursively(other_component_type, d.abbr)

def set_net_pay(self):
self.total_deduction = self.get_component_totals("deductions")
Expand Down Expand Up @@ -2350,4 +2349,6 @@ def email_salary_slips(names) -> None:


def get_variables_from_formula(formula: str) -> list[str]:
# compile expects a string
formula = cstr(formula)
return [node.id for node in ast.walk(ast.parse(formula, mode="eval")) if isinstance(node, ast.Name)]
34 changes: 19 additions & 15 deletions hrms/payroll/doctype/salary_slip/salary_slip_loan_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ def set_loan_repayment(doc: "SalarySlip"):
doc.total_principal_amount = 0

if not doc.get("loans", []):
for loan in _get_loan_details(doc):
amounts = calculate_amounts(loan.name, doc.posting_date, "Regular Payment")
loan_details = _get_loan_details(doc)
if loan_details:
process_loan_interest_accruals(loan_details, doc.end_date)

for loan in loan_details:
amounts = calculate_amounts(loan.name, doc.end_date, "Regular Payment")

if amounts["interest_amount"] or amounts["payable_principal_amount"]:
doc.append(
Expand All @@ -49,7 +53,7 @@ def set_loan_repayment(doc: "SalarySlip"):
doc.set("loans", [])

for payment in doc.get("loans", []):
amounts = calculate_amounts(payment.loan, doc.posting_date, "Regular Payment")
amounts = calculate_amounts(payment.loan, doc.end_date, "Regular Payment")
total_amount = amounts["interest_amount"] + amounts["payable_principal_amount"]
if payment.total_payment > total_amount:
frappe.throw(
Expand All @@ -68,11 +72,7 @@ def set_loan_repayment(doc: "SalarySlip"):
doc.total_loan_repayment += payment.total_payment


def _get_loan_details(doc: "SalarySlip"):
from lending.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import (
process_loan_interest_accrual_for_term_loans,
)

def _get_loan_details(doc: "SalarySlip") -> dict[str, str | bool]:
loan_details = frappe.get_all(
"Loan",
fields=["name", "interest_income_account", "loan_account", "loan_product", "is_term_loan"],
Expand All @@ -84,15 +84,19 @@ def _get_loan_details(doc: "SalarySlip"):
"status": ("!=", "Closed"),
},
)
return loan_details

if loan_details:
for loan in loan_details:
if loan.is_term_loan:
process_loan_interest_accrual_for_term_loans(
posting_date=doc.posting_date, loan_product=loan.loan_product, loan=loan.name
)

return loan_details
def process_loan_interest_accruals(loan_details: dict[str, str | bool], posting_date: str):
from lending.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import (
process_loan_interest_accrual_for_term_loans,
)

for loan in loan_details:
if loan.is_term_loan:
process_loan_interest_accrual_for_term_loans(
posting_date=posting_date, loan_product=loan.loan_product, loan=loan.name
)


@if_lending_app_installed
Expand Down

0 comments on commit b84909e

Please sign in to comment.