mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-13 20:05:09 +00:00
test: statistical component based on payment days
This commit is contained in:
@@ -1105,7 +1105,7 @@ def allocate_leaves(employee, leave_period, leave_type, new_leaves_allocated, el
|
||||
allocate_leave.submit()
|
||||
|
||||
|
||||
def get_first_sunday(holiday_list, for_date=None):
|
||||
def get_first_sunday(holiday_list="Salary Slip Test Holiday List", for_date=None):
|
||||
date = for_date or getdate()
|
||||
month_start_date = get_first_day(date)
|
||||
month_end_date = get_last_day(date)
|
||||
|
||||
@@ -1032,6 +1032,43 @@ class TestSalarySlip(FrappeTestCase):
|
||||
components = [row.salary_component for row in new_ss.get("earnings")]
|
||||
self.assertNotIn("Statistical Component", components)
|
||||
|
||||
@change_settings(
|
||||
"Payroll Settings",
|
||||
{"payroll_based_on": "Attendance", "consider_unmarked_attendance_as": "Present"},
|
||||
)
|
||||
def test_statistical_component_based_on_payment_days(self):
|
||||
"""
|
||||
Tests whether component using statistical component in the formula
|
||||
gets the updated value based on payment days
|
||||
"""
|
||||
from erpnext.hr.doctype.leave_application.test_leave_application import get_first_sunday
|
||||
from erpnext.payroll.doctype.salary_structure.test_salary_structure import (
|
||||
create_salary_structure_assignment,
|
||||
)
|
||||
|
||||
emp = make_employee("test_statistical_component@salary.com")
|
||||
first_sunday = get_first_sunday()
|
||||
mark_attendance(emp, add_days(first_sunday, 1), "Absent", ignore_validate=True)
|
||||
salary_structure = make_salary_structure_for_payment_days_based_component_dependency(
|
||||
test_statistical_comp=True
|
||||
)
|
||||
create_salary_structure_assignment(
|
||||
emp, salary_structure.name, company="_Test Company", currency="INR"
|
||||
)
|
||||
# make salary slip and assert payment days
|
||||
ss = make_salary_slip_for_payment_days_dependency_test(
|
||||
"test_statistical_component@salary.com", salary_structure.name
|
||||
)
|
||||
|
||||
amount = precision = None
|
||||
for entry in ss.earnings:
|
||||
if entry.salary_component == "Dependency Component":
|
||||
amount = entry.amount
|
||||
precision = entry.precision("amount")
|
||||
break
|
||||
|
||||
self.assertEqual(amount, flt((1000 * ss.payment_days / ss.total_working_days) * 0.5, precision))
|
||||
|
||||
def make_activity_for_employee(self):
|
||||
activity_type = frappe.get_doc("Activity Type", "_Test Activity Type")
|
||||
activity_type.billing_rate = 50
|
||||
@@ -1151,7 +1188,11 @@ def create_account(account_name, company, parent_account, account_type=None):
|
||||
|
||||
|
||||
def make_earning_salary_component(
|
||||
setup=False, test_tax=False, company_list=None, include_flexi_benefits=False
|
||||
setup=False,
|
||||
test_tax=False,
|
||||
company_list=None,
|
||||
include_flexi_benefits=False,
|
||||
test_statistical_comp=False,
|
||||
):
|
||||
data = [
|
||||
{
|
||||
@@ -1517,7 +1558,7 @@ def make_holiday_list(list_name=None, from_date=None, to_date=None):
|
||||
return holiday_list
|
||||
|
||||
|
||||
def make_salary_structure_for_payment_days_based_component_dependency():
|
||||
def make_salary_structure_for_payment_days_based_component_dependency(test_statistical_comp=False):
|
||||
earnings = [
|
||||
{
|
||||
"salary_component": "Basic Salary - Payment Days",
|
||||
@@ -1535,6 +1576,27 @@ def make_salary_structure_for_payment_days_based_component_dependency():
|
||||
"formula": "base * 0.20",
|
||||
},
|
||||
]
|
||||
if test_statistical_comp:
|
||||
earnings.extend(
|
||||
[
|
||||
{
|
||||
"salary_component": "Statistical Component",
|
||||
"abbr": "SC",
|
||||
"type": "Earning",
|
||||
"statistical_component": 1,
|
||||
"amount": 1000,
|
||||
"depends_on_payment_days": 1,
|
||||
},
|
||||
{
|
||||
"salary_component": "Dependency Component",
|
||||
"abbr": "DC",
|
||||
"type": "Earning",
|
||||
"amount_based_on_formula": 1,
|
||||
"formula": "SC * 0.5",
|
||||
"depends_on_payment_days": 0,
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
make_salary_component(earnings, False, company_list=["_Test Company"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user