Skip to content

Commit

Permalink
Merge pull request #1047 from frappe/mergify/bp/version-14-hotfix/pr-…
Browse files Browse the repository at this point in the history
…1046

refactor: allow repost for `Expense Claim` (backport #1046)
  • Loading branch information
ruchamahabal authored Nov 7, 2023
2 parents 84fbd96 + 972017a commit 66bca1e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
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 @@ -9,6 +9,7 @@ hrms.patches.post_install.update_performance_module_changes #2023-04-17
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.v14_0.update_repay_from_salary_and_payroll_payable_account_fields
hrms.patches.v14_0.create_custom_field_in_loan
hrms.patches.v14_0.update_loan_repayment_repay_from_salary
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()

0 comments on commit 66bca1e

Please sign in to comment.