mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 19:59:12 +00:00
Merge pull request #51453 from khushi8112/payment-entry-gl-merge
fix(payment_entry): merge GL entries with similar account heads based on setting
This commit is contained in:
@@ -1285,8 +1285,11 @@ class PaymentEntry(AccountsController):
|
|||||||
|
|
||||||
def make_gl_entries(self, cancel=0, adv_adj=0):
|
def make_gl_entries(self, cancel=0, adv_adj=0):
|
||||||
gl_entries = self.build_gl_map()
|
gl_entries = self.build_gl_map()
|
||||||
gl_entries = process_gl_map(gl_entries)
|
|
||||||
make_gl_entries(gl_entries, cancel=cancel, adv_adj=adv_adj)
|
merge_entries = frappe.get_single_value("Accounts Settings", "merge_similar_account_heads")
|
||||||
|
|
||||||
|
gl_entries = process_gl_map(gl_entries, merge_entries=merge_entries)
|
||||||
|
make_gl_entries(gl_entries, cancel=cancel, adv_adj=adv_adj, merge_entries=merge_entries)
|
||||||
if cancel:
|
if cancel:
|
||||||
cancel_exchange_gain_loss_journal(frappe._dict(doctype=self.doctype, name=self.name))
|
cancel_exchange_gain_loss_journal(frappe._dict(doctype=self.doctype, name=self.name))
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1045,6 +1045,7 @@ class TestPaymentEntry(IntegrationTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_gl_of_multi_currency_payment_with_taxes(self):
|
def test_gl_of_multi_currency_payment_with_taxes(self):
|
||||||
|
frappe.db.set_single_value("Accounts Settings", "merge_similar_account_heads", 1)
|
||||||
payment_entry = create_payment_entry(
|
payment_entry = create_payment_entry(
|
||||||
party="_Test Supplier USD", paid_to="_Test Payable USD - _TC", save=True
|
party="_Test Supplier USD", paid_to="_Test Payable USD - _TC", save=True
|
||||||
)
|
)
|
||||||
@@ -1606,6 +1607,96 @@ class TestPaymentEntry(IntegrationTestCase):
|
|||||||
self.voucher_no = pe.name
|
self.voucher_no = pe.name
|
||||||
self.check_gl_entries()
|
self.check_gl_entries()
|
||||||
|
|
||||||
|
def test_payment_entry_merges_gl_entries_with_same_account_head(self):
|
||||||
|
"""
|
||||||
|
Test that Payment Entry merges GL entries with same account head
|
||||||
|
when 'Merge Similar Account Heads' setting is enabled.
|
||||||
|
"""
|
||||||
|
frappe.db.set_single_value("Accounts Settings", "merge_similar_account_heads", 1)
|
||||||
|
|
||||||
|
pe = create_payment_entry(
|
||||||
|
party_type="Supplier",
|
||||||
|
party="_Test Supplier",
|
||||||
|
paid_from="_Test Bank - _TC",
|
||||||
|
paid_to="Creditors - _TC",
|
||||||
|
)
|
||||||
|
|
||||||
|
pe.append(
|
||||||
|
"deductions",
|
||||||
|
{
|
||||||
|
"account": "Write Off - _TC",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"amount": 50,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
pe.append(
|
||||||
|
"deductions",
|
||||||
|
{
|
||||||
|
"account": "Write Off - _TC",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"amount": 30,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
pe.save()
|
||||||
|
pe.submit()
|
||||||
|
|
||||||
|
gl_entries = frappe.db.get_all(
|
||||||
|
"GL Entry",
|
||||||
|
filters={"voucher_no": pe.name, "account": "Write Off - _TC", "is_cancelled": 0},
|
||||||
|
fields=["debit", "credit"],
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(len(gl_entries), 1)
|
||||||
|
self.assertEqual(gl_entries[0].debit, 80)
|
||||||
|
|
||||||
|
def test_payment_entry_does_not_merge_gl_entries_when_setting_disabled(self):
|
||||||
|
"""
|
||||||
|
Test that Payment Entry does NOT merge GL entries
|
||||||
|
when 'Merge Similar Account Heads' is disabled.
|
||||||
|
"""
|
||||||
|
|
||||||
|
frappe.db.set_single_value("Accounts Settings", "merge_similar_account_heads", 0)
|
||||||
|
|
||||||
|
pe = create_payment_entry(
|
||||||
|
party_type="Supplier",
|
||||||
|
party="_Test Supplier",
|
||||||
|
paid_from="_Test Bank - _TC",
|
||||||
|
paid_to="Creditors - _TC",
|
||||||
|
)
|
||||||
|
|
||||||
|
pe.append(
|
||||||
|
"deductions",
|
||||||
|
{
|
||||||
|
"account": "Write Off - _TC",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"amount": 50,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
pe.append(
|
||||||
|
"deductions",
|
||||||
|
{
|
||||||
|
"account": "Write Off - _TC",
|
||||||
|
"cost_center": "_Test Cost Center - _TC",
|
||||||
|
"amount": 30,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
pe.save()
|
||||||
|
pe.submit()
|
||||||
|
|
||||||
|
gl_entries = frappe.db.get_all(
|
||||||
|
"GL Entry",
|
||||||
|
filters={"voucher_no": pe.name, "account": "Write Off - _TC", "is_cancelled": 0},
|
||||||
|
fields=["debit", "credit"],
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(len(gl_entries), 2)
|
||||||
|
|
||||||
|
frappe.db.set_single_value("Accounts Settings", "merge_similar_account_heads", 1)
|
||||||
|
|
||||||
def check_pl_entries(self):
|
def check_pl_entries(self):
|
||||||
ple = frappe.qb.DocType("Payment Ledger Entry")
|
ple = frappe.qb.DocType("Payment Ledger Entry")
|
||||||
pl_entries = (
|
pl_entries = (
|
||||||
|
|||||||
@@ -1498,6 +1498,8 @@ class TestPurchaseInvoice(IntegrationTestCase, StockTestMixin):
|
|||||||
def test_purchase_invoice_advance_taxes(self):
|
def test_purchase_invoice_advance_taxes(self):
|
||||||
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
|
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
|
||||||
|
|
||||||
|
frappe.db.set_single_value("Accounts Settings", "merge_similar_account_heads", 1)
|
||||||
|
|
||||||
company = "_Test Company"
|
company = "_Test Company"
|
||||||
|
|
||||||
tds_account_args = {
|
tds_account_args = {
|
||||||
|
|||||||
Reference in New Issue
Block a user