Merge pull request #47865 from aerele/accounts-receivable/payable-user-permission

fix: consider user permission while populating the data
This commit is contained in:
ruthra kumar
2025-06-09 15:22:15 +05:30
committed by GitHub

View File

@@ -6,6 +6,7 @@ from collections import OrderedDict
import frappe import frappe
from frappe import _, qb, query_builder, scrub from frappe import _, qb, query_builder, scrub
from frappe.desk.reportview import build_match_conditions
from frappe.query_builder import Criterion from frappe.query_builder import Criterion
from frappe.query_builder.functions import Date, Substring, Sum from frappe.query_builder.functions import Date, Substring, Sum
from frappe.utils import cint, cstr, flt, getdate, nowdate from frappe.utils import cint, cstr, flt, getdate, nowdate
@@ -126,7 +127,7 @@ class ReceivablePayableReport:
self.build_data() self.build_data()
def fetch_ple_in_buffered_cursor(self): def fetch_ple_in_buffered_cursor(self):
query, param = self.ple_query.walk() query, param = self.ple_query
self.ple_entries = frappe.db.sql(query, param, as_dict=True) self.ple_entries = frappe.db.sql(query, param, as_dict=True)
for ple in self.ple_entries: for ple in self.ple_entries:
@@ -140,7 +141,7 @@ class ReceivablePayableReport:
def fetch_ple_in_unbuffered_cursor(self): def fetch_ple_in_unbuffered_cursor(self):
self.ple_entries = [] self.ple_entries = []
query, param = self.ple_query.walk() query, param = self.ple_query
with frappe.db.unbuffered_cursor(): with frappe.db.unbuffered_cursor():
for ple in frappe.db.sql(query, param, as_dict=True, as_iterator=True): for ple in frappe.db.sql(query, param, as_dict=True, as_iterator=True):
self.init_voucher_balance(ple) # invoiced, paid, credit_note, outstanding self.init_voucher_balance(ple) # invoiced, paid, credit_note, outstanding
@@ -449,16 +450,14 @@ class ReceivablePayableReport:
self.invoice_details = frappe._dict() self.invoice_details = frappe._dict()
if self.account_type == "Receivable": if self.account_type == "Receivable":
# nosemgrep # nosemgrep
si_list = frappe.db.sql( si_list = frappe.get_list(
""" "Sales Invoice",
select name, due_date, po_no filters={
from `tabSales Invoice` "posting_date": ("<=", self.filters.report_date),
where posting_date <= %s "company": self.filters.company,
and company = %s "docstatus": 1,
and docstatus = 1 },
""", fields=["name", "due_date", "po_no"],
(self.filters.report_date, self.filters.company),
as_dict=1,
) )
for d in si_list: for d in si_list:
self.invoice_details.setdefault(d.name, d) self.invoice_details.setdefault(d.name, d)
@@ -481,33 +480,29 @@ class ReceivablePayableReport:
if self.account_type == "Payable": if self.account_type == "Payable":
# nosemgrep # nosemgrep
for pi in frappe.db.sql( invoices = frappe.get_list(
""" "Purchase Invoice",
select name, due_date, bill_no, bill_date filters={
from `tabPurchase Invoice` "posting_date": ("<=", self.filters.report_date),
where "company": self.filters.company,
posting_date <= %s "docstatus": 1,
and company = %s },
and docstatus = 1 fields=["name", "due_date", "bill_no", "bill_date"],
""", )
(self.filters.report_date, self.filters.company),
as_dict=1, for pi in invoices:
):
self.invoice_details.setdefault(pi.name, pi) self.invoice_details.setdefault(pi.name, pi)
# Invoices booked via Journal Entries # Invoices booked via Journal Entries
# nosemgrep # nosemgrep
journal_entries = frappe.db.sql( journal_entries = frappe.get_list(
""" "Journal Entry",
select name, due_date, bill_no, bill_date filters={
from `tabJournal Entry` "posting_date": ("<=", self.filters.report_date),
where "company": self.filters.company,
posting_date <= %s "docstatus": 1,
and company = %s },
and docstatus = 1 fields=["name", "due_date", "bill_no", "bill_date"],
""",
(self.filters.report_date, self.filters.company),
as_dict=1,
) )
for je in journal_entries: for je in journal_entries:
@@ -856,12 +851,18 @@ class ReceivablePayableReport:
else: else:
query = query.select(ple.remarks) query = query.select(ple.remarks)
if self.filters.get("group_by_party"): query, param = query.walk()
query = query.orderby(self.ple.party, self.ple.posting_date)
else:
query = query.orderby(self.ple.posting_date, self.ple.party)
self.ple_query = query match_conditions = build_match_conditions("Payment Ledger Entry")
if match_conditions:
query += " AND " + match_conditions
if self.filters.get("group_by_party"):
query += f" ORDER BY `{self.ple.party.name}`, `{self.ple.posting_date.name}`"
else:
query += f" ORDER BY `{self.ple.posting_date.name}`, `{self.ple.party.name}`"
self.ple_query = (query, param)
def get_sales_invoices_or_customers_based_on_sales_person(self): def get_sales_invoices_or_customers_based_on_sales_person(self):
if self.filters.get("sales_person"): if self.filters.get("sales_person"):