Skip to content

Commit

Permalink
fix: GL Entries against orders as an advance
Browse files Browse the repository at this point in the history
(cherry picked from commit 8289f3c)
  • Loading branch information
deepeshgarg007 authored and mergify[bot] committed May 3, 2024
1 parent 6bac561 commit e49a401
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
4 changes: 1 addition & 3 deletions erpnext/accounts/doctype/payment_entry/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ def make_advance_gl_entries(

def add_advance_gl_entries(self, gl_entries: list, entry: object | dict | None):
"""
If 'entry' is passed, GL enties only for that reference is added.
If 'entry' is passed, GL entries only for that reference is added.
"""
if self.book_advance_payments_in_separate_party_account:
references = [x for x in self.get("references")]
Expand All @@ -1239,8 +1239,6 @@ def add_advance_gl_entries(self, gl_entries: list, entry: object | dict | None):
"Sales Invoice",
"Purchase Invoice",
"Journal Entry",
"Sales Order",
"Purchase Order",
"Payment Entry",
):
self.add_advance_gl_for_reference(gl_entries, ref)
Expand Down
62 changes: 62 additions & 0 deletions erpnext/accounts/doctype/payment_entry/test_payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,68 @@ def test_ledger_entries_for_advance_as_liability(self):
self.check_gl_entries()
self.check_pl_entries()

def test_advance_as_liability_against_order(self):
from erpnext.buying.doctype.purchase_order.purchase_order import (
make_purchase_invoice as _make_purchase_invoice,
)
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order

company = "_Test Company"

advance_account = create_account(
parent_account="Current Liabilities - _TC",
account_name="Advances Paid",
company=company,
account_type="Liability",
)

frappe.db.set_value(
"Company",
company,
{
"book_advance_payments_in_separate_party_account": 1,
"default_advance_paid_account": advance_account,
},
)

po = create_purchase_order(supplier="_Test Supplier")
pe = get_payment_entry("Purchase Order", po.name)
pe.save().submit()

pre_reconciliation_gle = [
{"account": advance_account, "debit": 5000.0, "credit": 0.0},
{"account": "_Test Bank 2 - _TC", "debit": 0.0, "credit": 5000.0},
]

self.voucher_no = pe.name
self.expected_gle = pre_reconciliation_gle
self.check_gl_entries()

# Make Purchase Invoice against the order
pi = _make_purchase_invoice(po.name)
pi.append(
"advances",
{
"reference_type": pe.doctype,
"reference_name": pe.name,
"reference_row": pe.references[0].name,
"advance_amount": 5000,
"allocated_amount": 5000,
},
)
pi.save().submit()

# # assert General and Payment Ledger entries post partial reconciliation
self.expected_gle = [
{"account": pi.credit_to, "debit": 5000.0, "credit": 0.0},
{"account": advance_account, "debit": 5000.0, "credit": 0.0},
{"account": advance_account, "debit": 0.0, "credit": 5000.0},
{"account": "_Test Bank 2 - _TC", "debit": 0.0, "credit": 5000.0},
]

self.voucher_no = pe.name
self.check_gl_entries()

def check_pl_entries(self):
ple = frappe.qb.DocType("Payment Ledger Entry")
pl_entries = (
Expand Down

0 comments on commit e49a401

Please sign in to comment.