Skip to content

Commit

Permalink
Merge pull request #2405 from frappe/version-15-hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal authored Nov 8, 2024
2 parents a2c04b0 + afdac17 commit 12a70c4
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 23 deletions.
16 changes: 8 additions & 8 deletions frontend/src/components/AttendanceCalendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<div v-for="index in firstOfMonth.endOf('M').get('D')">
<div
class="h-8 w-8 flex rounded-full mx-auto"
:class="getEventOnDate(index) && `bg-${colorMap[getEventOnDate(index)]}`"
:class="getEventOnDate(index) && colorMap[getEventOnDate(index)]"
>
<span class="text-gray-800 text-sm font-medium m-auto">
{{ index }}
Expand All @@ -47,7 +47,7 @@
<div class="grid grid-cols-4 mx-2">
<div v-for="status in summaryStatuses" class="flex flex-col gap-1">
<div class="flex flex-row gap-1 items-center">
<span class="rounded full h-3 w-3" :class="`bg-${colorMap[status]}`" />
<span class="rounded full h-3 w-3" :class="colorMap[status]" />
<span class="text-gray-600 text-sm font-medium leading-5"> {{ __(status) }} </span>
</div>
<span class="text-gray-800 text-base font-semibold leading-6 mx-auto">
Expand All @@ -69,12 +69,12 @@ const __ = inject("$translate")
const firstOfMonth = ref(dayjs().date(1).startOf("D"))
const colorMap = {
Present: "green-200",
"Work From Home": "green-200",
"Half Day": "yellow-100",
Absent: "red-100",
"On Leave": "blue-100",
Holiday: "gray-100",
Present: "bg-green-300",
"Work From Home": "bg-green-300",
"Half Day": "bg-yellow-200",
Absent: "bg-red-200",
"On Leave": "bg-blue-300",
Holiday: "bg-gray-300",
}
// __("Present"), __("Half Day"), __("Absent"), __("On Leave"), __("Work From Home")
Expand Down
5 changes: 5 additions & 0 deletions hrms/api/roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from hrms.hr.doctype.shift_assignment_tool.shift_assignment_tool import create_shift_assignment


@frappe.whitelist()
def get_default_company() -> str:
return frappe.defaults.get_user_default("Company")


@frappe.whitelist()
def get_values(doctype: str, name: str, fields: list) -> dict[str, str]:
return frappe.db.get_value(doctype, name, fields, as_dict=True)
Expand Down
1 change: 1 addition & 0 deletions hrms/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@
#
# auto_cancel_exempted_doctypes = ["Auto Repeat"]

ignore_links_on_delete = ["PWA Notification"]

# User Data Protection
# --------------------
Expand Down
34 changes: 27 additions & 7 deletions hrms/payroll/doctype/payroll_entry/payroll_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
)
from erpnext.accounts.utils import get_fiscal_year

from hrms.payroll.doctype.salary_slip.salary_slip_loan_utils import if_lending_app_installed
from hrms.payroll.doctype.salary_withholding.salary_withholding import link_bank_entry_in_salary_withholdings


Expand Down Expand Up @@ -871,9 +872,9 @@ def make_bank_entry(self, for_withheld_salaries=False):
)

salary_slip_total = 0
salary_slips = self.get_salary_slip_details(for_withheld_salaries)
salary_details = self.get_salary_slip_details(for_withheld_salaries)

for salary_detail in salary_slips:
for salary_detail in salary_details:
if salary_detail.parentfield == "earnings":
(
is_flexible_benefit,
Expand Down Expand Up @@ -923,8 +924,7 @@ def make_bank_entry(self, for_withheld_salaries=False):

salary_slip_total -= salary_detail.amount

unique_salary_slips = {slip["name"]: slip for slip in salary_slips}.values()
total_loan_repayment = sum(flt(slip.get("total_loan_repayment", 0)) for slip in unique_salary_slips)
total_loan_repayment = self.process_loan_repayments_for_bank_entry(salary_details) or 0
salary_slip_total -= total_loan_repayment

bank_entry = None
Expand All @@ -933,7 +933,7 @@ def make_bank_entry(self, for_withheld_salaries=False):
bank_entry = self.set_accounting_entries_for_bank_entry(salary_slip_total, remark)

if for_withheld_salaries:
link_bank_entry_in_salary_withholdings(salary_slips, bank_entry.name)
link_bank_entry_in_salary_withholdings(salary_details, bank_entry.name)

return bank_entry

Expand Down Expand Up @@ -971,6 +971,23 @@ def get_salary_slip_details(self, for_withheld_salaries=False):
query = query.where(SalarySlip.status != "Withheld")
return query.run(as_dict=True)

@if_lending_app_installed
def process_loan_repayments_for_bank_entry(self, salary_details: list[dict]) -> float:
unique_salary_slips = {row["employee"]: row for row in salary_details}.values()
total_loan_repayment = sum(flt(slip.get("total_loan_repayment", 0)) for slip in unique_salary_slips)

if self.employee_based_payroll_payable_entries:
for salary_slip in unique_salary_slips:
if salary_slip.get("total_loan_repayment"):
self.set_employee_based_payroll_payable_entries(
"total_loan_repayment",
salary_slip.employee,
salary_slip.total_loan_repayment,
salary_slip.salary_structure,
)

return total_loan_repayment

def set_accounting_entries_for_bank_entry(self, je_payment_amount, user_remark):
payroll_payable_account = self.payroll_payable_account
precision = frappe.get_precision("Journal Entry Account", "debit_in_account_currency")
Expand Down Expand Up @@ -998,9 +1015,12 @@ def set_accounting_entries_for_bank_entry(self, je_payment_amount, user_remark):

if self.employee_based_payroll_payable_entries:
for employee, employee_details in self.employee_based_payroll_payable_entries.items():
je_payment_amount = employee_details.get("earnings", 0) - (
employee_details.get("deductions", 0)
je_payment_amount = (
employee_details.get("earnings", 0)
- employee_details.get("deductions", 0)
- employee_details.get("total_loan_repayment", 0)
)

exchange_rate, amount = self.get_amount_and_exchange_rate_for_journal_entry(
self.payment_account, je_payment_amount, company_currency, currencies
)
Expand Down
9 changes: 9 additions & 0 deletions hrms/payroll/doctype/payroll_entry/test_payroll_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class TestPayrollEntry(FrappeTestCase):
def setUp(self):
for dt in [
"Salary Slip",
"Salary Detail",
"Salary Component",
"Salary Component Account",
"Payroll Entry",
Expand Down Expand Up @@ -720,6 +721,14 @@ def test_validate_attendance(self):
@if_lending_app_installed
@change_settings("Payroll Settings", {"process_payroll_accounting_entry_based_on_employee": 0})
def test_loan_repayment_from_salary(self):
self.run_test_for_loan_repayment_from_salary()

@if_lending_app_installed
@change_settings("Payroll Settings", {"process_payroll_accounting_entry_based_on_employee": 1})
def test_loan_repayment_from_salary_with_employee_tagging(self):
self.run_test_for_loan_repayment_from_salary()

def run_test_for_loan_repayment_from_salary(self):
from lending.loan_management.doctype.loan.test_loan import make_loan_disbursement_entry
from lending.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import (
process_loan_interest_accrual_for_term_loans,
Expand Down
22 changes: 15 additions & 7 deletions roster/src/components/MonthViewHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

<script setup lang="ts">
import { ref, reactive, watch } from "vue";
import { FormControl, createListResource } from "frappe-ui";
import { FormControl, createResource, createListResource } from "frappe-ui";
import { Dayjs } from "dayjs";
import { raiseToast } from "../utils";
Expand Down Expand Up @@ -72,7 +72,7 @@ const filters: {
watch(
() => filters.company.model,
(val) => {
if (val?.value) return getFilterOptions("department", { company: val.value });
if (val?.value) getFilterOptions("department", { company: val.value });
else {
filters.department.model = null;
filters.department.options = [];
Expand All @@ -99,23 +99,31 @@ const toTitleCase = (str: string) =>
// RESOURCES
const defaultCompany = createResource({
url: "hrms.api.roster.get_default_company",
auto: true,
onSuccess: () => {
["company", "branch", "designation", "shift_type"].forEach((field) =>
getFilterOptions(field as FilterField),
);
},
});
const getFilterOptions = (field: FilterField, listFilters: { company?: string } = {}) => {
createListResource({
doctype: toTitleCase(field),
fields: ["name"],
filters: listFilters,
pageLength: 100,
auto: true,
onSuccess: (data: { name: string }[]) => {
filters[field].model = { value: "" };
const value = field === "company" ? defaultCompany.data : "";
filters[field].model = { value };
filters[field].options = data.map((item) => item.name);
},
onError(error: { messages: string[] }) {
raiseToast("error", error.messages[0]);
},
});
};
["company", "branch", "designation", "shift_type"].forEach((field) =>
getFilterOptions(field as FilterField),
);
</script>
7 changes: 6 additions & 1 deletion roster/src/views/MonthView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
@addToMonth="addToMonth"
/>
<MonthViewTable
v-if="isCompanySelected"
ref="monthViewTable"
:firstOfMonth="firstOfMonth"
:employees="employees.data || []"
:employeeFilters="employeeFilters"
:shiftTypeFilter="shiftTypeFilter"
/>
<div v-else class="my-40 text-center">Please select a company.</div>
</div>
</div>
<ShiftAssignmentDialog
Expand Down Expand Up @@ -61,6 +63,7 @@ export type EmployeeFilters = {
};
const monthViewTable = ref<InstanceType<typeof MonthViewTable>>();
const isCompanySelected = ref(false);
const showShiftAssignmentDialog = ref(false);
const firstOfMonth = ref(dayjs().date(1).startOf("D"));
const shiftTypeFilter = ref("");
Expand All @@ -73,6 +76,8 @@ const addToMonth = (change: number) => {
};
const updateFilters = (newFilters: EmployeeFilters & { shift_type: string }) => {
isCompanySelected.value = !!newFilters.company;
if (!isCompanySelected.value) return;
let employeeUpdated = false;
(Object.entries(newFilters) as [keyof EmployeeFilters | "shift_type", string][]).forEach(
([key, value]) => {
Expand All @@ -95,7 +100,7 @@ const employees = createListResource({
doctype: "Employee",
fields: ["name", "employee_name", "designation", "image"],
filters: employeeFilters,
auto: true,
pageLength: 99999,
onError(error: { messages: string[] }) {
raiseToast("error", error.messages[0]);
},
Expand Down

0 comments on commit 12a70c4

Please sign in to comment.