diff --git a/hrms/hr/doctype/expense_claim/test_expense_claim.py b/hrms/hr/doctype/expense_claim/test_expense_claim.py index 6fd9959ec1..b4f99c0714 100644 --- a/hrms/hr/doctype/expense_claim/test_expense_claim.py +++ b/hrms/hr/doctype/expense_claim/test_expense_claim.py @@ -516,6 +516,61 @@ def test_rounding(self): expense_claim.reload() self.assertEqual(expense_claim.status, "Unpaid") + def test_repost(self): + # Update repost settings + allowed_types = ["Expense Claim"] + repost_settings = frappe.get_doc("Repost Accounting Ledger Settings") + for x in allowed_types: + repost_settings.append("allowed_types", {"document_type": x, "allowed": True}) + repost_settings.save() + + payable_account = get_payable_account(company_name) + taxes = generate_taxes(rate=10) + expense_claim = make_expense_claim( + payable_account, + 100, + 100, + company_name, + "Travel Expenses - _TC3", + taxes=taxes, + ) + expected_data = [{"total_debit": 110.0, "total_credit": 110.0}] + + # assert ledger entries + ledger_balance = frappe.db.get_all( + "GL Entry", + filters={"voucher_no": expense_claim.name, "is_cancelled": 0}, + fields=["sum(debit) as total_debit", "sum(credit) as total_credit"], + ) + self.assertEqual(ledger_balance, expected_data) + + gl_entries = frappe.db.get_all( + "GL Entry", filters={"account": expense_claim.payable_account, "voucher_no": expense_claim.name} + ) + self.assertEqual(len(gl_entries), 1) + frappe.db.set_value("GL Entry", gl_entries[0].name, "credit", 0) + + ledger_balance = frappe.db.get_all( + "GL Entry", + filters={"voucher_no": expense_claim.name, "is_cancelled": 0}, + fields=["sum(debit) as total_debit", "sum(credit) as total_credit"], + ) + self.assertNotEqual(ledger_balance, expected_data) + + # Do a repost + repost_doc = frappe.new_doc("Repost Accounting Ledger") + repost_doc.company = expense_claim.company + repost_doc.append( + "vouchers", {"voucher_type": expense_claim.doctype, "voucher_no": expense_claim.name} + ) + repost_doc.save().submit() + ledger_balance = frappe.db.get_all( + "GL Entry", + filters={"voucher_no": expense_claim.name, "is_cancelled": 0}, + fields=["sum(debit) as total_debit", "sum(credit) as total_credit"], + ) + self.assertEqual(ledger_balance, expected_data) + def get_payable_account(company): return frappe.get_cached_value("Company", company, "default_payable_account") diff --git a/hrms/patches.txt b/hrms/patches.txt index c424a4b377..69c68ce1a7 100644 --- a/hrms/patches.txt +++ b/hrms/patches.txt @@ -11,6 +11,7 @@ hrms.patches.v14_0.update_payroll_frequency_to_none_if_salary_slip_is_based_on_t hrms.patches.v14_0.update_ess_user_access #2023-08-14 execute:frappe.db.set_default("date_format", frappe.db.get_single_value("System Settings", "date_format")) hrms.patches.v14_0.create_vehicle_service_item +hrms.patches.v14_0.add_expense_claim_to_repost_settings hrms.patches.v15_0.notify_about_loan_app_separation hrms.patches.v15_0.rename_enable_late_entry_early_exit_grace_period hrms.patches.v14_0.update_repay_from_salary_and_payroll_payable_account_fields diff --git a/hrms/patches/v14_0/add_expense_claim_to_repost_settings.py b/hrms/patches/v14_0/add_expense_claim_to_repost_settings.py new file mode 100644 index 0000000000..827ddb75bc --- /dev/null +++ b/hrms/patches/v14_0/add_expense_claim_to_repost_settings.py @@ -0,0 +1,12 @@ +import frappe + + +def execute(): + """ + Add `Expense Claim` to Repost settings + """ + allowed_types = ["Expense Claim"] + repost_settings = frappe.get_doc("Repost Accounting Ledger Settings") + for x in allowed_types: + repost_settings.append("allowed_types", {"document_type": x, "allowed": True}) + repost_settings.save()