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/app.py", line 57, in application response = frappe.handler.handle() File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 22, in handle data = execute_cmd(cmd) File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 53, in execute_cmd return frappe.call(method, **frappe.form_dict) File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 923, in call return fn(*args, **newargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/query_report.py", 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/gross_profit.py", 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:
self.get_average_rate_based_on_group_by()’

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.data = []
		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