mirror of
https://github.com/frappe/erpnext.git
synced 2026-10-29 22:57:42 +00:00
test(accounts): cover employee journal reconciliation
(cherry picked from commit 8c72d0fc5e)
# Conflicts:
# erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py
This commit is contained in:
@@ -16,9 +16,14 @@ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sal
|
||||
from erpnext.accounts.party import get_party_account
|
||||
from erpnext.accounts.utils import get_fiscal_year
|
||||
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
|
||||
<<<<<<< HEAD
|
||||
from erpnext.stock.doctype.item.test_item import create_item
|
||||
|
||||
test_dependencies = ["Item"]
|
||||
=======
|
||||
from erpnext.setup.doctype.employee.test_employee import make_employee
|
||||
from erpnext.tests.utils import ERPNextTestSuite
|
||||
>>>>>>> 8c72d0f (test(accounts): cover employee journal reconciliation)
|
||||
|
||||
|
||||
class TestPaymentReconciliation(FrappeTestCase):
|
||||
@@ -333,9 +338,36 @@ class TestPaymentReconciliation(FrappeTestCase):
|
||||
)
|
||||
return je
|
||||
|
||||
<<<<<<< HEAD
|
||||
def create_cost_center(self):
|
||||
# Setup cost center
|
||||
cc_name = "Sub"
|
||||
=======
|
||||
def create_employee_journal_entry(self, account, employee, amount, exchange_rate):
|
||||
journal = self.create_journal_entry(account, self.bank, amount)
|
||||
journal.multi_currency = exchange_rate != 1
|
||||
journal.accounts[0].party_type = "Employee"
|
||||
journal.accounts[0].party = employee
|
||||
journal.accounts[0].exchange_rate = exchange_rate
|
||||
journal.accounts[1].debit_in_account_currency *= exchange_rate
|
||||
journal.accounts[1].credit_in_account_currency *= exchange_rate
|
||||
return journal
|
||||
|
||||
def setup_split_exchange_accounts(self):
|
||||
gain_account = create_account(
|
||||
account_name="_Test PR Split Exchange Gain",
|
||||
parent_account="Indirect Expenses - _TC",
|
||||
company=self.company,
|
||||
)
|
||||
loss_account = create_account(
|
||||
account_name="_Test PR Split Exchange Loss",
|
||||
parent_account="Indirect Expenses - _TC",
|
||||
company=self.company,
|
||||
)
|
||||
frappe.db.set_value("Company", self.company, "exchange_gain_account", gain_account)
|
||||
frappe.db.set_value("Company", self.company, "exchange_loss_account", loss_account)
|
||||
return gain_account, loss_account
|
||||
>>>>>>> 8c72d0f (test(accounts): cover employee journal reconciliation)
|
||||
|
||||
self.main_cc = frappe.get_doc("Cost Center", get_default_cost_center(self.company))
|
||||
|
||||
@@ -697,6 +729,110 @@ class TestPaymentReconciliation(FrappeTestCase):
|
||||
self.assertEqual(len(pr.get("invoices")), 0)
|
||||
self.assertEqual(len(pr.get("payments")), 0)
|
||||
|
||||
def test_employee_journals_use_selected_account_type(self):
|
||||
gain_account, loss_account = self.setup_split_exchange_accounts()
|
||||
cases = (
|
||||
(self.debit_to, 7500, 1, 1, None),
|
||||
(self.creditors, -7500, 1, 1, None),
|
||||
(self.debtors_usd, 7500, 80, 85, gain_account),
|
||||
(self.debtors_usd, 7500, 85, 80, loss_account),
|
||||
(self.creditors_usd, -7500, 80, 85, loss_account),
|
||||
(self.creditors_usd, -7500, 85, 80, gain_account),
|
||||
)
|
||||
|
||||
for index, (account, amount, invoice_rate, payment_rate, difference_account) in enumerate(cases):
|
||||
with self.subTest(account=account, invoice_rate=invoice_rate, payment_rate=payment_rate):
|
||||
employee = make_employee(
|
||||
f"test_payment_reconciliation_employee_{index}@example.com", company=self.company
|
||||
)
|
||||
invoice = self.create_employee_journal_entry(account, employee, amount, invoice_rate)
|
||||
invoice.insert().submit()
|
||||
|
||||
pr = frappe.new_doc("Payment Reconciliation")
|
||||
pr.company = self.company
|
||||
pr.party_type = "Employee"
|
||||
pr.party = employee
|
||||
pr.receivable_payable_account = account
|
||||
pr.get_unreconciled_entries()
|
||||
self.assertEqual(
|
||||
[(row.invoice_number, row.outstanding_amount) for row in pr.invoices],
|
||||
[(invoice.name, 7500)],
|
||||
)
|
||||
self.assertFalse(pr.payments)
|
||||
|
||||
settlement = self.create_employee_journal_entry(account, employee, -amount, invoice_rate)
|
||||
settlement.accounts[0].reference_type = "Journal Entry"
|
||||
settlement.accounts[0].reference_name = invoice.name
|
||||
settlement.insert().submit()
|
||||
pr.get_unreconciled_entries()
|
||||
self.assertFalse(pr.invoices)
|
||||
self.assertFalse(pr.payments)
|
||||
|
||||
settlement.cancel()
|
||||
pr.get_unreconciled_entries()
|
||||
self.assertEqual(pr.invoices[0].outstanding_amount, 7500)
|
||||
self.assertFalse(pr.payments)
|
||||
|
||||
payment = self.create_employee_journal_entry(account, employee, -amount / 3, payment_rate)
|
||||
payment.insert().submit()
|
||||
pr.get_unreconciled_entries()
|
||||
self.assertEqual(
|
||||
[(row.reference_name, row.amount) for row in pr.payments], [(payment.name, 2500)]
|
||||
)
|
||||
pr.allocate_entries(
|
||||
{
|
||||
"invoices": [row.as_dict() for row in pr.invoices],
|
||||
"payments": [row.as_dict() for row in pr.payments],
|
||||
}
|
||||
)
|
||||
self.assertEqual(pr.allocation[0].difference_amount, 2500 * (payment_rate - invoice_rate))
|
||||
if difference_account:
|
||||
self.assertEqual(pr.allocation[0].difference_account, difference_account)
|
||||
pr.reconcile()
|
||||
self.assertEqual(pr.invoices[0].outstanding_amount, 5000)
|
||||
self.assertFalse(pr.payments)
|
||||
party_gl_entries = frappe.get_all(
|
||||
"GL Entry",
|
||||
filters={
|
||||
"account": account,
|
||||
"party_type": "Employee",
|
||||
"party": employee,
|
||||
"is_cancelled": 0,
|
||||
},
|
||||
fields=["debit", "credit"],
|
||||
)
|
||||
self.assertEqual(
|
||||
sum(row.debit - row.credit for row in party_gl_entries),
|
||||
(amount - amount / 3) * invoice_rate,
|
||||
)
|
||||
self.assertEqual(
|
||||
frappe.db.get_value(
|
||||
"Payment Ledger Entry",
|
||||
{"account": account, "party_type": "Employee", "party": employee, "delinked": 0},
|
||||
[{"SUM": "amount_in_account_currency"}],
|
||||
),
|
||||
5000,
|
||||
)
|
||||
|
||||
payment.reload().cancel()
|
||||
pr.get_unreconciled_entries()
|
||||
self.assertEqual(pr.invoices[0].outstanding_amount, 7500)
|
||||
self.assertFalse(pr.payments)
|
||||
party_gl_entries = frappe.get_all(
|
||||
"GL Entry",
|
||||
filters={
|
||||
"account": account,
|
||||
"party_type": "Employee",
|
||||
"party": employee,
|
||||
"is_cancelled": 0,
|
||||
},
|
||||
fields=["debit", "credit"],
|
||||
)
|
||||
self.assertEqual(
|
||||
sum(row.debit - row.credit for row in party_gl_entries),
|
||||
amount * invoice_rate,
|
||||
)
|
||||
|
||||
def test_journal_against_journal(self):
|
||||
transaction_date = nowdate()
|
||||
sales = "Sales - _PR"
|
||||
|
||||
Reference in New Issue
Block a user