Skip to content

Commit

Permalink
fix(tests): account and company setups
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal committed May 31, 2022
1 parent c6764fc commit 4a3ff01
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions erpnext/payroll/doctype/payroll_entry/test_payroll_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
create_account,
make_deduction_salary_component,
make_earning_salary_component,
make_employee_salary_slip,
set_salary_component_account,
)
from erpnext.payroll.doctype.salary_structure.salary_structure import make_salary_slip
from erpnext.payroll.doctype.salary_structure.test_salary_structure import (
create_salary_structure_assignment,
make_salary_structure,
Expand Down Expand Up @@ -83,14 +83,20 @@ def test_payroll_entry(self):
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 = frappe.get_doc("Company", "_Test Company")
employee = make_employee(
"test_muti_currency_employee@payroll.com", company=company.name, department="Accounts - _TC"
)
setup_salary_structure(employee, company, "USD")
salary_structure = "_Test Multi Currency Salary Structure"
setup_salary_structure(employee, company, "USD", salary_structure)
salary_slip = make_salary_slip(salary_structure, employee=employee)
salary_slip.exchange_rate = 70
salary_slip.calculate_net_pay()
salary_slip.db_update()

dates = get_start_end_dates("Monthly", nowdate())
payroll_entry = make_payroll_entry(
Expand All @@ -103,9 +109,7 @@ def test_multi_currency_payroll_entry(self):
)
payroll_entry.make_payment_entry()

salary_slip = frappe.db.get_value("Salary Slip", {"payroll_entry": payroll_entry.name})
salary_slip = frappe.get_doc("Salary Slip", salary_slip)

salary_slip.load_from_db()
payroll_je = salary_slip.journal_entry
if payroll_je:
payroll_je_doc = frappe.get_doc("Journal Entry", payroll_je)
Expand All @@ -127,6 +131,11 @@ def test_multi_currency_payroll_entry(self):
self.assertEqual(salary_slip.base_net_pay, payment_entry[0].total_credit)

def test_payroll_entry_with_employee_cost_center(self):
if not frappe.db.exists("Department", "cc - _TC"):
frappe.get_doc(
{"doctype": "Department", "department_name": "cc", "company": "_Test Company"}
).insert()

employee1 = make_employee(
"test_employee1@example.com",
payroll_cost_center="_Test Cost Center - _TC",
Expand All @@ -136,17 +145,6 @@ def test_payroll_entry_with_employee_cost_center(self):
employee2 = make_employee(
"test_employee2@example.com", department="cc - _TC", company="_Test Company"
)
create_account(
account_name="_Test Payroll Payable",
company="_Test Company",
parent_account="Current Liabilities - _TC",
account_type="Payable",
)

if not frappe.db.exists("Department", "cc - _TC"):
frappe.get_doc(
{"doctype": "Department", "department_name": "cc", "company": "_Test Company"}
).insert()

company = frappe.get_doc("Company", "_Test Company")
setup_salary_structure(employee1, company)
Expand Down Expand Up @@ -309,6 +307,7 @@ def test_salary_slip_operation_queueing(self):
end_date=dates.end_date,
payable_account=company_doc.default_payroll_payable_account,
currency=company_doc.default_currency,
company=company_doc.name,
)
frappe.flags.enqueue_payroll_entry = True
payroll_entry.create_salary_slips()
Expand Down Expand Up @@ -343,6 +342,7 @@ def test_salary_slip_operation_failure(self):
end_date=dates.end_date,
payable_account=company_doc.default_payroll_payable_account,
currency=company_doc.default_currency,
company=company_doc.name,
)
payroll_entry.create_salary_slips()
payroll_entry.submit_salary_slips()
Expand All @@ -352,15 +352,16 @@ def test_salary_slip_operation_failure(self):
self.assertIsNotNone(payroll_entry.error_message)

# 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(
"Salary Component Account", {"parent": data.name, "company": company}, "name"
"Salary Component Account", {"parent": data, "company": company}, "name"
):
set_salary_component_account(data.name, company_list=[company])
set_salary_component_account(data, company_list=[company])

# Payroll Entry successful, status should change to Submitted
payroll_entry.submit_salary_slips()
payroll_entry.reload()

self.assertEqual(payroll_entry.status, "Submitted")
self.assertEqual(payroll_entry.error_message, "")

Expand All @@ -377,6 +378,7 @@ def test_payroll_entry_status(self):
end_date=dates.end_date,
payable_account=company_doc.default_payroll_payable_account,
currency=company_doc.default_currency,
company=company_doc.name,
)
payroll_entry.submit()
self.assertEqual(payroll_entry.status, "Submitted")
Expand Down Expand Up @@ -457,15 +459,15 @@ def make_holiday(holiday_list_name):
return holiday_list_name


def setup_salary_structure(employee, company_doc, currency=None):
for data in frappe.get_all("Salary Component", fields=["name"]):
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.name, "company": company_doc.name}, "name"
"Salary Component Account", {"parent": data, "company": company_doc.name}, "name"
):
set_salary_component_account(data.name)
set_salary_component_account(data)

make_salary_structure(
"_Test Salary Structure",
salary_structure or "_Test Salary Structure",
"Monthly",
employee,
company=company_doc.name,
Expand Down

0 comments on commit 4a3ff01

Please sign in to comment.