frappe / erpnext

Free and Open Source Enterprise Resource Planning (ERP)
https://erpnext.com
GNU General Public License v3.0
21.87k stars 7.33k forks source link

AttributeError: 'NoneType' object has no attribute 'item_name' - Item-wise Sales History #28467

Closed muchai closed 2 years ago

muchai commented 2 years ago

image

Traceback (most recent call last): File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 68, in application response = frappe.api.handle() File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 55, in handle return frappe.handler.handle() File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 31, in handle data = execute_cmd(cmd) File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 67, in execute_cmd return frappe.call(method, frappe.form_dict) File "/home/frappe/frappe-bench/apps/frappe/frappe/init.py", line 1207, in call return fn(*args, *newargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/init.py", line 623, in wrapper_fn retval = fn(args, get_newargs(fn, kwargs)) File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/query_report.py", line 236, in run result = generate_report_result(report, filters, user, custom_columns) File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/query_report.py", line 78, in generate_report_result res = report.execute_script_report(filters) File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/report/report.py", line 125, in execute_script_report res = self.execute_module(filters) File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/report/report.py", line 142, in execute_module return frappe.get_attr(method_name)(frappe._dict(filters)) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.py", line 18, in execute data = get_data(filters) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.py", line 161, in get_data "item_name": item_record.item_name, AttributeError: 'NoneType' object has no attribute 'item_name'

kennethsequeira commented 2 years ago

@muchai versions which are affected?

muchai commented 2 years ago

ERPNext: v13.14.1 (version-13)

kennethsequeira commented 2 years ago

Tested on the said version on FC. Wasn't able to reproduce.

eg:

image

Am I missing any filter that may cause the error? Else we'll need to close the issue.

muchai commented 2 years ago

You're right. Just tested on another site, and it works well. Let me check for any data issues in the site with the error. Albeit, the site with error, is till in version ERPNext: v13.14.1 (version-13)

muchai commented 2 years ago

Not sure, will look it more keenly. Thing is, it's a multi-company environment. In one company, the report displays correctly. In one, it returns the error above. The companies share items.

stale[bot] commented 2 years ago

This issue has been automatically marked as inactive because it has not had recent activity and it wasn't validated by maintainer team. It will be closed within a week if no further activity occurs.

ankush commented 2 years ago

@muchai I am guessing this is a case of bad data or a rename gone wrong.

https://github.com/frappe/erpnext/blob/1ee17b43d5e65b2fc4796de2a33fdbe3ea86d45a/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.py#L212-L221

This fetches all item_codes so it's very weird if it doesn't find it i.e. None is returned.

One way to figure out would be to run this query (doable from "System Console" also):

frappe.db.sql("""SELECT
    so_item.item_code, so_item.parent as sales_order
FROM
    `tabSales Order Item` so_item
LEFT JOIN 
    `tabItem` ti on so_item.item_code = ti.item_code
WHERE
    COALESCE(ti.item_code, '') = ''""")

e.g. I faked data corruption by changing item_code in database

Screenshot 2022-01-28 at 7 53 27 PM

Leaving this issue closed since it's more about data than a bug.

muchai commented 2 years ago

@ankush Thanks for the query. Will test it. Currently merging (via open balances) these two companies, into one.