fix: Post Dated unallocated amount not considered in Advance Amount in AR/AP summary (#21837)
* fix: Post Dated unallocateed amount not considered in Advance Amount in AR/AP summary report
* fix: Add future payment filter in AR/AP summary
* fix: Show unallocated future payments only till current creation date
* fix: Remove extra query
* fix: Remove debug
* fix: Condition
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index 528fb4e..db91b66 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -602,10 +602,14 @@
else:
return ''
-def get_partywise_advanced_payment_amount(party_type, posting_date = None, company=None):
+def get_partywise_advanced_payment_amount(party_type, posting_date = None, future_payment=0, company=None):
cond = "1=1"
if posting_date:
- cond = "posting_date <= '{0}'".format(posting_date)
+ if future_payment:
+ cond = "posting_date <= '{0}' OR DATE(creation) <= '{0}' """.format(posting_date)
+ else:
+ cond = "posting_date <= '{0}'".format(posting_date)
+
if company:
cond += "and company = '{0}'".format(company)
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
index a0a1b97..c776d47 100755
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
@@ -559,6 +559,14 @@
conditions, values = self.prepare_conditions()
order_by = self.get_order_by_condition()
+ if self.filters.show_future_payments:
+ values.insert(2, self.filters.report_date)
+
+ date_condition = """AND (posting_date <= %s
+ OR (against_voucher IS NULL AND DATE(creation) <= %s))"""
+ else:
+ date_condition = "AND posting_date <=%s"
+
if self.filters.get(scrub(self.party_type)):
select_fields = "debit_in_account_currency as debit, credit_in_account_currency as credit"
else:
@@ -574,9 +582,8 @@
docstatus < 2
and party_type=%s
and (party is not null and party != '')
- and posting_date <= %s
- {1} {2}"""
- .format(select_fields, conditions, order_by), values, as_dict=True)
+ {1} {2} {3}"""
+ .format(select_fields, date_condition, conditions, order_by), values, as_dict=True)
def get_sales_invoices_or_customers_based_on_sales_person(self):
if self.filters.get("sales_person"):
diff --git a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js
index 32ecc63..305cddb 100644
--- a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js
+++ b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.js
@@ -111,7 +111,12 @@
"fieldname":"based_on_payment_terms",
"label": __("Based On Payment Terms"),
"fieldtype": "Check",
- }
+ },
+ {
+ "fieldname":"show_future_payments",
+ "label": __("Show Future Payments"),
+ "fieldtype": "Check",
+ },
],
onload: function(report) {
diff --git a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py
index aa6b42e..657b3e8 100644
--- a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py
+++ b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py
@@ -33,7 +33,7 @@
self.get_party_total(args)
party_advance_amount = get_partywise_advanced_payment_amount(self.party_type,
- self.filters.report_date, self.filters.company) or {}
+ self.filters.report_date, self.filters.show_future_payments, self.filters.company) or {}
for party, party_dict in iteritems(self.party_total):
if party_dict.outstanding == 0: