Gross Profit Report Error: Undefined grouped_data

erpnext 9.1.4
frappe 9.1.6

When I open Gross Profit Report in the Account Module. I get an error on the page. The error creates a log within Error Snapshot.

AttributeError("'GrossProfitGenerator' object has no attribute 'grouped_data'",)

Traceback (most recent call last): File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 57, in application response = frappe.handler.handle() File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 22, in handle data = execute_cmd(cmd) File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 53, in execute_cmd return, **frappe.form_dict) File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 923, in call return fn(*args, **newargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/", line 96, in run res = frappe.get_attr(method_name)(frappe._dict(filters)) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/report/gross_profit/", line 47, in execute for src in gross_profit_data.grouped_data: AttributeError: 'GrossProfitGenerator' object has no attribute 'grouped_data'

Thank you

Okay I was looking at the code. It seems that the error displays only when there is no Sales Invoice

At line 149
`if self.grouped:

I added

else: self.grouped_data = []

to initialize the grouped_data to empty array when there are no sales invoice to show.

Don’t know if what I did is correct, please anyone experience can help me or the erpnext community correct the issue.

Thank you

yeah that will work just fine but can I suggest that you simply add self.grouped_data as one of the instance variables:

class GrossProfitGenerator(object):
	def __init__(self, filters=None): = []
		self.average_buying_rate = {}
                self.grouped_data = []

Please report this on github and if you have the time, send a PR with the fix. Thanks for making ERPNext better

Thank you

First time looking at python codes.

that section does look like a constructor.

I’ve posted this in the github issues

1 Like

:+1: for first time contributor