mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 07:54:46 +00:00
test: advance payment against reverse payment reconciliation
This commit is contained in:
@@ -101,6 +101,14 @@ class TestPaymentReconciliation(FrappeTestCase):
|
|||||||
"account_currency": "USD",
|
"account_currency": "USD",
|
||||||
"account_type": "Payable",
|
"account_type": "Payable",
|
||||||
},
|
},
|
||||||
|
# 'Payable' account for capturing advance paid, under 'Assets' group
|
||||||
|
{
|
||||||
|
"attribute": "advance_payable_account",
|
||||||
|
"account_name": "Advance Paid",
|
||||||
|
"parent_account": "Current Assets - _PR",
|
||||||
|
"account_currency": "INR",
|
||||||
|
"account_type": "Payable",
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
for x in accounts:
|
for x in accounts:
|
||||||
@@ -1388,6 +1396,135 @@ class TestPaymentReconciliation(FrappeTestCase):
|
|||||||
# There should be no Exchange Gain/Loss created
|
# There should be no Exchange Gain/Loss created
|
||||||
self.assertEqual(journals, [])
|
self.assertEqual(journals, [])
|
||||||
|
|
||||||
|
def test_advance_reverse_payment_against_payment_for_supplier(self):
|
||||||
|
"""
|
||||||
|
Reconcile an Advance payment against reverse payment, for a supplier.
|
||||||
|
"""
|
||||||
|
frappe.db.set_value(
|
||||||
|
"Company",
|
||||||
|
self.company,
|
||||||
|
{
|
||||||
|
"book_advance_payments_in_separate_party_account": 1,
|
||||||
|
"default_advance_paid_account": self.advance_payable_account,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
self.supplier = "_Test Supplier"
|
||||||
|
amount = 4000
|
||||||
|
|
||||||
|
pe = self.create_payment_entry(amount=amount)
|
||||||
|
pe.party_type = "Supplier"
|
||||||
|
pe.party = self.supplier
|
||||||
|
pe.payment_type = "Pay"
|
||||||
|
pe.paid_from = self.cash
|
||||||
|
pe.paid_to = self.advance_payable_account
|
||||||
|
pe.save().submit()
|
||||||
|
|
||||||
|
reverse_pe = self.create_payment_entry(amount=amount)
|
||||||
|
reverse_pe.party_type = "Supplier"
|
||||||
|
reverse_pe.party = self.supplier
|
||||||
|
reverse_pe.payment_type = "Receive"
|
||||||
|
reverse_pe.paid_from = self.advance_payable_account
|
||||||
|
reverse_pe.paid_to = self.cash
|
||||||
|
reverse_pe.save().submit()
|
||||||
|
|
||||||
|
pr = self.create_payment_reconciliation(party_is_customer=False)
|
||||||
|
pr.default_advance_account = self.advance_payable_account
|
||||||
|
pr.get_unreconciled_entries()
|
||||||
|
self.assertEqual(len(pr.invoices), 1)
|
||||||
|
self.assertEqual(len(pr.payments), 1)
|
||||||
|
self.assertEqual(pr.invoices[0].invoice_number, reverse_pe.name)
|
||||||
|
self.assertEqual(pr.payments[0].reference_name, pe.name)
|
||||||
|
|
||||||
|
invoices = [invoice.as_dict() for invoice in pr.invoices]
|
||||||
|
payments = [payment.as_dict() for payment in pr.payments]
|
||||||
|
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
|
||||||
|
pr.reconcile()
|
||||||
|
|
||||||
|
pe.reload()
|
||||||
|
self.assertEqual(len(pe.references), 1)
|
||||||
|
self.assertEqual(pe.references[0].exchange_rate, 1)
|
||||||
|
# There should not be any Exc Gain/Loss
|
||||||
|
self.assertEqual(pe.references[0].exchange_gain_loss, 0)
|
||||||
|
self.assertEqual(pe.references[0].reference_name, reverse_pe.name)
|
||||||
|
|
||||||
|
journals = frappe.db.get_all(
|
||||||
|
"Journal Entry",
|
||||||
|
filters={
|
||||||
|
"voucher_type": "Exchange Gain Or Loss",
|
||||||
|
"reference_type": "Payment Entry",
|
||||||
|
"reference_name": ("in", [pe.name, reverse_pe.name]),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
# There should be no Exchange Gain/Loss created
|
||||||
|
self.assertEqual(journals, [])
|
||||||
|
|
||||||
|
# Assert Ledger Entries
|
||||||
|
gl_entries = frappe.db.get_all(
|
||||||
|
"GL Entry",
|
||||||
|
filters={"voucher_no": pe.name},
|
||||||
|
fields=["account", "voucher_no", "against_voucher", "debit", "credit"],
|
||||||
|
order_by="account, against_voucher, debit",
|
||||||
|
)
|
||||||
|
expected_gle = [
|
||||||
|
{
|
||||||
|
"account": self.advance_payable_account,
|
||||||
|
"voucher_no": pe.name,
|
||||||
|
"against_voucher": pe.name,
|
||||||
|
"debit": 0.0,
|
||||||
|
"credit": amount,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account": self.advance_payable_account,
|
||||||
|
"voucher_no": pe.name,
|
||||||
|
"against_voucher": pe.name,
|
||||||
|
"debit": amount,
|
||||||
|
"credit": 0.0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account": self.advance_payable_account,
|
||||||
|
"voucher_no": pe.name,
|
||||||
|
"against_voucher": reverse_pe.name,
|
||||||
|
"debit": amount,
|
||||||
|
"credit": 0.0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account": "Cash - _PR",
|
||||||
|
"voucher_no": pe.name,
|
||||||
|
"against_voucher": None,
|
||||||
|
"debit": 0.0,
|
||||||
|
"credit": amount,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
self.assertEqual(gl_entries, expected_gle)
|
||||||
|
pl_entries = frappe.db.get_all(
|
||||||
|
"Payment Ledger Entry",
|
||||||
|
filters={"voucher_no": pe.name},
|
||||||
|
fields=["account", "voucher_no", "against_voucher_no", "amount"],
|
||||||
|
order_by="account, against_voucher_no, amount",
|
||||||
|
)
|
||||||
|
expected_ple = [
|
||||||
|
{
|
||||||
|
"account": self.advance_payable_account,
|
||||||
|
"voucher_no": pe.name,
|
||||||
|
"against_voucher_no": pe.name,
|
||||||
|
"amount": -amount,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account": self.advance_payable_account,
|
||||||
|
"voucher_no": pe.name,
|
||||||
|
"against_voucher_no": pe.name,
|
||||||
|
"amount": amount,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account": self.advance_payable_account,
|
||||||
|
"voucher_no": pe.name,
|
||||||
|
"against_voucher_no": reverse_pe.name,
|
||||||
|
"amount": -amount,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
self.assertEqual(pl_entries, expected_ple)
|
||||||
|
|
||||||
|
|
||||||
def make_customer(customer_name, currency=None):
|
def make_customer(customer_name, currency=None):
|
||||||
if not frappe.db.exists("Customer", customer_name):
|
if not frappe.db.exists("Customer", customer_name):
|
||||||
|
|||||||
Reference in New Issue
Block a user