fix: only show advance payment entries where "book_advance_payments_in_separate_party_account" is true

This commit is contained in:
ljain112
2024-12-05 15:18:44 +05:30
parent 029dc948fe
commit ffd6a8424b
2 changed files with 24 additions and 12 deletions

View File

@@ -153,10 +153,7 @@ class PaymentReconciliation(Document):
self.add_payment_entries(non_reconciled_payments)
def get_payment_entries(self):
if self.default_advance_account:
party_account = [self.receivable_payable_account, self.default_advance_account]
else:
party_account = [self.receivable_payable_account]
party_account = [self.receivable_payable_account]
order_doctype = "Sales Order" if self.party_type == "Customer" else "Purchase Order"
condition = frappe._dict(
@@ -187,6 +184,7 @@ class PaymentReconciliation(Document):
self.party,
party_account,
order_doctype,
default_advance_account=self.default_advance_account,
against_all_orders=True,
limit=self.payment_limit,
condition=condition,

View File

@@ -2946,6 +2946,7 @@ def get_advance_payment_entries(
party_account,
order_doctype,
order_list=None,
default_advance_account=None,
include_unallocated=True,
against_all_orders=False,
limit=None,
@@ -2959,6 +2960,7 @@ def get_advance_payment_entries(
party_type,
party,
party_account,
default_advance_account,
limit,
condition,
)
@@ -2982,13 +2984,14 @@ def get_advance_payment_entries(
party_type,
party,
party_account,
default_advance_account,
limit,
condition,
)
q = q.select((payment_entry.unallocated_amount).as_("amount"))
q = q.where(payment_entry.unallocated_amount > 0)
unallocated = list(q.run(as_dict=True))
unallocated = list(q.run(as_dict=True, debug=True))
payment_entries += unallocated
return payment_entries
@@ -2997,6 +3000,7 @@ def get_common_query(
party_type,
party,
party_account,
default_advance_account,
limit,
condition,
):
@@ -3018,14 +3022,24 @@ def get_common_query(
.where(payment_entry.docstatus == 1)
)
if payment_type == "Receive":
q = q.select((payment_entry.paid_from_account_currency).as_("currency"))
q = q.select(payment_entry.paid_from)
q = q.where(payment_entry.paid_from.isin(party_account))
field = "paid_from" if payment_type == "Receive" else "paid_to"
q = q.select((payment_entry[f"{field}_account_currency"]).as_("currency"))
q = q.select(payment_entry[field])
account_condition = payment_entry[field].isin(party_account)
if default_advance_account:
q = q.where(
(
account_condition
| (
(payment_entry[field] == default_advance_account)
& (payment_entry.book_advance_payments_in_separate_party_account == 1)
)
)
)
else:
q = q.select((payment_entry.paid_to_account_currency).as_("currency"))
q = q.select(payment_entry.paid_to)
q = q.where(payment_entry.paid_to.isin(party_account))
q = q.where(account_condition)
if payment_type == "Receive":
q = q.select((payment_entry.source_exchange_rate).as_("exchange_rate"))