Skip to content

Commit

Permalink
Merge pull request #2638 from frappe/version-15-hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal authored Jan 14, 2025
2 parents f1a1321 + eb7c313 commit 9002c7f
Show file tree
Hide file tree
Showing 19 changed files with 192 additions and 66 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/CheckInPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
</div>
</template>

<Button variant="solid" class="w-full py-5 text-sm" @click="submitLog(nextAction.action)">
<Button variant="solid" class="w-full py-5 text-sm" @click.once="submitLog(nextAction.action)">
{{ __("Confirm {0}", [nextAction.label]) }}
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

import datetime

import frappe
from frappe import _
Expand Down Expand Up @@ -78,7 +79,7 @@ def on_submit(self):
comp_leave_valid_from = add_days(self.work_end_date, 1)
leave_period = get_leave_period(comp_leave_valid_from, comp_leave_valid_from, company)
if leave_period:
leave_allocation = self.get_existing_allocation_for_period(leave_period)
leave_allocation = self.get_existing_allocation(comp_leave_valid_from)
if leave_allocation:
leave_allocation.new_leaves_allocated += date_difference
leave_allocation.validate()
Expand Down Expand Up @@ -122,30 +123,21 @@ def on_cancel(self):
leave_allocation, date_difference * -1, add_days(self.work_end_date, 1)
)

def get_existing_allocation_for_period(self, leave_period):
leave_allocation = frappe.db.sql(
"""
select name
from `tabLeave Allocation`
where employee=%(employee)s and leave_type=%(leave_type)s
and docstatus=1
and (from_date between %(from_date)s and %(to_date)s
or to_date between %(from_date)s and %(to_date)s
or (from_date < %(from_date)s and to_date > %(to_date)s))
""",
{
"from_date": leave_period[0].from_date,
"to_date": leave_period[0].to_date,
def get_existing_allocation(self, comp_leave_valid_from: datetime.date) -> dict | None:
leave_allocation = frappe.db.get_all(
"Leave Allocation",
filters={
"employee": self.employee,
"leave_type": self.leave_type,
"from_date": ("<=", comp_leave_valid_from),
"to_date": (">=", comp_leave_valid_from),
"docstatus": 1,
},
as_dict=1,
limit=1,
)

if leave_allocation:
return frappe.get_doc("Leave Allocation", leave_allocation[0].name)
else:
return False

def create_leave_allocation(self, leave_period, date_difference):
is_carry_forward = frappe.db.get_value("Leave Type", self.leave_type, "is_carry_forward")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_days, add_months, today
from frappe.utils import add_days, add_months, getdate, today

from hrms.hr.doctype.attendance_request.test_attendance_request import get_employee
from hrms.hr.doctype.leave_allocation.test_leave_allocation import create_leave_allocation
from hrms.hr.doctype.leave_application.leave_application import get_leave_balance_on
from hrms.hr.doctype.leave_period.test_leave_period import create_leave_period
from hrms.tests.test_utils import add_date_to_holiday_list

test_dependencies = ["Employee"]


class TestCompensatoryLeaveRequest(FrappeTestCase):
def setUp(self):
Expand Down Expand Up @@ -42,7 +41,7 @@ def test_leave_balance_on_submit(self):
before + 1,
)

def test_leave_allocation_update_on_submit(self):
def test_allocation_update_on_submit(self):
employee = get_employee()
mark_attendance(employee, date=add_days(today(), -1))
compensatory_leave_request = get_compensatory_leave_request(
Expand Down Expand Up @@ -70,6 +69,54 @@ def test_leave_allocation_update_on_submit(self):
)
self.assertEqual(leaves_allocated, 2)

def test_allocation_update_on_submit_on_multiple_allocations(self):
"""Tests whether the correct allocation is updated when there are multiple allocations in the same leave period"""
employee = get_employee()
today = getdate()

first_alloc_start = add_months(today, -3)
first_alloc_end = add_days(today, -1)
second_alloc_start = today
second_alloc_end = add_months(today, 1)

add_date_to_holiday_list(first_alloc_start, employee.holiday_list)
allocation_1 = create_leave_allocation(
leave_type="Compensatory Off",
employee=employee.name,
from_date=first_alloc_start,
to_date=first_alloc_end,
)
allocation_1.new_leaves_allocated = 0
allocation_1.submit()

add_date_to_holiday_list(second_alloc_start, employee.holiday_list)
allocation_2 = create_leave_allocation(
leave_type="Compensatory Off",
employee=employee.name,
from_date=second_alloc_start,
to_date=second_alloc_end,
)
allocation_2.new_leaves_allocated = 0
allocation_2.submit()

# adds leave balance in first allocation
mark_attendance(employee, date=first_alloc_start)
compensatory_leave_request = get_compensatory_leave_request(
employee.name, leave_date=first_alloc_start
)
compensatory_leave_request.submit()
allocation_1.reload()
self.assertEqual(allocation_1.total_leaves_allocated, 1)

# adds leave balance in second allocation
mark_attendance(employee, date=second_alloc_start)
compensatory_leave_request = get_compensatory_leave_request(
employee.name, leave_date=second_alloc_start
)
compensatory_leave_request.submit()
allocation_2.reload()
self.assertEqual(allocation_2.total_leaves_allocated, 1)

def test_creation_of_leave_ledger_entry_on_submit(self):
"""check creation of leave ledger entry on submission of leave request"""
employee = get_employee()
Expand Down
8 changes: 8 additions & 0 deletions hrms/hr/doctype/expense_claim/expense_claim.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ frappe.ui.form.on("Expense Claim", {
query: "erpnext.controllers.queries.employee_query",
};
});

frm.set_query("department", function () {
return {
filters: {
company: frm.doc.company,
},
};
});
},

onload: function (frm) {
Expand Down
14 changes: 14 additions & 0 deletions hrms/hr/doctype/expense_claim/expense_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class ExpenseApproverIdentityError(frappe.ValidationError):
pass


class MismatchError(frappe.ValidationError):
pass


class ExpenseClaim(AccountsController, PWANotificationsMixin):
def onload(self):
self.get("__onload").make_payment_via_journal_entry = frappe.db.get_single_value(
Expand All @@ -47,6 +51,7 @@ def validate(self):
self.set_expense_account(validate=True)
self.calculate_taxes()
self.set_status()
self.validate_company_and_department()
if self.task and not self.project:
self.project = frappe.db.get_value("Task", self.task, "project")

Expand Down Expand Up @@ -83,6 +88,15 @@ def set_status(self, update=False):
else:
self.status = status

def validate_company_and_department(self):
if self.department:
company = frappe.db.get_value("Department", self.department, "company")
if company and self.company != company:
frappe.throw(
_("Department {0} does not belong to company: {1}").format(self.department, self.company),
exc=MismatchError,
)

def on_update(self):
share_doc_with_approver(self, self.expense_approver)
self.publish_update()
Expand Down
8 changes: 8 additions & 0 deletions hrms/hr/doctype/expense_claim/test_expense_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from erpnext.setup.doctype.employee.test_employee import make_employee

from hrms.hr.doctype.expense_claim.expense_claim import (
MismatchError,
get_outstanding_amount_for_claim,
make_bank_entry,
make_expense_claim_for_delivery_trip,
Expand Down Expand Up @@ -568,6 +569,13 @@ def test_repost(self):
)
self.assertEqual(ledger_balance, expected_data)

def test_company_department_validation(self):
# validate company and department
expense_claim = frappe.new_doc("Expense Claim")
expense_claim.company = "_Test Company 3"
expense_claim.department = "Accounts - _TC2"
self.assertRaises(MismatchError, expense_claim.save)


def get_payable_account(company):
return frappe.get_cached_value("Company", company, "default_payable_account")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ frappe.ui.form.on("Full and Final Statement", {
filters["is_group"] = 0;
}

if (frappe.model.is_submittable(fnf_doc.reference_document_type)) {
filters["docstatus"] = ["!=", 2];
}

if (frappe.meta.has_field(fnf_doc.reference_document_type, "company")) {
filters["company"] = frm.doc.company;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def create_journal_entry(self):
"debit_in_account_currency": flt(data.amount, precision),
"user_remark": data.remark,
}
if data.reference_document_type == "Expense Claim":
if data.reference_document_type in ["Expense Claim", "Gratuity"]:
account_dict["party_type"] = "Employee"
account_dict["party"] = self.employee

Expand Down Expand Up @@ -248,6 +248,15 @@ def create_journal_entry(self):
)
return jv

def set_gratuity_status(self):
for payable in self.payables:
if payable.component != "Gratuity":
continue
gratuity = frappe.get_doc("Gratuity", payable.reference_document)
amount = payable.amount if self.docstatus == 1 and self.status == "Paid" else 0
gratuity.db_set("paid_amount", amount)
gratuity.set_status(update=True)


@frappe.whitelist()
def get_account_and_amount(ref_doctype, ref_document):
Expand Down Expand Up @@ -310,3 +319,4 @@ def update_full_and_final_statement_status(doc, method=None):
fnf = frappe.get_doc("Full and Final Statement", entry.reference_name)
fnf.db_set("status", status)
fnf.notify_update()
fnf.set_gratuity_status()
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_check_bootstraped_data_asset_movement_and_jv_creation(self):
"Leave Encashment",
]

receivable_bootstraped_component = ["Employee Advance", "Loan"]
receivable_bootstraped_component = self.fnf.get_receivable_component()

# checking payables and receivables bootstraped value
self.assertEqual([payable.component for payable in self.fnf.payables], payables_bootstraped_component)
Expand Down
5 changes: 2 additions & 3 deletions hrms/hr/doctype/leave_control_panel/leave_control_panel.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
"idx": 1,
"issingle": 1,
"links": [],
"modified": "2024-03-20 15:05:39.635388",
"modified": "2025-01-13 13:47:55.262534",
"modified_by": "Administrator",
"module": "HR",
"name": "Leave Control Panel",
Expand All @@ -199,8 +199,7 @@
"write": 1
}
],
"read_only": 1,
"sort_field": "modified",
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
4 changes: 3 additions & 1 deletion hrms/hr/doctype/leave_encashment/leave_encashment.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ def create_leave_ledger_entry(self, submit=True):
return

to_date = leave_allocation.get("to_date")
if to_date < getdate():

can_expire = not frappe.db.get_value("Leave Type", self.leave_type, "is_carry_forward")
if to_date < getdate() and can_expire:
args = frappe._dict(
leaves=self.encashment_days, from_date=to_date, to_date=to_date, is_carry_forward=0
)
Expand Down
17 changes: 15 additions & 2 deletions hrms/hr/doctype/leave_ledger_entry/leave_ledger_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import DATE_FORMAT, flt, get_link_to_form, getdate, today
from frappe.utils import DATE_FORMAT, flt, formatdate, get_link_to_form, getdate, today


class InvalidLeaveLedgerEntry(frappe.ValidationError):
pass


class LeaveLedgerEntry(Document):
def validate(self):
if getdate(self.from_date) > getdate(self.to_date):
frappe.throw(_("To date needs to be before from date"))
frappe.throw(
_(
"Leave Ledger Entry's To date needs to be after From date. Currently, From Date is {0} and To Date is {1}"
).format(
frappe.bold(formatdate(self.from_date)),
frappe.bold(formatdate(self.to_date)),
),
exc=InvalidLeaveLedgerEntry,
title=_("Invalid Leave Ledger Entry"),
)

def on_cancel(self):
# allow cancellation of expiry leaves
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
"hide_toolbar": 1,
"issingle": 1,
"links": [],
"modified": "2024-12-13 17:38:45.675004",
"modified": "2025-01-13 13:48:33.710186",
"modified_by": "Administrator",
"module": "HR",
"name": "Shift Assignment Tool",
Expand All @@ -225,7 +225,6 @@
"write": 1
}
],
"read_only": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
"hide_toolbar": 1,
"issingle": 1,
"links": [],
"modified": "2024-07-09 19:33:40.135057",
"modified": "2025-01-13 13:48:46.095481",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Bulk Salary Structure Assignment",
Expand All @@ -163,8 +163,7 @@
"write": 1
}
],
"read_only": 1,
"sort_field": "modified",
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
2 changes: 1 addition & 1 deletion hrms/payroll/doctype/gratuity/gratuity.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def set_status(self, update=False):
else:
status = "Unpaid"

if update:
if update and self.status != status:
self.db_set("status", status)
else:
self.status = status
Expand Down
Loading

0 comments on commit 9002c7f

Please sign in to comment.