mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-13 02:01:21 +00:00
refactor: clean-up and commonify payroll entry test setups
This commit is contained in:
@@ -25,7 +25,6 @@ from erpnext.payroll.doctype.salary_slip.test_salary_slip import (
|
|||||||
create_account,
|
create_account,
|
||||||
make_deduction_salary_component,
|
make_deduction_salary_component,
|
||||||
make_earning_salary_component,
|
make_earning_salary_component,
|
||||||
make_employee_salary_slip,
|
|
||||||
set_salary_component_account,
|
set_salary_component_account,
|
||||||
)
|
)
|
||||||
from erpnext.payroll.doctype.salary_structure.test_salary_structure import (
|
from erpnext.payroll.doctype.salary_structure.test_salary_structure import (
|
||||||
@@ -38,10 +37,6 @@ test_dependencies = ["Holiday List"]
|
|||||||
|
|
||||||
class TestPayrollEntry(FrappeTestCase):
|
class TestPayrollEntry(FrappeTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
frappe.db.set_value(
|
|
||||||
"Company", erpnext.get_default_company(), "default_holiday_list", "_Test Holiday List"
|
|
||||||
)
|
|
||||||
|
|
||||||
for dt in [
|
for dt in [
|
||||||
"Salary Slip",
|
"Salary Slip",
|
||||||
"Salary Component",
|
"Salary Component",
|
||||||
@@ -51,76 +46,79 @@ class TestPayrollEntry(FrappeTestCase):
|
|||||||
"Salary Structure Assignment",
|
"Salary Structure Assignment",
|
||||||
"Payroll Employee Detail",
|
"Payroll Employee Detail",
|
||||||
"Additional Salary",
|
"Additional Salary",
|
||||||
|
"Loan",
|
||||||
]:
|
]:
|
||||||
frappe.db.sql("delete from `tab%s`" % dt)
|
frappe.db.delete(dt)
|
||||||
|
|
||||||
make_earning_salary_component(setup=True, company_list=["_Test Company"])
|
make_earning_salary_component(setup=True, company_list=["_Test Company"])
|
||||||
make_deduction_salary_component(setup=True, test_tax=False, company_list=["_Test Company"])
|
make_deduction_salary_component(setup=True, test_tax=False, company_list=["_Test Company"])
|
||||||
|
|
||||||
|
frappe.db.set_value("Company", "_Test Company", "default_holiday_list", "_Test Holiday List")
|
||||||
frappe.db.set_value("Payroll Settings", None, "email_salary_slip_to_employee", 0)
|
frappe.db.set_value("Payroll Settings", None, "email_salary_slip_to_employee", 0)
|
||||||
|
|
||||||
def test_payroll_entry(self): # pylint: disable=no-self-use
|
# set default payable account
|
||||||
|
default_account = frappe.db.get_value(
|
||||||
|
"Company", "_Test Company", "default_payroll_payable_account"
|
||||||
|
)
|
||||||
|
if not default_account or default_account != "_Test Payroll Payable - _TC":
|
||||||
|
create_account(
|
||||||
|
account_name="_Test Payroll Payable",
|
||||||
|
company="_Test Company",
|
||||||
|
parent_account="Current Liabilities - _TC",
|
||||||
|
account_type="Payable",
|
||||||
|
)
|
||||||
|
frappe.db.set_value(
|
||||||
|
"Company", "_Test Company", "default_payroll_payable_account", "_Test Payroll Payable - _TC"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_payroll_entry(self):
|
||||||
|
company = frappe.get_doc("Company", "_Test Company")
|
||||||
|
employee = frappe.db.get_value("Employee", {"company": "_Test Company"})
|
||||||
|
setup_salary_structure(employee, company)
|
||||||
|
|
||||||
|
dates = get_start_end_dates("Monthly", nowdate())
|
||||||
|
make_payroll_entry(
|
||||||
|
start_date=dates.start_date,
|
||||||
|
end_date=dates.end_date,
|
||||||
|
payable_account=company.default_payroll_payable_account,
|
||||||
|
currency=company.default_currency,
|
||||||
|
company=company.name,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_multi_currency_payroll_entry(self):
|
||||||
company = erpnext.get_default_company()
|
company = erpnext.get_default_company()
|
||||||
|
employee = make_employee("test_muti_currency_employee@payroll.com", company=company)
|
||||||
for data in frappe.get_all("Salary Component", fields=["name"]):
|
for data in frappe.get_all("Salary Component", fields=["name"]):
|
||||||
if not frappe.db.get_value(
|
if not frappe.db.get_value(
|
||||||
"Salary Component Account", {"parent": data.name, "company": company}, "name"
|
"Salary Component Account", {"parent": data.name, "company": company}, "name"
|
||||||
):
|
):
|
||||||
set_salary_component_account(data.name)
|
get_salary_component_account(data.name)
|
||||||
|
|
||||||
employee = frappe.db.get_value("Employee", {"company": company})
|
|
||||||
company_doc = frappe.get_doc("Company", company)
|
company_doc = frappe.get_doc("Company", company)
|
||||||
make_salary_structure(
|
salary_structure = make_salary_structure(
|
||||||
"_Test Salary Structure",
|
"_Test Multi Currency Salary Structure", "Monthly", company=company, currency="USD"
|
||||||
"Monthly",
|
|
||||||
employee,
|
|
||||||
company=company,
|
|
||||||
currency=company_doc.default_currency,
|
|
||||||
)
|
)
|
||||||
dates = get_start_end_dates("Monthly", nowdate())
|
create_salary_structure_assignment(
|
||||||
if not frappe.db.get_value(
|
employee, salary_structure.name, company=company, currency="USD"
|
||||||
"Salary Slip", {"start_date": dates.start_date, "end_date": dates.end_date}
|
|
||||||
):
|
|
||||||
make_payroll_entry(
|
|
||||||
start_date=dates.start_date,
|
|
||||||
end_date=dates.end_date,
|
|
||||||
payable_account=company_doc.default_payroll_payable_account,
|
|
||||||
currency=company_doc.default_currency,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_multi_currency_payroll_entry(self):
|
|
||||||
company = frappe.get_doc("Company", "_Test Company")
|
|
||||||
employee = make_employee(
|
|
||||||
"test_muti_currency_employee@payroll.com", company=company.name, department="Accounts - _TC"
|
|
||||||
)
|
)
|
||||||
|
frappe.db.sql(
|
||||||
for data in frappe.get_all("Salary Component", fields=["name"]):
|
"""delete from `tabSalary Slip` where employee=%s""",
|
||||||
if not frappe.db.get_value(
|
(frappe.db.get_value("Employee", {"user_id": "test_muti_currency_employee@payroll.com"})),
|
||||||
"Salary Component Account", {"parent": data.name, "company": company.name}, "name"
|
)
|
||||||
):
|
salary_slip = get_salary_slip(
|
||||||
set_salary_component_account(data.name)
|
"test_muti_currency_employee@payroll.com", "Monthly", "_Test Multi Currency Salary Structure"
|
||||||
|
|
||||||
salary_struct = make_salary_structure(
|
|
||||||
"_Test Multi Currency Salary Structure",
|
|
||||||
"Monthly",
|
|
||||||
employee,
|
|
||||||
currency="USD",
|
|
||||||
company=company.name,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
frappe.db.delete("Salary Slip", {"employee": employee})
|
|
||||||
dates = get_start_end_dates("Monthly", nowdate())
|
dates = get_start_end_dates("Monthly", nowdate())
|
||||||
payroll_entry = make_payroll_entry(
|
payroll_entry = make_payroll_entry(
|
||||||
start_date=dates.start_date,
|
start_date=dates.start_date,
|
||||||
end_date=dates.end_date,
|
end_date=dates.end_date,
|
||||||
payable_account=company.default_payroll_payable_account,
|
payable_account=company_doc.default_payroll_payable_account,
|
||||||
currency="USD",
|
currency="USD",
|
||||||
exchange_rate=70,
|
exchange_rate=70,
|
||||||
company=company.name,
|
|
||||||
)
|
)
|
||||||
payroll_entry.make_payment_entry()
|
payroll_entry.make_payment_entry()
|
||||||
|
|
||||||
salary_slip = frappe.db.get_value("Salary Slip", {"payroll_entry": payroll_entry.name})
|
salary_slip.load_from_db()
|
||||||
salary_slip = frappe.get_doc("Salary Slip", salary_slip)
|
|
||||||
|
|
||||||
payroll_je = salary_slip.journal_entry
|
payroll_je = salary_slip.journal_entry
|
||||||
if payroll_je:
|
if payroll_je:
|
||||||
@@ -143,22 +141,11 @@ class TestPayrollEntry(FrappeTestCase):
|
|||||||
self.assertEqual(salary_slip.base_net_pay, payment_entry[0].total_credit)
|
self.assertEqual(salary_slip.base_net_pay, payment_entry[0].total_credit)
|
||||||
|
|
||||||
def test_payroll_entry_with_employee_cost_center(self):
|
def test_payroll_entry_with_employee_cost_center(self):
|
||||||
for data in frappe.get_all("Salary Component", fields=["name"]):
|
|
||||||
if not frappe.db.get_value(
|
|
||||||
"Salary Component Account", {"parent": data.name, "company": "_Test Company"}, "name"
|
|
||||||
):
|
|
||||||
set_salary_component_account(data.name)
|
|
||||||
|
|
||||||
if not frappe.db.exists("Department", "cc - _TC"):
|
if not frappe.db.exists("Department", "cc - _TC"):
|
||||||
frappe.get_doc(
|
frappe.get_doc(
|
||||||
{"doctype": "Department", "department_name": "cc", "company": "_Test Company"}
|
{"doctype": "Department", "department_name": "cc", "company": "_Test Company"}
|
||||||
).insert()
|
).insert()
|
||||||
|
|
||||||
frappe.db.sql("""delete from `tabEmployee` where employee_name='test_employee1@example.com' """)
|
|
||||||
frappe.db.sql("""delete from `tabEmployee` where employee_name='test_employee2@example.com' """)
|
|
||||||
frappe.db.sql("""delete from `tabSalary Structure` where name='_Test Salary Structure 1' """)
|
|
||||||
frappe.db.sql("""delete from `tabSalary Structure` where name='_Test Salary Structure 2' """)
|
|
||||||
|
|
||||||
employee1 = make_employee(
|
employee1 = make_employee(
|
||||||
"test_employee1@example.com",
|
"test_employee1@example.com",
|
||||||
payroll_cost_center="_Test Cost Center - _TC",
|
payroll_cost_center="_Test Cost Center - _TC",
|
||||||
@@ -169,38 +156,15 @@ class TestPayrollEntry(FrappeTestCase):
|
|||||||
"test_employee2@example.com", department="cc - _TC", company="_Test Company"
|
"test_employee2@example.com", department="cc - _TC", company="_Test Company"
|
||||||
)
|
)
|
||||||
|
|
||||||
if not frappe.db.exists("Account", "_Test Payroll Payable - _TC"):
|
company = frappe.get_doc("Company", "_Test Company")
|
||||||
create_account(
|
setup_salary_structure(employee1, company)
|
||||||
account_name="_Test Payroll Payable",
|
|
||||||
company="_Test Company",
|
|
||||||
parent_account="Current Liabilities - _TC",
|
|
||||||
account_type="Payable",
|
|
||||||
)
|
|
||||||
|
|
||||||
if (
|
|
||||||
not frappe.db.get_value("Company", "_Test Company", "default_payroll_payable_account")
|
|
||||||
or frappe.db.get_value("Company", "_Test Company", "default_payroll_payable_account")
|
|
||||||
!= "_Test Payroll Payable - _TC"
|
|
||||||
):
|
|
||||||
frappe.db.set_value(
|
|
||||||
"Company", "_Test Company", "default_payroll_payable_account", "_Test Payroll Payable - _TC"
|
|
||||||
)
|
|
||||||
currency = frappe.db.get_value("Company", "_Test Company", "default_currency")
|
|
||||||
|
|
||||||
make_salary_structure(
|
|
||||||
"_Test Salary Structure 1",
|
|
||||||
"Monthly",
|
|
||||||
employee1,
|
|
||||||
company="_Test Company",
|
|
||||||
currency=currency,
|
|
||||||
test_tax=False,
|
|
||||||
)
|
|
||||||
ss = make_salary_structure(
|
ss = make_salary_structure(
|
||||||
"_Test Salary Structure 2",
|
"_Test Salary Structure 2",
|
||||||
"Monthly",
|
"Monthly",
|
||||||
employee2,
|
employee2,
|
||||||
company="_Test Company",
|
company="_Test Company",
|
||||||
currency=currency,
|
currency=company.default_currency,
|
||||||
test_tax=False,
|
test_tax=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -219,42 +183,38 @@ class TestPayrollEntry(FrappeTestCase):
|
|||||||
ssa_doc.append(
|
ssa_doc.append(
|
||||||
"payroll_cost_centers", {"cost_center": "_Test Cost Center 2 - _TC", "percentage": 40}
|
"payroll_cost_centers", {"cost_center": "_Test Cost Center 2 - _TC", "percentage": 40}
|
||||||
)
|
)
|
||||||
|
|
||||||
ssa_doc.save()
|
ssa_doc.save()
|
||||||
|
|
||||||
dates = get_start_end_dates("Monthly", nowdate())
|
dates = get_start_end_dates("Monthly", nowdate())
|
||||||
if not frappe.db.get_value(
|
pe = make_payroll_entry(
|
||||||
"Salary Slip", {"start_date": dates.start_date, "end_date": dates.end_date}
|
start_date=dates.start_date,
|
||||||
):
|
end_date=dates.end_date,
|
||||||
pe = make_payroll_entry(
|
payable_account="_Test Payroll Payable - _TC",
|
||||||
start_date=dates.start_date,
|
currency=frappe.db.get_value("Company", "_Test Company", "default_currency"),
|
||||||
end_date=dates.end_date,
|
department="cc - _TC",
|
||||||
payable_account="_Test Payroll Payable - _TC",
|
company="_Test Company",
|
||||||
currency=frappe.db.get_value("Company", "_Test Company", "default_currency"),
|
payment_account="Cash - _TC",
|
||||||
department="cc - _TC",
|
cost_center="Main - _TC",
|
||||||
company="_Test Company",
|
)
|
||||||
payment_account="Cash - _TC",
|
je = frappe.db.get_value("Salary Slip", {"payroll_entry": pe.name}, "journal_entry")
|
||||||
cost_center="Main - _TC",
|
je_entries = frappe.db.sql(
|
||||||
)
|
"""
|
||||||
je = frappe.db.get_value("Salary Slip", {"payroll_entry": pe.name}, "journal_entry")
|
select account, cost_center, debit, credit
|
||||||
je_entries = frappe.db.sql(
|
from `tabJournal Entry Account`
|
||||||
"""
|
where parent=%s
|
||||||
select account, cost_center, debit, credit
|
order by account, cost_center
|
||||||
from `tabJournal Entry Account`
|
""",
|
||||||
where parent=%s
|
je,
|
||||||
order by account, cost_center
|
)
|
||||||
""",
|
expected_je = (
|
||||||
je,
|
("_Test Payroll Payable - _TC", "Main - _TC", 0.0, 155600.0),
|
||||||
)
|
("Salary - _TC", "_Test Cost Center - _TC", 124800.0, 0.0),
|
||||||
expected_je = (
|
("Salary - _TC", "_Test Cost Center 2 - _TC", 31200.0, 0.0),
|
||||||
("_Test Payroll Payable - _TC", "Main - _TC", 0.0, 155600.0),
|
("Salary Deductions - _TC", "_Test Cost Center - _TC", 0.0, 320.0),
|
||||||
("Salary - _TC", "_Test Cost Center - _TC", 124800.0, 0.0),
|
("Salary Deductions - _TC", "_Test Cost Center 2 - _TC", 0.0, 80.0),
|
||||||
("Salary - _TC", "_Test Cost Center 2 - _TC", 31200.0, 0.0),
|
)
|
||||||
("Salary Deductions - _TC", "_Test Cost Center - _TC", 0.0, 320.0),
|
|
||||||
("Salary Deductions - _TC", "_Test Cost Center 2 - _TC", 0.0, 80.0),
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(je_entries, expected_je)
|
self.assertEqual(je_entries, expected_je)
|
||||||
|
|
||||||
def test_get_end_date(self):
|
def test_get_end_date(self):
|
||||||
self.assertEqual(get_end_date("2017-01-01", "monthly"), {"end_date": "2017-01-31"})
|
self.assertEqual(get_end_date("2017-01-01", "monthly"), {"end_date": "2017-01-31"})
|
||||||
@@ -267,31 +227,22 @@ class TestPayrollEntry(FrappeTestCase):
|
|||||||
self.assertEqual(get_end_date("2017-02-15", "daily"), {"end_date": "2017-02-15"})
|
self.assertEqual(get_end_date("2017-02-15", "daily"), {"end_date": "2017-02-15"})
|
||||||
|
|
||||||
def test_loan(self):
|
def test_loan(self):
|
||||||
branch = "Test Employee Branch"
|
|
||||||
applicant = make_employee("test_employee@loan.com", company="_Test Company")
|
|
||||||
company = "_Test Company"
|
company = "_Test Company"
|
||||||
holiday_list = make_holiday("test holiday for loan")
|
branch = "Test Employee Branch"
|
||||||
|
|
||||||
company_doc = frappe.get_doc("Company", company)
|
|
||||||
if not company_doc.default_payroll_payable_account:
|
|
||||||
company_doc.default_payroll_payable_account = frappe.db.get_value(
|
|
||||||
"Account", {"company": company, "root_type": "Liability", "account_type": ""}, "name"
|
|
||||||
)
|
|
||||||
company_doc.save()
|
|
||||||
|
|
||||||
if not frappe.db.exists("Branch", branch):
|
if not frappe.db.exists("Branch", branch):
|
||||||
frappe.get_doc({"doctype": "Branch", "branch": branch}).insert()
|
frappe.get_doc({"doctype": "Branch", "branch": branch}).insert()
|
||||||
|
holiday_list = make_holiday("test holiday for loan")
|
||||||
|
|
||||||
employee_doc = frappe.get_doc("Employee", applicant)
|
applicant = make_employee(
|
||||||
employee_doc.branch = branch
|
"test_employee@loan.com", company="_Test Company", branch=branch, holiday_list=holiday_list
|
||||||
employee_doc.holiday_list = holiday_list
|
)
|
||||||
employee_doc.save()
|
company_doc = frappe.get_doc("Company", company)
|
||||||
|
|
||||||
salary_structure = "Test Salary Structure for Loan"
|
|
||||||
make_salary_structure(
|
make_salary_structure(
|
||||||
salary_structure,
|
"Test Salary Structure for Loan",
|
||||||
"Monthly",
|
"Monthly",
|
||||||
employee=employee_doc.name,
|
employee=applicant,
|
||||||
company="_Test Company",
|
company="_Test Company",
|
||||||
currency=company_doc.default_currency,
|
currency=company_doc.default_currency,
|
||||||
)
|
)
|
||||||
@@ -352,21 +303,11 @@ class TestPayrollEntry(FrappeTestCase):
|
|||||||
self.assertEqual(row.principal_amount, principal_amount)
|
self.assertEqual(row.principal_amount, principal_amount)
|
||||||
self.assertEqual(row.total_payment, interest_amount + principal_amount)
|
self.assertEqual(row.total_payment, interest_amount + principal_amount)
|
||||||
|
|
||||||
if salary_slip.docstatus == 0:
|
|
||||||
frappe.delete_doc("Salary Slip", name)
|
|
||||||
|
|
||||||
def test_salary_slip_operation_queueing(self):
|
def test_salary_slip_operation_queueing(self):
|
||||||
# setup
|
company = "_Test Company"
|
||||||
company = erpnext.get_default_company()
|
|
||||||
company_doc = frappe.get_doc("Company", company)
|
company_doc = frappe.get_doc("Company", company)
|
||||||
employee = frappe.db.get_value("Employee", {"company": company})
|
employee = frappe.db.get_value("Employee", {"company": company})
|
||||||
make_salary_structure(
|
setup_salary_structure(employee, company_doc)
|
||||||
"_Test Salary Structure",
|
|
||||||
"Monthly",
|
|
||||||
employee,
|
|
||||||
company=company,
|
|
||||||
currency=company_doc.default_currency,
|
|
||||||
)
|
|
||||||
|
|
||||||
# enqueue salary slip creation via payroll entry
|
# enqueue salary slip creation via payroll entry
|
||||||
# Payroll Entry status should change to Queued
|
# Payroll Entry status should change to Queued
|
||||||
@@ -376,6 +317,7 @@ class TestPayrollEntry(FrappeTestCase):
|
|||||||
end_date=dates.end_date,
|
end_date=dates.end_date,
|
||||||
payable_account=company_doc.default_payroll_payable_account,
|
payable_account=company_doc.default_payroll_payable_account,
|
||||||
currency=company_doc.default_currency,
|
currency=company_doc.default_currency,
|
||||||
|
company=company_doc.name,
|
||||||
)
|
)
|
||||||
frappe.flags.enqueue_payroll_entry = True
|
frappe.flags.enqueue_payroll_entry = True
|
||||||
payroll_entry.create_salary_slips()
|
payroll_entry.create_salary_slips()
|
||||||
@@ -385,10 +327,10 @@ class TestPayrollEntry(FrappeTestCase):
|
|||||||
frappe.flags.enqueue_payroll_entry = False
|
frappe.flags.enqueue_payroll_entry = False
|
||||||
|
|
||||||
def test_salary_slip_operation_failure(self):
|
def test_salary_slip_operation_failure(self):
|
||||||
# setup
|
company = "_Test Company"
|
||||||
company = erpnext.get_default_company()
|
|
||||||
company_doc = frappe.get_doc("Company", company)
|
company_doc = frappe.get_doc("Company", company)
|
||||||
employee = frappe.db.get_value("Employee", {"company": company})
|
employee = frappe.db.get_value("Employee", {"company": company})
|
||||||
|
|
||||||
salary_structure = make_salary_structure(
|
salary_structure = make_salary_structure(
|
||||||
"_Test Salary Structure",
|
"_Test Salary Structure",
|
||||||
"Monthly",
|
"Monthly",
|
||||||
@@ -410,6 +352,7 @@ class TestPayrollEntry(FrappeTestCase):
|
|||||||
end_date=dates.end_date,
|
end_date=dates.end_date,
|
||||||
payable_account=company_doc.default_payroll_payable_account,
|
payable_account=company_doc.default_payroll_payable_account,
|
||||||
currency=company_doc.default_currency,
|
currency=company_doc.default_currency,
|
||||||
|
company=company_doc.name,
|
||||||
)
|
)
|
||||||
payroll_entry.create_salary_slips()
|
payroll_entry.create_salary_slips()
|
||||||
payroll_entry.submit_salary_slips()
|
payroll_entry.submit_salary_slips()
|
||||||
@@ -419,41 +362,30 @@ class TestPayrollEntry(FrappeTestCase):
|
|||||||
self.assertIsNotNone(payroll_entry.error_message)
|
self.assertIsNotNone(payroll_entry.error_message)
|
||||||
|
|
||||||
# set accounts
|
# set accounts
|
||||||
for data in frappe.get_all("Salary Component", fields=["name"]):
|
for data in frappe.get_all("Salary Component", pluck="name"):
|
||||||
if not frappe.db.get_value(
|
set_salary_component_account(data, company_list=[company])
|
||||||
"Salary Component Account", {"parent": data.name, "company": company}, "name"
|
|
||||||
):
|
|
||||||
set_salary_component_account(data.name, company_list=[company])
|
|
||||||
|
|
||||||
# Payroll Entry successful, status should change to Submitted
|
# Payroll Entry successful, status should change to Submitted
|
||||||
payroll_entry.submit_salary_slips()
|
payroll_entry.submit_salary_slips()
|
||||||
payroll_entry.reload()
|
payroll_entry.reload()
|
||||||
|
|
||||||
self.assertEqual(payroll_entry.status, "Submitted")
|
self.assertEqual(payroll_entry.status, "Submitted")
|
||||||
self.assertEqual(payroll_entry.error_message, "")
|
self.assertEqual(payroll_entry.error_message, "")
|
||||||
|
|
||||||
def test_payroll_entry_status(self):
|
def test_payroll_entry_status(self):
|
||||||
company = erpnext.get_default_company()
|
company = "_Test Company"
|
||||||
for data in frappe.get_all("Salary Component", fields=["name"]):
|
|
||||||
if not frappe.db.get_value(
|
|
||||||
"Salary Component Account", {"parent": data.name, "company": company}, "name"
|
|
||||||
):
|
|
||||||
set_salary_component_account(data.name)
|
|
||||||
|
|
||||||
employee = frappe.db.get_value("Employee", {"company": company})
|
|
||||||
company_doc = frappe.get_doc("Company", company)
|
company_doc = frappe.get_doc("Company", company)
|
||||||
make_salary_structure(
|
employee = frappe.db.get_value("Employee", {"company": company})
|
||||||
"_Test Salary Structure",
|
|
||||||
"Monthly",
|
setup_salary_structure(employee, company_doc)
|
||||||
employee,
|
|
||||||
company=company,
|
|
||||||
currency=company_doc.default_currency,
|
|
||||||
)
|
|
||||||
dates = get_start_end_dates("Monthly", nowdate())
|
dates = get_start_end_dates("Monthly", nowdate())
|
||||||
payroll_entry = get_payroll_entry_data(
|
payroll_entry = get_payroll_entry_data(
|
||||||
start_date=dates.start_date,
|
start_date=dates.start_date,
|
||||||
end_date=dates.end_date,
|
end_date=dates.end_date,
|
||||||
payable_account=company_doc.default_payroll_payable_account,
|
payable_account=company_doc.default_payroll_payable_account,
|
||||||
currency=company_doc.default_currency,
|
currency=company_doc.default_currency,
|
||||||
|
company=company_doc.name,
|
||||||
)
|
)
|
||||||
payroll_entry.submit()
|
payroll_entry.submit()
|
||||||
self.assertEqual(payroll_entry.status, "Submitted")
|
self.assertEqual(payroll_entry.status, "Submitted")
|
||||||
@@ -532,3 +464,28 @@ def make_holiday(holiday_list_name):
|
|||||||
).insert()
|
).insert()
|
||||||
|
|
||||||
return holiday_list_name
|
return holiday_list_name
|
||||||
|
|
||||||
|
|
||||||
|
def get_salary_slip(user, period, salary_structure):
|
||||||
|
salary_slip = make_employee_salary_slip(user, period, salary_structure)
|
||||||
|
salary_slip.exchange_rate = 70
|
||||||
|
salary_slip.calculate_net_pay()
|
||||||
|
salary_slip.db_update()
|
||||||
|
|
||||||
|
return salary_slip
|
||||||
|
|
||||||
|
|
||||||
|
def setup_salary_structure(employee, company_doc, currency=None, salary_structure=None):
|
||||||
|
for data in frappe.get_all("Salary Component", pluck="name"):
|
||||||
|
if not frappe.db.get_value(
|
||||||
|
"Salary Component Account", {"parent": data, "company": company_doc.name}, "name"
|
||||||
|
):
|
||||||
|
set_salary_component_account(data)
|
||||||
|
|
||||||
|
make_salary_structure(
|
||||||
|
salary_structure or "_Test Salary Structure",
|
||||||
|
"Monthly",
|
||||||
|
employee,
|
||||||
|
company=company_doc.name,
|
||||||
|
currency=(currency or company_doc.default_currency),
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user