fix: avoid double reduction of pe reference outstanding (#54193)

Co-authored-by: diptanilsaha <diptanil@frappe.io>
This commit is contained in:
Ravibharathi
2026-04-29 01:46:55 +05:30
committed by GitHub
parent a8030c9713
commit d1a80d40c4
2 changed files with 28 additions and 4 deletions

View File

@@ -195,6 +195,30 @@ class TestPaymentEntry(ERPNextTestSuite):
outstanding_amount = flt(frappe.db.get_value("Sales Invoice", si.name, "outstanding_amount"))
self.assertEqual(outstanding_amount, 100)
def test_reference_outstanding_amount_on_advance_pull(self):
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
so = make_sales_order(qty=1, rate=1000)
pe = get_payment_entry("Sales Order", so.name, bank_account="_Test Cash - _TC")
pe.paid_amount = pe.received_amount = 500
pe.references[0].allocated_amount = 500
pe.insert()
pe.submit()
so.reload()
self.assertEqual(so.advance_paid, 500)
si = make_sales_invoice(so.name)
si.allocate_advances_automatically = 1
si.save()
self.assertEqual(si.get("advances")[0].allocated_amount, 500)
self.assertEqual(si.get("advances")[0].reference_name, pe.name)
si.submit()
pe.load_from_db()
self.assertEqual(pe.references[0].reference_name, si.name)
self.assertEqual(pe.references[0].outstanding_amount, si.outstanding_amount)
def test_payment_entry_against_pi(self):
pi = make_purchase_invoice(
supplier="_Test Supplier USD",

View File

@@ -3,7 +3,6 @@
from collections import defaultdict
from datetime import date, datetime
from json import loads
from typing import TYPE_CHECKING, Optional
@@ -31,6 +30,7 @@ from frappe.utils import (
nowdate,
)
from frappe.utils.caching import site_cache
from frappe.utils.data import DateTimeLikeObject
from pypika import Order
from pypika.functions import Coalesce
from pypika.terms import ExistsCriterion
@@ -61,7 +61,7 @@ OUTSTANDING_DOCTYPES = frozenset(["Sales Invoice", "Purchase Invoice", "Fees"])
@frappe.whitelist()
def get_fiscal_year(
date: str | datetime | None = None,
date: DateTimeLikeObject | None = None,
fiscal_year: str | None = None,
label: str = "Date",
verbose: int = 1,
@@ -201,7 +201,7 @@ def validate_fiscal_year(date, fiscal_year, company, label="Date", doc=None):
@frappe.whitelist()
def get_balance_on(
account: str | None = None,
date: str | date | None = None,
date: DateTimeLikeObject | None = None,
party_type: str | None = None,
party: str | None = None,
company: str | None = None,
@@ -547,7 +547,7 @@ def reconcile_against_document(
skip_ref_details_update_for_pe=skip_ref_details_update_for_pe,
dimensions_dict=dimensions_dict,
)
if referenced_row.get("outstanding_amount"):
if referenced_row.get("outstanding_amount") and entry.get("outstanding_amount") is None:
referenced_row.outstanding_amount -= flt(entry.allocated_amount)
reposting_rows.append(referenced_row)