def test_loan(self): branch = "Test Employee Branch" applicant = make_employee("*****@*****.**", company="_Test Company") company = "_Test Company" holiday_list = make_holiday("test holiday for loan") 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): frappe.get_doc({ 'doctype': 'Branch', 'branch': branch }).insert() employee_doc = frappe.get_doc('Employee', applicant) employee_doc.branch = branch employee_doc.holiday_list = holiday_list employee_doc.save() salary_structure = "Test Salary Structure for Loan" make_salary_structure(salary_structure, "Monthly", employee=employee_doc.name, company="_Test Company") loan = create_loan(applicant, "Car Loan", 280000, "Repay Over Number of Periods", 20, posting_date=add_months(nowdate(), -1)) loan.repay_from_salary = 1 loan.submit() make_loan_disbursement_entry(loan.name, loan.loan_amount, disbursement_date=add_months(nowdate(), -1)) process_loan_interest_accrual_for_term_loans(posting_date=nowdate()) dates = get_start_end_dates('Monthly', nowdate()) make_payroll_entry(company="_Test Company", start_date=dates.start_date, end_date=dates.end_date, branch=branch, cost_center="Main - _TC", payment_account="Cash - _TC") name = frappe.db.get_value('Salary Slip', {'posting_date': nowdate(), 'employee': applicant}, 'name') salary_slip = frappe.get_doc('Salary Slip', name) for row in salary_slip.loans: if row.loan == loan.name: interest_amount = (280000 * 8.4)/(12*100) principal_amount = loan.monthly_repayment_amount - interest_amount self.assertEqual(row.interest_amount, interest_amount) self.assertEqual(row.principal_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_payroll_entry(self): # pylint: disable=no-self-use company = erpnext.get_default_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'): get_salary_component_account(data.name) employee = frappe.db.get_value("Employee", {'company': company}) make_salary_structure("_Test Salary Structure", "Monthly", employee) dates = get_start_end_dates('Monthly', nowdate()) if not frappe.db.get_value("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)
def test_loan(self): branch = "Test Employee Branch" applicant = make_employee("*****@*****.**") company = erpnext.get_default_company() holiday_list = make_holiday("test holiday for loan") 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): frappe.get_doc({ 'doctype': 'Branch', 'branch': branch }).insert() employee_doc = frappe.get_doc('Employee', applicant) employee_doc.branch = branch employee_doc.holiday_list = holiday_list employee_doc.save() loan = create_loan(applicant, "Personal Loan", 280000, "Repay Over Number of Periods", 20) loan.repay_from_salary = 1 loan.submit() salary_structure = "Test Salary Structure for Loan" make_salary_structure(salary_structure, "Monthly", employee_doc.name) dates = get_start_end_dates('Monthly', nowdate()) make_payroll_entry(start_date=dates.start_date, end_date=dates.end_date, branch=branch) name = frappe.db.get_value('Salary Slip', {'posting_date': nowdate(), 'employee': applicant}, 'name') salary_slip = frappe.get_doc('Salary Slip', name) for row in salary_slip.loans: if row.loan == loan.name: interest_amount = (280000 * 8.4)/(12*100) principal_amount = loan.monthly_repayment_amount - interest_amount self.assertEqual(row.interest_amount, interest_amount) self.assertEqual(row.principal_amount, principal_amount) self.assertEqual(row.total_payment, interest_amount + principal_amount) if salary_slip.docstatus == 0: frappe.delete_doc('Salary Slip', name)
def setUp(self): frappe.db.sql('''delete from `tabLeave Period`''') frappe.db.sql('''delete from `tabLeave Allocation`''') frappe.db.sql('''delete from `tabLeave Ledger Entry`''') frappe.db.sql('''delete from `tabAdditional Salary`''') # create the leave policy leave_policy = create_leave_policy( leave_type="_Test Leave Type Encashment", annual_allocation=10) leave_policy.submit() # create employee, salary structure and assignment self.employee = make_employee("*****@*****.**") frappe.db.set_value("Employee", self.employee, "leave_policy", leave_policy.name) salary_structure = make_salary_structure( "Salary Structure for Encashment", "Monthly", self.employee, other_details={"leave_encashment_amount_per_day": 50}) # create the leave period and assign the leaves self.leave_period = create_leave_period(add_months(today(), -3), add_months(today(), 3)) self.leave_period.grant_leave_allocation(employee=self.employee)
def make_employee_salary_slip(user, payroll_frequency, salary_structure=None): from erpnext.hr.doctype.salary_structure.test_salary_structure import make_salary_structure if not salary_structure: salary_structure = payroll_frequency + " Salary Structure Test for Salary Slip" employee = frappe.db.get_value("Employee", {"user_id": user}) salary_structure_doc = make_salary_structure(salary_structure, payroll_frequency, employee) salary_slip = frappe.db.get_value( "Salary Slip", {"employee": frappe.db.get_value("Employee", {"user_id": user})}) if not salary_slip: salary_slip = make_salary_slip(salary_structure_doc.name, employee=employee) salary_slip.employee_name = frappe.get_value( "Employee", {"name": frappe.db.get_value("Employee", {"user_id": user})}, "employee_name") salary_slip.payroll_frequency = payroll_frequency salary_slip.posting_date = nowdate() salary_slip.insert() # salary_slip.submit() # salary_slip = salary_slip.name return salary_slip
def test_payroll_entry_with_employee_cost_center(self): # pylint: disable=no-self-use 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'): get_salary_component_account(data.name) if not frappe.db.exists('Department', "cc - _TC"): frappe.get_doc({ 'doctype': 'Department', 'department_name': "cc", "company": "_Test Company" }).insert() employee1 = make_employee("*****@*****.**", payroll_cost_center="_Test Cost Center - _TC", department="cc - _TC", company="_Test Company") employee2 = make_employee("*****@*****.**", payroll_cost_center="_Test Cost Center 2 - _TC", department="cc - _TC", company="_Test Company") make_salary_structure("_Test Salary Structure 1", "Monthly", employee1, company="_Test Company") make_salary_structure("_Test Salary Structure 2", "Monthly", employee2, company="_Test Company") if not frappe.db.exists("Account", "_Test Payroll Payable - _TC"): create_account(account_name="_Test Payroll Payable", company="_Test Company", parent_account="Current Liabilities - _TC") frappe.db.set_value("Company", "_Test Company", "default_payroll_payable_account", "_Test Payroll Payable - _TC") dates = get_start_end_dates('Monthly', nowdate()) if not frappe.db.get_value("Salary Slip", {"start_date": dates.start_date, "end_date": dates.end_date}): pe = make_payroll_entry(start_date=dates.start_date, end_date=dates.end_date, department="cc - _TC", company="_Test Company", payment_account="Cash - _TC", cost_center="Main - _TC") je = frappe.db.get_value("Salary Slip", {"payroll_entry": pe.name}, "journal_entry") je_entries = frappe.db.sql(""" select account, cost_center, debit, credit from `tabJournal Entry Account` where parent=%s order by account, cost_center """, je) expected_je = ( ('_Test Payroll Payable - _TC', 'Main - _TC', 0.0, 155600.0), ('Salary - _TC', '_Test Cost Center - _TC', 78000.0, 0.0), ('Salary - _TC', '_Test Cost Center 2 - _TC', 78000.0, 0.0), ('Salary Deductions - _TC', '_Test Cost Center - _TC', 0.0, 200.0), ('Salary Deductions - _TC', '_Test Cost Center 2 - _TC', 0.0, 200.0) ) self.assertEqual(je_entries, expected_je)
def make_salary_structure_for_timesheet(employee): salary_structure_name = "Timesheet Salary Structure Test" frequency = "Monthly" salary_structure = make_salary_structure(salary_structure_name, frequency, dont_submit=True) salary_structure.salary_component = "Timesheet Component" salary_structure.salary_slip_based_on_timesheet = 1 salary_structure.hour_rate = 50.0 salary_structure.save() salary_structure.submit() if not frappe.db.get_value("Salary Structure Assignment", {'employee':employee, 'docstatus': 1}): create_salary_structure_assignment(employee, salary_structure.name) return salary_structure
def make_employee_salary_slip(user, payroll_frequency, salary_structure=None): from erpnext.hr.doctype.salary_structure.test_salary_structure import make_salary_structure if not salary_structure: salary_structure = payroll_frequency + " Salary Structure Test for Salary Slip" employee = frappe.db.get_value("Employee", {"user_id": user}) salary_structure_doc = make_salary_structure(salary_structure, payroll_frequency, employee) salary_slip = frappe.db.get_value("Salary Slip", {"employee": frappe.db.get_value("Employee", {"user_id": user})}) if not salary_slip: salary_slip = make_salary_slip(salary_structure_doc.name, employee = employee) salary_slip.employee_name = frappe.get_value("Employee", {"name":frappe.db.get_value("Employee", {"user_id": user})}, "employee_name") salary_slip.payroll_frequency = payroll_frequency salary_slip.posting_date = nowdate() salary_slip.insert() return salary_slip
def test_leave_balance_value_and_amount(self): employee = "*****@*****.**" leave_type = "_Test Leave Type Encashment" # create the leave policy leave_policy = frappe.get_doc({ "doctype": "Leave Policy", "leave_policy_details": [{ "leave_type": leave_type, "annual_allocation": 10 }] }).insert() leave_policy.submit() # create employee, salary structure and assignment employee = make_employee(employee) frappe.db.set_value("Employee", employee, "leave_policy", leave_policy.name) salary_structure = make_salary_structure( "Salary Structure for Encashment", "Monthly", employee, other_details={"leave_encashment_amount_per_day": 50}) # create the leave period and assign the leaves leave_period = create_leave_period(add_months(today(), -3), add_months(today(), 3)) leave_period.grant_leave_allocation(employee=employee) leave_encashment = frappe.get_doc( dict(doctype='Leave Encashment', employee=employee, leave_type=leave_type, leave_period=leave_period.name, payroll_date=today())).insert() self.assertEqual(leave_encashment.leave_balance, 10) self.assertEqual(leave_encashment.encashable_days, 5) self.assertEqual(leave_encashment.encashment_amount, 250) leave_encashment.submit() self.assertTrue( frappe.db.get_value("Leave Encashment", leave_encashment.name, "additional_salary"))
def make_salary_structure_for_timesheet(employee): salary_structure_name = "Timesheet Salary Structure Test" frequency = "Monthly" salary_structure = make_salary_structure(salary_structure_name, frequency, dont_submit=True) salary_structure.salary_component = "Timesheet Component" salary_structure.salary_slip_based_on_timesheet = 1 salary_structure.hour_rate = 50.0 salary_structure.save() salary_structure.submit() if not frappe.db.get_value("Salary Structure Assignment", { 'employee': employee, 'docstatus': 1 }): create_salary_structure_assignment(employee, salary_structure.name) return salary_structure
def test_leave_balance_value_and_amount(self): employee = "*****@*****.**" leave_type = "_Test Leave Type Encashment" # create the leave policy leave_policy = frappe.get_doc({ "doctype": "Leave Policy", "leave_policy_details": [{ "leave_type": leave_type, "annual_allocation": 10 }] }).insert() leave_policy.submit() # create employee, salary structure and assignment employee = make_employee(employee) frappe.db.set_value("Employee", employee, "leave_policy", leave_policy.name) salary_structure = make_salary_structure("Salary Structure for Encashment", "Monthly", employee, other_details={"leave_encashment_amount_per_day": 50}) # create the leave period and assign the leaves leave_period = create_leave_period(add_months(today(), -3), add_months(today(), 3)) leave_period.grant_leave_allocation(employee=employee) leave_encashment = frappe.get_doc(dict( doctype = 'Leave Encashment', employee = employee, leave_type = leave_type, leave_period = leave_period.name, payroll_date = today() )).insert() self.assertEqual(leave_encashment.leave_balance, 10) self.assertEqual(leave_encashment.encashable_days, 5) self.assertEqual(leave_encashment.encashment_amount, 250) leave_encashment.submit() self.assertTrue(frappe.db.get_value("Leave Encashment", leave_encashment.name, "additional_salary"))
def test_tax_for_payroll_period(self): data = {} # test the impact of tax exemption declaration, tax exemption proof submission # and deduct check boxes in annual tax calculation # as per assigned salary structure 40500 in monthly salary so 236000*5/100/12 frappe.db.sql("""delete from `tabPayroll Period`""") frappe.db.sql("""delete from `tabSalary Component`""") payroll_period = create_payroll_period() create_tax_slab(payroll_period) employee = make_employee("*****@*****.**") delete_docs = [ "Salary Slip", "Additional Salary", "Employee Tax Exemption Declaration", "Employee Tax Exemption Proof Submission", "Employee Benefit Claim", "Salary Structure Assignment" ] for doc in delete_docs: frappe.db.sql("delete from `tab%s` where employee='%s'" % (doc, employee)) from erpnext.hr.doctype.salary_structure.test_salary_structure import \ make_salary_structure, create_salary_structure_assignment salary_structure = make_salary_structure( "Stucture to test tax", "Monthly", other_details={"max_benefits": 100000}, test_tax=True) create_salary_structure_assignment(employee, salary_structure.name, payroll_period.start_date) # create salary slip for whole period deducting tax only on last period # to find the total tax amount paid create_salary_slips_for_payroll_period(employee, salary_structure.name, payroll_period, deduct_random=False) tax_paid = get_tax_paid_in_period(employee) # total taxable income 586000, 250000 @ 5%, 86000 @ 20% ie. 12500 + 17200 annual_tax = 113567.79 try: self.assertEqual(tax_paid, annual_tax) except AssertionError: print("\nSalary Slip - Annual tax calculation failed\n") raise frappe.db.sql("""delete from `tabSalary Slip` where employee=%s""", (employee)) # create exemption declaration so the tax amount varies create_exemption_declaration(employee, payroll_period.name) # create for payroll deducting in random months data["deducted_dates"] = create_salary_slips_for_payroll_period( employee, salary_structure.name, payroll_period) tax_paid = get_tax_paid_in_period(employee) # No proof, benefit claim sumitted, total tax paid, should not change try: self.assertEqual(tax_paid, annual_tax) except AssertionError: print("\nSalary Slip - Tax calculation failed on following case\n", data, "\n") raise # Submit proof for total 120000 data["proof-1"] = create_proof_submission(employee, payroll_period, 50000) data["proof-2"] = create_proof_submission(employee, payroll_period, 70000) # Submit benefit claim for total 50000 data["benefit-1"] = create_benefit_claim(employee, payroll_period, 15000, "Medical Allowance") data["benefit-2"] = create_benefit_claim(employee, payroll_period, 35000, "Leave Travel Allowance") frappe.db.sql("""delete from `tabSalary Slip` where employee=%s""", (employee)) data["deducted_dates"] = create_salary_slips_for_payroll_period( employee, salary_structure.name, payroll_period) tax_paid = get_tax_paid_in_period(employee) # total taxable income 416000, 166000 @ 5% ie. 8300 try: self.assertEqual(tax_paid, 88607.79) except AssertionError: print("\nSalary Slip - Tax calculation failed on following case\n", data, "\n") raise # create additional salary of 150000 frappe.db.sql("""delete from `tabSalary Slip` where employee=%s""", (employee)) data["additional-1"] = create_additional_salary( employee, payroll_period, 50000) data["additional-2"] = create_additional_salary( employee, payroll_period, 100000) data["deducted_dates"] = create_salary_slips_for_payroll_period( employee, salary_structure.name, payroll_period) # total taxable income 566000, 250000 @ 5%, 66000 @ 20%, 12500 + 13200 tax_paid = get_tax_paid_in_period(employee) try: self.assertEqual(tax_paid, 121211.48) except AssertionError: print("\nSalary Slip - Tax calculation failed on following case\n", data, "\n") raise frappe.db.sql( """delete from `tabAdditional Salary` where employee=%s""", (employee)) # undelete fixture data frappe.db.rollback()
def test_employee_loan(self): from erpnext.hr.doctype.salary_structure.test_salary_structure import ( make_employee, make_salary_structure) from erpnext.hr.doctype.employee_loan.test_employee_loan import create_employee_loan branch = "Test Employee Branch" employee = make_employee("*****@*****.**") company = erpnext.get_default_company() holiday_list = make_holiday("test holiday for loan") if not frappe.db.exists('Salary Component', 'Basic Salary'): frappe.get_doc({ 'doctype': 'Salary Component', 'salary_component': 'Basic Salary', 'salary_component_abbr': 'BS', 'type': 'Earning', 'accounts': [{ 'company': company, 'default_account': frappe.db.get_value( 'Account', { 'company': company, 'root_type': 'Expense', 'account_type': '' }, 'name') }] }).insert() if not frappe.db.get_value('Salary Component Account', { 'parent': 'Basic Salary', 'company': company }): salary_component = frappe.get_doc('Salary Component', 'Basic Salary') salary_component.append('accounts', { 'company': company, 'default_account': 'Salary - WP' }) 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): frappe.get_doc({'doctype': 'Branch', 'branch': branch}).insert() employee_doc = frappe.get_doc('Employee', employee) employee_doc.branch = branch employee_doc.holiday_list = holiday_list employee_doc.save() employee_loan = create_employee_loan(employee, "Personal Loan", 280000, "Repay Over Number of Periods", 20) employee_loan.repay_from_salary = 1 employee_loan.submit() salary_strcture = "Test Salary Structure for Loan" if not frappe.db.exists('Salary Structure', salary_strcture): salary_strcture = make_salary_structure( salary_strcture, [{ 'employee': employee, 'from_date': '2017-01-01', 'base': 30000 }]) salary_strcture = frappe.get_doc('Salary Structure', salary_strcture) salary_strcture.set('earnings', [{ 'salary_component': 'Basic Salary', 'abbr': 'BS', 'amount_based_on_formula': 1, 'formula': 'base*.5' }]) salary_strcture.save() dates = get_start_end_dates('Monthly', nowdate()) make_process_payroll(start_date=dates.start_date, end_date=dates.end_date, branch=branch) name = frappe.db.get_value('Salary Slip', { 'posting_date': nowdate(), 'employee': employee }, 'name') salary_slip = frappe.get_doc('Salary Slip', name) for row in salary_slip.loans: if row.employee_loan == employee_loan.name: interest_amount = (280000 * 8.4) / (12 * 100) principal_amount = employee_loan.monthly_repayment_amount - interest_amount self.assertEqual(row.interest_amount, interest_amount) self.assertEqual(row.principal_amount, principal_amount) self.assertEqual(row.total_payment, interest_amount + principal_amount) if salary_slip.docstatus == 0: frappe.delete_doc('Salary Slip', name) employee_loan.cancel() frappe.delete_doc('Employee Loan', employee_loan.name)
def test_tax_for_payroll_period(self): data = {} # test the impact of tax exemption declaration, tax exemption proof submission # and deduct check boxes in annual tax calculation # as per assigned salary structure 40500 in monthly salary so 236000*5/100/12 frappe.db.sql("""delete from `tabPayroll Period`""") frappe.db.sql("""delete from `tabSalary Component`""") payroll_period = create_payroll_period() create_tax_slab(payroll_period) employee = make_employee("*****@*****.**") delete_docs = [ "Salary Slip", "Additional Salary", "Employee Tax Exemption Declaration", "Employee Tax Exemption Proof Submission", "Employee Benefit Claim", "Salary Structure Assignment" ] for doc in delete_docs: frappe.db.sql("delete from `tab%s` where employee='%s'" % (doc, employee)) from erpnext.hr.doctype.salary_structure.test_salary_structure import \ make_salary_structure, create_salary_structure_assignment salary_structure = make_salary_structure("Stucture to test tax", "Monthly", other_details={"max_benefits": 100000}, test_tax=True) create_salary_structure_assignment(employee, salary_structure.name, payroll_period.start_date) # create salary slip for whole period deducting tax only on last period # to find the total tax amount paid create_salary_slips_for_payroll_period(employee, salary_structure.name, payroll_period, deduct_random=False) tax_paid = get_tax_paid_in_period(employee) # total taxable income 586000, 250000 @ 5%, 86000 @ 20% ie. 12500 + 17200 annual_tax = 29700 try: self.assertEqual(tax_paid, annual_tax) except AssertionError: print("\nSalary Slip - Annual tax calculation failed\n") raise frappe.db.sql("""delete from `tabSalary Slip` where employee=%s""", (employee)) # create exemption declaration so the tax amount varies create_exemption_declaration(employee, payroll_period.name) # create for payroll deducting in random months data["deducted_dates"] = create_salary_slips_for_payroll_period(employee, salary_structure.name, payroll_period) tax_paid = get_tax_paid_in_period(employee) # No proof, benefit claim sumitted, total tax paid, should not change try: self.assertEqual(tax_paid, annual_tax) except AssertionError: print("\nSalary Slip - Tax calculation failed on following case\n", data, "\n") raise # Submit proof for total 120000 data["proof-1"] = create_proof_submission(employee, payroll_period, 50000) data["proof-2"] = create_proof_submission(employee, payroll_period, 70000) # Submit benefit claim for total 50000 data["benefit-1"] = create_benefit_claim(employee, payroll_period, 15000, "Medical Allowance") data["benefit-2"] = create_benefit_claim(employee, payroll_period, 35000, "Leave Travel Allowance") frappe.db.sql("""delete from `tabSalary Slip` where employee=%s""", (employee)) data["deducted_dates"] = create_salary_slips_for_payroll_period(employee, salary_structure.name, payroll_period) tax_paid = get_tax_paid_in_period(employee) # total taxable income 416000, 166000 @ 5% ie. 8300 try: self.assertEqual(tax_paid, 8300) except AssertionError: print("\nSalary Slip - Tax calculation failed on following case\n", data, "\n") raise # create additional salary of 150000 frappe.db.sql("""delete from `tabSalary Slip` where employee=%s""", (employee)) data["additional-1"] = create_additional_salary(employee, payroll_period, 50000) data["additional-2"] = create_additional_salary(employee, payroll_period, 100000) data["deducted_dates"] = create_salary_slips_for_payroll_period(employee, salary_structure.name, payroll_period) # total taxable income 566000, 250000 @ 5%, 66000 @ 20%, 12500 + 13200 tax_paid = get_tax_paid_in_period(employee) try: self.assertEqual(tax_paid, 25700) except AssertionError: print("\nSalary Slip - Tax calculation failed on following case\n", data, "\n") raise frappe.db.sql("""delete from `tabAdditional Salary` where employee=%s""", (employee)) # undelete fixture data frappe.db.rollback()
def test_employee_loan(self): from erpnext.hr.doctype.salary_structure.test_salary_structure import (make_employee, make_salary_structure) from erpnext.hr.doctype.employee_loan.test_employee_loan import create_employee_loan branch = "Test Employee Branch" employee = make_employee("*****@*****.**") company = erpnext.get_default_company() holiday_list = make_holiday("test holiday for loan") if not frappe.db.exists('Salary Component', 'Basic Salary'): frappe.get_doc({ 'doctype': 'Salary Component', 'salary_component': 'Basic Salary', 'salary_component_abbr': 'BS', 'type': 'Earning', 'accounts': [{ 'company': company, 'default_account': frappe.db.get_value('Account', {'company': company, 'root_type': 'Expense', 'account_type': ''}, 'name') }] }).insert() if not frappe.db.get_value('Salary Component Account', {'parent': 'Basic Salary', 'company': company}): salary_component = frappe.get_doc('Salary Component', 'Basic Salary') salary_component.append('accounts', { 'company': company, 'default_account': 'Salary - WP' }) 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): frappe.get_doc({ 'doctype': 'Branch', 'branch': branch }).insert() employee_doc = frappe.get_doc('Employee', employee) employee_doc.branch = branch employee_doc.holiday_list = holiday_list employee_doc.save() employee_loan = create_employee_loan(employee, "Personal Loan", 280000, "Repay Over Number of Periods", 20) employee_loan.repay_from_salary = 1 employee_loan.submit() salary_strcture = "Test Salary Structure for Loan" if not frappe.db.exists('Salary Structure', salary_strcture): salary_strcture = make_salary_structure(salary_strcture, [{ 'employee': employee, 'from_date': '2017-01-01', 'base': 30000 }]) salary_strcture = frappe.get_doc('Salary Structure', salary_strcture) salary_strcture.set('earnings', [{ 'salary_component': 'Basic Salary', 'abbr': 'BS', 'amount_based_on_formula':1, 'formula': 'base*.5' }]) salary_strcture.save() dates = get_start_end_dates('Monthly', nowdate()) make_payroll_entry(start_date=dates.start_date, end_date=dates.end_date, branch=branch) name = frappe.db.get_value('Salary Slip', {'posting_date': nowdate(), 'employee': employee}, 'name') salary_slip = frappe.get_doc('Salary Slip', name) for row in salary_slip.loans: if row.employee_loan == employee_loan.name: interest_amount = (280000 * 8.4)/(12*100) principal_amount = employee_loan.monthly_repayment_amount - interest_amount self.assertEqual(row.interest_amount, interest_amount) self.assertEqual(row.principal_amount, principal_amount) self.assertEqual(row.total_payment, interest_amount + principal_amount) if salary_slip.docstatus == 0: frappe.delete_doc('Salary Slip', name) employee_loan.cancel() frappe.delete_doc('Employee Loan', employee_loan.name)