fix: correct invoice order in payment reconcillaiton

(cherry picked from commit 5c34a5aaed)

# Conflicts:
#	erpnext/accounts/utils.py
This commit is contained in:
ljain112
2025-03-18 12:49:29 +05:30
committed by Mergify
parent e5fb77c65f
commit 2a70791bba

View File

@@ -9,8 +9,13 @@ import frappe
import frappe.defaults import frappe.defaults
from frappe import _, qb, throw from frappe import _, qb, throw
from frappe.model.meta import get_field_precision from frappe.model.meta import get_field_precision
<<<<<<< HEAD
from frappe.query_builder import AliasedQuery, Criterion, Table from frappe.query_builder import AliasedQuery, Criterion, Table
from frappe.query_builder.functions import Count, Sum from frappe.query_builder.functions import Count, Sum
=======
from frappe.query_builder import AliasedQuery, Case, Criterion, Table
from frappe.query_builder.functions import Count, Max, Round, Sum
>>>>>>> 5c34a5aaed (fix: correct invoice order in payment reconcillaiton)
from frappe.query_builder.utils import DocType from frappe.query_builder.utils import DocType
from frappe.utils import ( from frappe.utils import (
add_days, add_days,
@@ -1974,6 +1979,15 @@ class QueryPaymentLedger:
.select( .select(
ple.against_voucher_no.as_("voucher_no"), ple.against_voucher_no.as_("voucher_no"),
Sum(ple.amount_in_account_currency).as_("amount_in_account_currency"), Sum(ple.amount_in_account_currency).as_("amount_in_account_currency"),
Max(
Case().when(
(
(ple.voucher_no == ple.against_voucher_no)
& (ple.voucher_type == ple.against_voucher_type)
),
(ple.posting_date),
)
).as_("invoice_date"),
) )
.where(ple.delinked == 0) .where(ple.delinked == 0)
.where(Criterion.all(filter_on_against_voucher_no)) .where(Criterion.all(filter_on_against_voucher_no))
@@ -1981,7 +1995,7 @@ class QueryPaymentLedger:
.where(Criterion.all(self.dimensions_filter)) .where(Criterion.all(self.dimensions_filter))
.where(Criterion.all(self.voucher_posting_date)) .where(Criterion.all(self.voucher_posting_date))
.groupby(ple.against_voucher_type, ple.against_voucher_no, ple.party_type, ple.party) .groupby(ple.against_voucher_type, ple.against_voucher_no, ple.party_type, ple.party)
.orderby(ple.posting_date, ple.voucher_no) .orderby(ple.invoice_date, ple.voucher_no)
.having(qb.Field("amount_in_account_currency") > 0) .having(qb.Field("amount_in_account_currency") > 0)
.limit(self.limit) .limit(self.limit)
.run() .run()