mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 20:29:09 +00:00
Feat:Filter on Payment Entries and Journal Entries
Applying filters on Payement entries and Journal Entries as per reference date and posting date
This commit is contained in:
@@ -533,66 +533,58 @@ def get_pe_matching_query(amount_condition, account_from_to, transaction):
|
|||||||
currency_field = "paid_to_account_currency as currency"
|
currency_field = "paid_to_account_currency as currency"
|
||||||
else:
|
else:
|
||||||
currency_field = "paid_from_account_currency as currency"
|
currency_field = "paid_from_account_currency as currency"
|
||||||
if filtered_by_reference_date:
|
cond_filtered_from_ref_date = ""
|
||||||
pe_data = f"""
|
cond_filtered_to_ref_date = ""
|
||||||
SELECT
|
cond_filtered_from_posting_date = ""
|
||||||
(CASE WHEN reference_no=%(reference_no)s THEN 1 ELSE 0 END
|
cond_filtered_to_posting_date = ""
|
||||||
+ CASE WHEN (party_type = %(party_type)s AND party = %(party)s ) THEN 1 ELSE 0 END
|
from_ref_date =""
|
||||||
+ 1 ) AS rank,
|
to_ref_date =""
|
||||||
'Payment Entry' as doctype,
|
from_post_date = ""
|
||||||
name,
|
to_post_date = ""
|
||||||
paid_amount,
|
if(filtered_by_reference_date):
|
||||||
reference_no,
|
cond_filtered_from_ref_date = " AND reference_date >="
|
||||||
reference_date,
|
cond_filtered_to_ref_date = " AND reference_date <="
|
||||||
party,
|
from_ref_date = from_reference_date
|
||||||
party_type,
|
to_ref_date = to_reference_date
|
||||||
posting_date,
|
elif(not filtered_by_reference_date):
|
||||||
{currency_field}
|
cond_filtered_from_posting_date = " AND posting_date >="
|
||||||
FROM
|
cond_filtered_to_posting_date = " AND posting_date <="
|
||||||
`tabPayment Entry`
|
from_post_date = from_date
|
||||||
WHERE
|
to_post_date = to_date
|
||||||
paid_amount {amount_condition} %(amount)s
|
|
||||||
AND docstatus = 1
|
pe_data= f"""
|
||||||
AND payment_type IN (%(payment_type)s, 'Internal Transfer')
|
SELECT
|
||||||
AND ifnull(clearance_date, '') = ""
|
(CASE WHEN reference_no=%(reference_no)s THEN 1 ELSE 0 END
|
||||||
AND {account_from_to} = %(bank_account)s
|
+ CASE WHEN (party_type = %(party_type)s AND party = %(party)s ) THEN 1 ELSE 0 END
|
||||||
AND reference_date >= '{from_reference_date}'
|
+ 1 ) AS rank,
|
||||||
AND reference_date <= '{to_reference_date}'
|
'Payment Entry' as doctype,
|
||||||
|
name,
|
||||||
"""
|
paid_amount,
|
||||||
else:
|
reference_no,
|
||||||
pe_data = f"""
|
reference_date,
|
||||||
SELECT
|
party,
|
||||||
(CASE WHEN reference_no=%(reference_no)s THEN 1 ELSE 0 END
|
party_type,
|
||||||
+ CASE WHEN (party_type = %(party_type)s AND party = %(party)s ) THEN 1 ELSE 0 END
|
posting_date,
|
||||||
+ 1 ) AS rank,
|
{currency_field}
|
||||||
'Payment Entry' as doctype,
|
FROM
|
||||||
name,
|
`tabPayment Entry`
|
||||||
paid_amount,
|
WHERE
|
||||||
reference_no,
|
paid_amount {amount_condition} %(amount)s
|
||||||
reference_date,
|
AND docstatus = 1
|
||||||
party,
|
AND payment_type IN (%(payment_type)s, 'Internal Transfer')
|
||||||
party_type,
|
AND ifnull(clearance_date, '') = ""
|
||||||
posting_date,
|
AND {account_from_to} = %(bank_account)s
|
||||||
{currency_field}
|
AND reference_no = '{transaction.reference_number}'
|
||||||
FROM
|
{cond_filtered_from_ref_date} "{from_ref_date}"
|
||||||
`tabPayment Entry`
|
{cond_filtered_to_ref_date} "{to_ref_date}"
|
||||||
WHERE
|
{cond_filtered_from_posting_date} "{from_post_date}"
|
||||||
paid_amount {amount_condition} %(amount)s
|
{cond_filtered_to_posting_date} "{to_post_date}"
|
||||||
AND docstatus = 1
|
"""
|
||||||
AND payment_type IN (%(payment_type)s, 'Internal Transfer')
|
|
||||||
AND ifnull(clearance_date, '') = ""
|
|
||||||
AND {account_from_to} = %(bank_account)s
|
|
||||||
AND posting_date >= '{from_date}'
|
|
||||||
AND posting_date <= '{to_date}'
|
|
||||||
|
|
||||||
"""
|
|
||||||
return pe_data
|
return pe_data
|
||||||
|
|
||||||
|
|
||||||
def get_je_matching_query(amount_condition, transaction):
|
def get_je_matching_query(amount_condition, transaction):
|
||||||
# get matching journal entry query
|
# get matching journal entry query
|
||||||
|
|
||||||
# We have mapping at the bank level
|
# We have mapping at the bank level
|
||||||
# So one bank could have both types of bank accounts like asset and liability
|
# So one bank could have both types of bank accounts like asset and liability
|
||||||
# So cr_or_dr should be judged only on basis of withdrawal and deposit and not account type
|
# So cr_or_dr should be judged only on basis of withdrawal and deposit and not account type
|
||||||
@@ -606,65 +598,56 @@ def get_je_matching_query(amount_condition, transaction):
|
|||||||
"Bank Reconciliation Tool", "filtered_by_reference_date"
|
"Bank Reconciliation Tool", "filtered_by_reference_date"
|
||||||
)
|
)
|
||||||
cr_or_dr = "credit" if transaction.withdrawal > 0 else "debit"
|
cr_or_dr = "credit" if transaction.withdrawal > 0 else "debit"
|
||||||
if filtered_by_reference_date == 1:
|
cond_filtered_from_ref_date = ""
|
||||||
je_data = f"""
|
cond_filtered_to_ref_date = ""
|
||||||
SELECT
|
cond_filtered_from_posting_date = ""
|
||||||
(CASE WHEN je.cheque_no=%(reference_no)s THEN 1 ELSE 0 END
|
cond_filtered_to_posting_date = ""
|
||||||
+ 1) AS rank ,
|
from_ref_date =""
|
||||||
'Journal Entry' as doctype,
|
to_ref_date =""
|
||||||
je.name,
|
from_post_date = ""
|
||||||
jea.{cr_or_dr}_in_account_currency as paid_amount,
|
to_post_date = ""
|
||||||
je.cheque_no as reference_no,
|
if(filtered_by_reference_date):
|
||||||
je.cheque_date as reference_date,
|
cond_filtered_from_ref_date = " AND je.cheque_date >="
|
||||||
je.pay_to_recd_from as party,
|
cond_filtered_to_ref_date = " AND je.cheque_date <="
|
||||||
jea.party_type,
|
from_ref_date = from_reference_date
|
||||||
je.posting_date,
|
to_ref_date = to_reference_date
|
||||||
jea.account_currency as currency
|
elif(not filtered_by_reference_date):
|
||||||
FROM
|
cond_filtered_from_posting_date = " AND je.posting_date>="
|
||||||
`tabJournal Entry Account` as jea
|
cond_filtered_to_posting_date = " AND je.posting_date <="
|
||||||
JOIN
|
from_post_date = from_date
|
||||||
`tabJournal Entry` as je
|
to_post_date = to_date
|
||||||
ON
|
je_data = f"""
|
||||||
jea.parent = je.name
|
SELECT
|
||||||
WHERE
|
(CASE WHEN je.cheque_no=%(reference_no)s THEN 1 ELSE 0 END
|
||||||
(je.clearance_date is null or je.clearance_date='0000-00-00')
|
+ 1) AS rank ,
|
||||||
AND jea.account = %(bank_account)s
|
'Journal Entry' as doctype,
|
||||||
AND jea.{cr_or_dr}_in_account_currency {amount_condition} %(amount)s
|
je.name,
|
||||||
AND je.docstatus = 1
|
jea.{cr_or_dr}_in_account_currency as paid_amount,
|
||||||
AND je.cheque_date >= '{from_reference_date}'
|
je.cheque_no as reference_no,
|
||||||
AND je.cheque_date <= '{to_reference_date}'
|
je.cheque_date as reference_date,
|
||||||
"""
|
je.pay_to_recd_from as party,
|
||||||
else:
|
jea.party_type,
|
||||||
je_data = f"""
|
je.posting_date,
|
||||||
SELECT
|
jea.account_currency as currency
|
||||||
(CASE WHEN je.cheque_no=%(reference_no)s THEN 1 ELSE 0 END
|
FROM
|
||||||
+ 1) AS rank ,
|
`tabJournal Entry Account` as jea
|
||||||
'Journal Entry' as doctype,
|
JOIN
|
||||||
je.name,
|
`tabJournal Entry` as je
|
||||||
jea.{cr_or_dr}_in_account_currency as paid_amount,
|
ON
|
||||||
je.cheque_no as reference_no,
|
jea.parent = je.name
|
||||||
je.cheque_date as reference_date,
|
WHERE
|
||||||
je.pay_to_recd_from as party,
|
(je.clearance_date is null or je.clearance_date='0000-00-00')
|
||||||
jea.party_type,
|
AND jea.account = %(bank_account)s
|
||||||
je.posting_date,
|
AND jea.{cr_or_dr}_in_account_currency {amount_condition} %(amount)s
|
||||||
jea.account_currency as currency
|
AND je.docstatus = 1
|
||||||
FROM
|
AND je.cheque_no = '{transaction.reference_number}'
|
||||||
`tabJournal Entry Account` as jea
|
{cond_filtered_from_ref_date} "{from_ref_date}"
|
||||||
JOIN
|
{cond_filtered_to_ref_date} "{to_ref_date}"
|
||||||
`tabJournal Entry` as je
|
{cond_filtered_from_posting_date} "{from_post_date}"
|
||||||
ON
|
{cond_filtered_to_posting_date} "{to_post_date}"
|
||||||
jea.parent = je.name
|
"""
|
||||||
WHERE
|
|
||||||
(je.clearance_date is null or je.clearance_date='0000-00-00')
|
|
||||||
AND jea.account = %(bank_account)s
|
|
||||||
AND jea.{cr_or_dr}_in_account_currency {amount_condition} %(amount)s
|
|
||||||
AND je.docstatus = 1
|
|
||||||
AND je.posting_date >= '{from_date}'
|
|
||||||
AND je.posting_date <= '{to_date}'
|
|
||||||
"""
|
|
||||||
return je_data
|
return je_data
|
||||||
|
|
||||||
|
|
||||||
def get_si_matching_query(amount_condition):
|
def get_si_matching_query(amount_condition):
|
||||||
# get matchin sales invoice query
|
# get matchin sales invoice query
|
||||||
return f"""
|
return f"""
|
||||||
|
|||||||
Reference in New Issue
Block a user