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}) company_doc = frappe.get_doc("Company", company) make_salary_structure( "_Test Salary Structure", "Monthly", employee, company=company, currency=company_doc.default_currency, ) 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, payable_account=company_doc.default_payroll_payable_account, currency=company_doc.default_currency, )
def test_multi_currency_payroll_entry(self): # pylint: disable=no-self-use company = erpnext.get_default_company() employee = make_employee("*****@*****.**", company=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) company_doc = frappe.get_doc('Company', company) salary_structure = make_salary_structure( "_Test Multi Currency Salary Structure", "Monthly", company=company, currency='USD') create_salary_structure_assignment(employee, salary_structure.name, company=company, currency='USD') frappe.db.sql( """delete from `tabSalary Slip` where employee=%s""", (frappe.db.get_value( "Employee", {"user_id": "*****@*****.**"}))) salary_slip = get_salary_slip( "*****@*****.**", "Monthly", "_Test Multi Currency Salary Structure") dates = get_start_end_dates('Monthly', nowdate()) payroll_entry = make_payroll_entry( start_date=dates.start_date, end_date=dates.end_date, payable_account=company_doc.default_payroll_payable_account, currency='USD', exchange_rate=70) payroll_entry.make_payment_entry() salary_slip.load_from_db() payroll_je = salary_slip.journal_entry if payroll_je: payroll_je_doc = frappe.get_doc('Journal Entry', payroll_je) self.assertEqual(salary_slip.base_gross_pay, payroll_je_doc.total_debit) self.assertEqual(salary_slip.base_gross_pay, payroll_je_doc.total_credit) payment_entry = frappe.db.sql(''' Select ifnull(sum(je.total_debit),0) as total_debit, ifnull(sum(je.total_credit),0) as total_credit from `tabJournal Entry` je, `tabJournal Entry Account` jea Where je.name = jea.parent And jea.reference_name = %s ''', (payroll_entry.name), as_dict=1) self.assertEqual(salary_slip.base_net_pay, payment_entry[0].total_debit) self.assertEqual(salary_slip.base_net_pay, payment_entry[0].total_credit)
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() frappe.db.sql("""delete from `tabEmployee` where employee_name='*****@*****.**' """) frappe.db.sql("""delete from `tabEmployee` where employee_name='*****@*****.**' """) 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("*****@*****.**", 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") 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") 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) make_salary_structure("_Test Salary Structure 2", "Monthly", employee2, company="_Test Company", currency=currency, test_tax=False) 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, payable_account="_Test Payroll Payable - _TC", currency=frappe.db.get_value("Company", "_Test Company", "default_currency"), 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 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, company=company) 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_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() frappe.db.sql( """delete from `tabEmployee` where employee_name='*****@*****.**' """ ) frappe.db.sql( """delete from `tabEmployee` where employee_name='*****@*****.**' """ ) 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( "*****@*****.**", payroll_cost_center="_Test Cost Center - _TC", department="cc - _TC", company="_Test Company", ) employee2 = make_employee("*****@*****.**", department="cc - _TC", 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", 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( "_Test Salary Structure 2", "Monthly", employee2, company="_Test Company", currency=currency, test_tax=False, ) # update cost centers in salary structure assignment for employee2 ssa = frappe.db.get_value( "Salary Structure Assignment", { "employee": employee2, "salary_structure": ss.name, "docstatus": 1 }, "name", ) ssa_doc = frappe.get_doc("Salary Structure Assignment", ssa) ssa_doc.payroll_cost_centers = [] ssa_doc.append("payroll_cost_centers", { "cost_center": "_Test Cost Center - _TC", "percentage": 60 }) ssa_doc.append("payroll_cost_centers", { "cost_center": "_Test Cost Center 2 - _TC", "percentage": 40 }) ssa_doc.save() 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, payable_account="_Test Payroll Payable - _TC", currency=frappe.db.get_value("Company", "_Test Company", "default_currency"), 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", 124800.0, 0.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)