When I Generate Account Receivable Report Using Api Gives Error

When i try to generate account receivable report using api its return data but when i pass filter party_type = ‘Customer’ and party = party_name is return error.

My Code

def get_receivable_report_content(name):
filters = {‘company’: ‘My Private Limited’, ‘ageing_based_on’: ‘Due Date’, ‘range1’: ‘30’, ‘range2’: ‘60’, ‘range3’: ‘90’, ‘range4’: ‘120’, ‘party_type’: ‘Customer’, ‘party’: ‘India-02’}
“”“Returns file in for the report in given format”“”

report = frappe.get_doc("Report", "Accounts Receivable")

filters = frappe.parse_json(filters) if filters else {}

columns, data = report.get_data(
    limit= 100,
    user= frappe.session.user,
    filters= filters,
    as_dict=True,
    ignore_prepared_report=True,
    are_default_filters=False,
) 

Error

Traceback (most recent call last):
File “apps/frappe/frappe/app.py”, line 95, in application
response = frappe.api.handle()
File “apps/frappe/frappe/api.py”, line 54, in handle
return frappe.handler.handle()
File “apps/frappe/frappe/handler.py”, line 47, in handle
data = execute_cmd(cmd)
File “apps/frappe/frappe/handler.py”, line 85, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “apps/frappe/frappe/init.py”, line 1622, in call
return fn(*args, **newargs)
File “apps/vijay_whatsapp/vijay_whatsapp/report.py”, line 15, in get_receivable_report_content
columns, data = report.get_data(
File “apps/frappe/frappe/core/doctype/report/report.py”, line 169, in get_data
columns, result = self.run_query_report(
File “apps/frappe/frappe/core/doctype/report/report.py”, line 184, in run_query_report
data = frappe.desk.query_report.run(
File “apps/frappe/frappe/init.py”, line 802, in wrapper_fn
retval = fn(*args, **get_newargs(fn, kwargs))
File “apps/frappe/frappe/desk/query_report.py”, line 239, in run
result = generate_report_result(report, filters, user, custom_columns, is_tree, parent_field)
File “apps/frappe/frappe/init.py”, line 802, in wrapper_fn
retval = fn(*args, **get_newargs(fn, kwargs))
File “apps/frappe/frappe/desk/query_report.py”, line 89, in generate_report_result
res = get_report_result(report, filters) or []
File “apps/frappe/frappe/desk/query_report.py”, line 70, in get_report_result
res = report.execute_script_report(filters)
File “apps/frappe/frappe/core/doctype/report/report.py”, line 131, in execute_script_report
res = self.execute_module(filters)
File “apps/frappe/frappe/core/doctype/report/report.py”, line 148, in execute_module
return frappe.get_attr(method_name)(frappe.dict(filters))
File “apps/erpnext/erpnext/accounts/report/accounts_receivable/accounts_receivable.py”, line 40, in execute
return ReceivablePayableReport(filters).run(args)
File “apps/erpnext/erpnext/accounts/report/accounts_receivable/accounts_receivable.py”, line 62, in run
self.get_data()
File “apps/erpnext/erpnext/accounts/report/accounts_receivable/accounts_receivable.py”, line 88, in get_data
self.get_ple_entries()
File “apps/erpnext/erpnext/accounts/report/accounts_receivable/accounts_receivable.py”, line 737, in get_ple_entries
.where(Criterion.all(self.qb_selection_filter))
File “env/lib/python3.10/site-packages/pypika/utils.py”, line 50, in copy
result = func(self_copy, args, *kwargs)
File “env/lib/python3.10/site-packages/pypika/queries.py”, line 930, in where
if not self.validate_table(criterion):
File “env/lib/python3.10/site-packages/pypika/queries.py”, line 1155, in validate_table
for field in term.fields
():
File “env/lib/python3.10/site-packages/pypika/terms.py”, line 57, in fields

return set(self.find
(Field))
File “env/lib/python3.10/site-packages/pypika/terms.py”, line 37, in find

return [node for node in self.nodes_() if isinstance(node, type)]
File “env/lib/python3.10/site-packages/pypika/terms.py”, line 37, in
return [node for node in self.nodes_() if isinstance(node, type)]
File “env/lib/python3.10/site-packages/pypika/terms.py”, line 743, in nodes_
yield from self.left.nodes_()
File “env/lib/python3.10/site-packages/pypika/terms.py”, line 743, in nodes_
yield from self.left.nodes_()
File “env/lib/python3.10/site-packages/pypika/terms.py”, line 742, in nodes_
yield from self.right.nodes_()
File “env/lib/python3.10/site-packages/pypika/terms.py”, line 795, in nodes_
yield from self.container.nodes_()
AttributeError: ‘str’ object has no attribute ‘nodes_’

Hi @pithiya_Nilesh,

Please check the syntax and try it.

import frappe

def generate_accounts_receivable_report():
    filters = {
        'company': 'My Private Limited',
        'ageing_based_on': 'Due Date',
        'range1': '30',
        'range2': '60',
        'range3': '90',
        'range4': '120',
        'party_type': 'Customer',
        'party': 'India-02',
    }

    # Convert the filters to JSON format
    filters_json = frappe.as_json(filters)

    try:
        # Call API to generate the report
        result = frappe.get_all("Report", filters=filters_json, as_list=True)

        columns = result[0]
        data = result[1:]

        # For the testing
        print("Columns:", columns)
        print("Data:", data)

    except Exception as e:
        print("Error:", str(e))

generate_accounts_receivable_report()

First, define the filters as a dictionary containing criteria such as company name, aging criteria, and party information.
convert these filters into JSON format. Then, make an API call using the filters and retrieve the report results. It handles the report data, separating column names and data rows, which can be further processed or displayed as needed. Any errors during the API call are also caught and displayed.

I hope this helps.

Thank You!

its not works

it create proble only when i send party in filter otherwise is work fine.

I am getting the same error in version 15.18, if your issue is solved can you help me to resolve the same.Thank You.