fix: Loan Doc query in Bank Reconciliation Statement

This commit is contained in:
Deepesh Garg 2022-05-25 17:58:30 +05:30
parent cb8cd7f5bc
commit 147fc8fde7

View File

@ -198,11 +198,12 @@ def get_loan_entries(filters):
amount_field = (loan_doc.disbursed_amount).as_("credit") amount_field = (loan_doc.disbursed_amount).as_("credit")
posting_date = (loan_doc.disbursement_date).as_("posting_date") posting_date = (loan_doc.disbursement_date).as_("posting_date")
account = loan_doc.disbursement_account account = loan_doc.disbursement_account
salary_condition = loan_doc.docstatus == 1
else: else:
amount_field = (loan_doc.amount_paid).as_("debit") amount_field = (loan_doc.amount_paid).as_("debit")
posting_date = (loan_doc.posting_date).as_("posting_date") posting_date = (loan_doc.posting_date).as_("posting_date")
account = loan_doc.payment_account account = loan_doc.payment_account
salary_condition = loan_doc.repay_from_salary == 0
query = ( query = (
frappe.qb.from_(loan_doc) frappe.qb.from_(loan_doc)
.select( .select(
@ -214,15 +215,13 @@ def get_loan_entries(filters):
posting_date, posting_date,
) )
.where(loan_doc.docstatus == 1) .where(loan_doc.docstatus == 1)
.where(salary_condition)
.where(account == filters.get("account")) .where(account == filters.get("account"))
.where(posting_date <= getdate(filters.get("report_date"))) .where(posting_date <= getdate(filters.get("report_date")))
.where(ifnull(loan_doc.clearance_date, "4000-01-01") > getdate(filters.get("report_date"))) .where(ifnull(loan_doc.clearance_date, "4000-01-01") > getdate(filters.get("report_date")))
) )
if doctype == "Loan Repayment": entries = query.run(as_dict=1, debug=1)
query.where(loan_doc.repay_from_salary == 0)
entries = query.run(as_dict=1)
loan_docs.extend(entries) loan_docs.extend(entries)
return loan_docs return loan_docs
@ -267,15 +266,17 @@ def get_loan_amount(filters):
amount_field = Sum(loan_doc.disbursed_amount) amount_field = Sum(loan_doc.disbursed_amount)
posting_date = (loan_doc.disbursement_date).as_("posting_date") posting_date = (loan_doc.disbursement_date).as_("posting_date")
account = loan_doc.disbursement_account account = loan_doc.disbursement_account
salary_condition = loan_doc.docstatus == 1
else: else:
amount_field = Sum(loan_doc.amount_paid) amount_field = Sum(loan_doc.amount_paid)
posting_date = (loan_doc.posting_date).as_("posting_date") posting_date = (loan_doc.posting_date).as_("posting_date")
account = loan_doc.payment_account account = loan_doc.payment_account
salary_condition = loan_doc.repay_from_salary == 0
amount = ( amount = (
frappe.qb.from_(loan_doc) frappe.qb.from_(loan_doc)
.select(amount_field) .select(amount_field)
.where(loan_doc.docstatus == 1) .where(loan_doc.docstatus == 1)
.where(salary_condition)
.where(account == filters.get("account")) .where(account == filters.get("account"))
.where(posting_date > getdate(filters.get("report_date"))) .where(posting_date > getdate(filters.get("report_date")))
.where(ifnull(loan_doc.clearance_date, "4000-01-01") <= getdate(filters.get("report_date"))) .where(ifnull(loan_doc.clearance_date, "4000-01-01") <= getdate(filters.get("report_date")))