Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: allow repost for Expense Claim #1046

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions hrms/hr/doctype/expense_claim/test_expense_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions hrms/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions hrms/patches/v14_0/add_expense_claim_to_repost_settings.py
Original file line number Diff line number Diff line change
@@ -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()
Loading