i create script report from frappe and make it not standard and use script result =…
- User
i create script report from frappe and make it not standard and use script result = frappe.db.get_all("Item Price", fields=["*"]) and then i created coloume anf filter , all good but when i choose filter list not filtred
- Assistant
It seems that there might be an issue with the filtering in your script report. Here are a few things you can check:
-
Make sure that the filter conditions are correctly set. Double-check the code where you define the filter conditions for your query using the
frappe.db.get_allfunction. Ensure that the filter conditions are correctly written and that they match the field names and values you want to filter on. -
Verify that the filter conditions are correctly passed to the query. After defining the filter conditions, make sure that you include them in the query by appending them to the
filtersparameter of thefrappe.db.get_allfunction. -
Ensure that the filter values are valid. Check if the values you are providing for filtering exist in the database. If the filtering is not working, the issue might be due to invalid or incorrect values being used in the filters.
-
Confirm that the filter logic is correctly applied. If you are using multiple filters, ensure that the correct logic, such as
andoror, is applied between the filters to achieve the desired result.
By carefully reviewing these steps and making necessary corrections, you should be able to fix the issue with the filter not being applied correctly in your script report.
-
- User
no i didn't make filters parameter how i cane make it
- Assistant
To add filters to your query using the
frappe.db.get_allfunction, you need to include thefiltersparameter in the function call. Thefiltersparameter allows you to specify the filter conditions for your query.Here's an example of how you can add filters to your script report using the
filtersparameter:script_result = frappe.db.get_all("Item Price", fields=["*"], filters={"field1": "value1", "field2": "value2"})In the above example, replace
"field1"and"value1"with the field name and value you want to filter on. Similarly, replace"field2"and"value2"with the second field name and value for filtering.You can add multiple filters by including more key-value pairs in the
filtersdictionary. For example:filters={"field1": "value1", "field2": "value2", "field3": "value3"}Make sure to match the field names and values with the appropriate fields in the "Item Price" table.
By providing the correct filter conditions in the
filtersparameter, you should be able to successfully filter the results in your script report. - User
App Versions
{ "chat": "0.0.1", "erpnext": "14.27.12", "frappe": "14.40.3", "posawesome": "6.0.3" }Route
query-report/Item Price ListTraceback
Traceback (most recent call last): File "apps/frappe/frappe/app.py", line 94, 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 1610, in call return fn(*args, **newargs) File "apps/frappe/frappe/__init__.py", line 792, in wrapper_fn retval = fn(*args, **get_newargs(fn, kwargs)) File "apps/frappe/frappe/desk/query_report.py", line 232, in run result = generate_report_result(report, filters, user, custom_columns, is_tree, parent_field) File "apps/frappe/frappe/__init__.py", line 792, in wrapper_fn retval = fn(*args, **get_newargs(fn, kwargs)) File "apps/frappe/frappe/desk/query_report.py", line 90, in generate_report_result res = get_report_result(report, filters) or [] File "apps/frappe/frappe/desk/query_report.py", line 71, in get_report_result res = report.execute_script_report(filters) File "apps/frappe/frappe/core/doctype/report/report.py", line 133, in execute_script_report res = self.execute_script(filters) File "apps/frappe/frappe/core/doctype/report/report.py", line 153, in execute_script safe_exec(self.report_script, None, loc) File "apps/frappe/frappe/utils/safe_exec.py", line 72, in safe_exec exec(compile_restricted(script), exec_globals, _locals) # pylint: disable=exec-used File "env/lib/python3.10/site-packages/RestrictedPython/compile.py", line 211, in compile_restricted raise SyntaxError(result.errors) SyntaxError: ("Line 4: IndentationError: unexpected indent at statement: ')'",)Request Data
{ "type": "GET", "args": { "report_name": "Item Price List", "filters": "{}", "are_default_filters": true }, "headers": {}, "error_handlers": {}, "url": "/api/method/frappe.desk.query_report.run" }Response Data
{ "exception": "SyntaxError: (\"Line 4: IndentationError: unexpected indent at statement: ')'\",)" } - Assistant
Based on the traceback and response data you provided, it seems that there is a syntax error in your report script. The specific error states that there is an unexpected indent at line 4, which seems to be related to a closing parenthesis
).Please double-check your script to ensure proper indentation and syntax. Here's a potential fix for you to try:
# Your existing code script_result = frappe.db.get_all("Item Price", fields=["*"])In the above code snippet, make sure that the closing parenthesis
)is correctly placed. Sometimes, copy-pasting code can introduce invisible characters, causing indentation issues.After making the necessary corrections, save the script, and try running your script report again. If the issue persists, please provide the updated script and any additional error message or traceback you encounter.
- User
result = frappe.db.get_all("Item Price", fields=["*"], filters={"item_code": "item_code", "price_list": "price_list"}) )
- Assistant
In the code you provided, there seems to be an extra closing parenthesis
)at the end of theget_all()function call. This is causing a syntax error.To fix the issue, remove the extra closing parenthesis at the end of the code. Here's the corrected code:
result = frappe.db.get_all("Item Price", fields=["*"], filters={"item_code": "item_code", "price_list": "price_list"})Make sure to replace
"price_list"and"item_code"with the actual field names and values you want to use as filters in your query.After making these corrections, save your script and try running your script report with the updated code.
- User
App Versions
{ "chat": "0.0.1", "erpnext": "14.27.12", "frappe": "14.40.3", "posawesome": "6.0.3" }Route
query-report/Item Price ListTraceback
Traceback (most recent call last): File "apps/frappe/frappe/app.py", line 94, 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 1610, in call return fn(*args, **newargs) File "apps/frappe/frappe/__init__.py", line 792, in wrapper_fn retval = fn(*args, **get_newargs(fn, kwargs)) File "apps/frappe/frappe/desk/query_report.py", line 232, in run result = generate_report_result(report, filters, user, custom_columns, is_tree, parent_field) File "apps/frappe/frappe/__init__.py", line 792, in wrapper_fn retval = fn(*args, **get_newargs(fn, kwargs)) File "apps/frappe/frappe/desk/query_report.py", line 90, in generate_report_result res = get_report_result(report, filters) or [] File "apps/frappe/frappe/desk/query_report.py", line 71, in get_report_result res = report.execute_script_report(filters) File "apps/frappe/frappe/core/doctype/report/report.py", line 133, in execute_script_report res = self.execute_script(filters) File "apps/frappe/frappe/core/doctype/report/report.py", line 153, in execute_script safe_exec(self.report_script, None, loc) File "apps/frappe/frappe/utils/safe_exec.py", line 72, in safe_exec exec(compile_restricted(script), exec_globals, _locals) # pylint: disable=exec-used File "env/lib/python3.10/site-packages/RestrictedPython/compile.py", line 211, in compile_restricted raise SyntaxError(result.errors) SyntaxError: ("Line 1: SyntaxError: invalid character '“' (U+201C) at statement: 'result = frappe.db.get_all(“Item Price”, fields=[“*”], filters={“item_code”: “item_code”, “price_list”: “price_list”})'",)Request Data
{ "type": "GET", "args": { "report_name": "Item Price List", "filters": "{}", "are_default_filters": true }, "headers": {}, "error_handlers": {}, "url": "/api/method/frappe.desk.query_report.run" }Response Data
{ "exception": "SyntaxError: (\"Line 1: SyntaxError: invalid character '“' (U+201C) at statement: 'result = frappe.db.get_all(“Item Price”, fields=[“*”], filters={“item_code”: “item_code”, “price_list”: “price_list”})'\",)" } - Assistant
The traceback and response data indicate that the issue is related to the presence of invalid characters, specifically the double curly quotation marks (
“and”), in the code snippet you provided. These characters are not valid in Python syntax.To fix the issue, replace the invalid quotation marks with regular double quotation marks (
"). Here's the corrected code:result = frappe.db.get_all("Item Price", fields=["*"], filters={"item_code": "item_code", "price_list": "price_list"})After replacing the invalid characters, save your script and try running the script report again. The issue should be resolved, and the script should execute without any syntax errors.
- User
App Versions
{ "chat": "0.0.1", "erpnext": "14.27.12", "frappe": "14.40.3", "posawesome": "6.0.3" }Route
query-report/Item Price ListTraceback
Traceback (most recent call last): File "apps/frappe/frappe/app.py", line 94, 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 1610, in call return fn(*args, **newargs) File "apps/frappe/frappe/__init__.py", line 792, in wrapper_fn retval = fn(*args, **get_newargs(fn, kwargs)) File "apps/frappe/frappe/desk/query_report.py", line 232, in run result = generate_report_result(report, filters, user, custom_columns, is_tree, parent_field) File "apps/frappe/frappe/__init__.py", line 792, in wrapper_fn retval = fn(*args, **get_newargs(fn, kwargs)) File "apps/frappe/frappe/desk/query_report.py", line 90, in generate_report_result res = get_report_result(report, filters) or [] File "apps/frappe/frappe/desk/query_report.py", line 71, in get_report_result res = report.execute_script_report(filters) File "apps/frappe/frappe/core/doctype/report/report.py", line 133, in execute_script_report res = self.execute_script(filters) File "apps/frappe/frappe/core/doctype/report/report.py", line 153, in execute_script safe_exec(self.report_script, None, loc) File "apps/frappe/frappe/utils/safe_exec.py", line 72, in safe_exec exec(compile_restricted(script), exec_globals, _locals) # pylint: disable=exec-used File "env/lib/python3.10/site-packages/RestrictedPython/compile.py", line 211, in compile_restricted raise SyntaxError(result.errors) SyntaxError: ("Line 1: SyntaxError: invalid character '“' (U+201C) at statement: 'result = frappe.db.get_all(“Item Price”,'",)Request Data
{ "type": "GET", "args": { "report_name": "Item Price List", "filters": "{}", "are_default_filters": true }, "headers": {}, "error_handlers": {}, "url": "/api/method/frappe.desk.query_report.run" }Response Data
{ "exception": "SyntaxError: (\"Line 1: SyntaxError: invalid character '“' (U+201C) at statement: 'result = frappe.db.get_all(“Item Price”,'\",)" } - Assistant
The traceback and response data indicate that the issue is related to the presence of invalid characters, specifically the double curly quotation marks (
“and”), in the code snippet you provided. These characters are not valid in Python syntax.To fix the issue, replace the invalid quotation marks with regular double quotation marks (
"). Here's the corrected code:result = frappe.db.get_all("Item Price", fields=["*"], filters={"item_code": "item_code", "price_list": "price_list"})After replacing the invalid characters, save your script and try running the script report again. The issue should be resolved, and the script should execute without any syntax errors.
- User
in report doctype there is part name client code < is this i should write here to filter run
- Assistant
To filter the report's results based on the
client_codefield in the report doctype, you can modify your script as follows:result = frappe.db.get_all("Item Price", fields=["*"], filters={"client_code": "<your_filter_value>"})Replace
<your_filter_value>with the actual value you want to filter on. For example, if you want to filter the results where theclient_codeis equal to "ABC123", you would modify the code like this:result = frappe.db.get_all("Item Price", fields=["*"], filters={"client_code": "ABC123"})Make sure to adjust the field name (
client_code) and the desired filter value according to your specific requirements. - User
no there is text box in the bottom name client code
- Assistant
Apologies for the confusion. If there is a textbox in the report UI for filtering based on the
client_codefield, you need to modify the script to use the value entered in the textbox as the filter.Here's an example of how you can achieve this:
# Get the filter value entered in the client code textbox client_code_filter = filters.get("client_code") # Use the filter value in the query result = frappe.db.get_all("Item Price", fields=["*"], filters={"client_code": client_code_filter})In the above code,
filters.get("client_code")retrieves the value entered in the client code textbox from thefiltersdictionary. By using this filter value in the query, the results will be filtered based on the entered client code.Make sure to adjust the field name (
client_code) based on the actual field in the document and its corresponding filter field in the report. - User
JavaScript Format: frappe.query_reports['REPORTNAME'] = {}
- Assistant
The JavaScript format you shared
frappe.query_reports['REPORTNAME'] = {}is the syntax for defining a JavaScript object to customize or override a specific Frappe query report.To use this format, replace
'REPORTNAME'with the actual name of the report you want to customize. Then, inside the object, you can define various properties to modify the behavior of the report.Here's an example to demonstrate how you can use this format to customize a query report:
frappe.query_reports['Item Price List'] = { filters: [ { fieldname: 'client_code', label: 'Client Code', fieldtype: 'Data', options: '', default: '', reqd: 0, } ], onload: function(report) { // Perform additional actions when the report is loaded // For example, you can modify the filters or manipulate the DOM console.log(report); }, before_render: function(report) { // Perform actions before the report is rendered // For example, you can modify the report data or perform calculations console.log(report
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.