Cost Center filter not working for Account Payable and Receivable reports

Hi All,
We want to filter the Account Payable and Account Receivable reports based on the cost center. What’s observed is that the cost center filter is already present in the report but when used its not filtering based on the cost center selected. After having a look at the accounts_receivable.py file observed that there are no conditions applied for cost center filtering. So have tried adding the conditions in the code, to get the cost center from the sales invoice/purchase invoice item level and map it with the selected cost center of the report and its working fine for us. It would be helpful if anybody could guide me if this is the right way. We can modify the file directly but on the version upgrade we might lose the changes and if you all find that the code is right we can also send a pull request.

Following is the code for condition checking added in the file:

def prepare_conditions(self):
conditions = [“”]
values = [self.party_type, self.filters.report_date]
party_type_field = scrub(self.party_type)

	self.add_common_filters(conditions, values, party_type_field)

	if party_type_field=="customer":
		self.add_customer_filters(conditions, values)
		if self.filters.get("cost_center"):
			conditions.append("voucher_no in (select distinct `tabSales Invoice`.name from `tabSales Invoice` left join `tabSales Invoice Item` on `tabSales Invoice Item`.parent=`tabSales Invoice`.name where `tabSales Invoice Item`.cost_center=%s)")
			values.append(self.filters.get("cost_center"))

	elif party_type_field=="supplier":
		self.add_supplier_filters(conditions, values)
		if self.filters.get("cost_center"):
			conditions.append("voucher_no in (select distinct `tabPurchase Invoice`.name from `tabPurchase Invoice` left join `tabPurchase Invoice Item` on `tabPurchase Invoice Item`.parent=`tabPurchase Invoice`.name where `tabPurchase Invoice Item`.cost_center=%s)")
			values.append(self.filters.get("cost_center"))
		
	self.add_accounting_dimensions_filters(conditions, values)
	return " and ".join(conditions), values

Thanks

I remember some other user had this problem too. Technically Balance Sheet items don’t have Cost Center as Cost is P&L related. But hey, if it already has a Cost Center field, we might as well use it completely, right?

Maybe you could do a pull request and fix it for everyone.

Hope this helps: Contribution Guidelines · frappe/erpnext Wiki · GitHub

Thanks

Jay

@JayRam
Thanks

Unless you actually have separate bank, payables, receivables accounts for each cost center, as soon as you make payments/deposits from/to the common bank account your cost center balance sheet will not add up correctly. So in most real world cases a balance sheet by cost center is not useful.