2
0
mirror of https://github.com/frappe/erpnext.git synced 2024-06-12 07:04:00 +00:00
erpnext/erpnext/accounts/report/bank_clearance_summary/bank_clearance_summary.py
Anand Baburajan 988d755906
refactor!: removing loan management module (#35522)
* chore: resolving conflicts

* refactor: bank_clearance and add hook for get_payment_entries_for_bank_clearance

* refactor: bank_reconciliation_tool and add hook for get_matching_vouchers_for_bank_reconciliation

* fix: remove sales invoice from bank_reconciliation_doctypes and use hook for voucher clearance

* refactor: remove loan tests from test_bank_transaction

* refactor: bank_clearance_summary and add hook for get_entries_for_bank_clearance_summary

* refactor: removed test_bank_reconciliation_statement

* refactor: bank_reconciliation_statement and add hook for get_amounts_not_reflected_in_system_for_bank_reconciliation_statement

* refactor: add missing hook and patches for module removal and deprecation warning

* refactor: remove loan management translations

* chore: add erpnext tests dependent on lending
2023-06-30 11:02:49 +05:30

118 lines
2.7 KiB
Python

# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import frappe
from frappe import _
from frappe.utils import getdate, nowdate
def execute(filters=None):
if not filters:
filters = {}
columns = get_columns()
data = get_entries(filters)
return columns, data
def get_columns():
columns = [
{
"label": _("Payment Document Type"),
"fieldname": "payment_document_type",
"fieldtype": "Data",
"width": 130,
},
{
"label": _("Payment Entry"),
"fieldname": "payment_entry",
"fieldtype": "Dynamic Link",
"options": "payment_document_type",
"width": 140,
},
{"label": _("Posting Date"), "fieldname": "posting_date", "fieldtype": "Date", "width": 120},
{"label": _("Cheque/Reference No"), "fieldname": "cheque_no", "width": 120},
{"label": _("Clearance Date"), "fieldname": "clearance_date", "fieldtype": "Date", "width": 120},
{
"label": _("Against Account"),
"fieldname": "against",
"fieldtype": "Link",
"options": "Account",
"width": 200,
},
{"label": _("Amount"), "fieldname": "amount", "fieldtype": "Currency", "width": 120},
]
return columns
def get_conditions(filters):
conditions = ""
if filters.get("from_date"):
conditions += " and posting_date>=%(from_date)s"
if filters.get("to_date"):
conditions += " and posting_date<=%(to_date)s"
return conditions
def get_entries(filters):
entries = []
# get entries from all the apps
for method_name in frappe.get_hooks("get_entries_for_bank_clearance_summary"):
entries += (
frappe.get_attr(method_name)(
filters,
)
or []
)
return sorted(
entries,
key=lambda k: k[2] or getdate(nowdate()),
)
def get_entries_for_bank_clearance_summary(filters):
entries = []
conditions = get_conditions(filters)
journal_entries = frappe.db.sql(
"""SELECT
"Journal Entry", jv.name, jv.posting_date, jv.cheque_no,
jv.clearance_date, jvd.against_account, jvd.debit - jvd.credit
FROM
`tabJournal Entry Account` jvd, `tabJournal Entry` jv
WHERE
jvd.parent = jv.name and jv.docstatus=1 and jvd.account = %(account)s {0}
order by posting_date DESC, jv.name DESC""".format(
conditions
),
filters,
as_list=1,
)
payment_entries = frappe.db.sql(
"""SELECT
"Payment Entry", name, posting_date, reference_no, clearance_date, party,
if(paid_from=%(account)s, ((paid_amount * -1) - total_taxes_and_charges) , received_amount)
FROM
`tabPayment Entry`
WHERE
docstatus=1 and (paid_from = %(account)s or paid_to = %(account)s) {0}
order by posting_date DESC, name DESC""".format(
conditions
),
filters,
as_list=1,
)
entries = journal_entries + payment_entries
return entries