Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

i create script report from frappe and make it not standard and use script result =…

  1. 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

  2. Assistant

    It seems that there might be an issue with the filtering in your script report. Here are a few things you can check:

    1. 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_all function. Ensure that the filter conditions are correctly written and that they match the field names and values you want to filter on.

    2. 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 filters parameter of the frappe.db.get_all function.

    3. 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.

    4. Confirm that the filter logic is correctly applied. If you are using multiple filters, ensure that the correct logic, such as and or or, 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.

  3. User

    no i didn't make filters parameter how i cane make it

  4. Assistant

    To add filters to your query using the frappe.db.get_all function, you need to include the filters parameter in the function call. The filters parameter 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 filters parameter:

    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 filters dictionary. 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 filters parameter, you should be able to successfully filter the results in your script report.

  5. User

    App Versions

    {
    	"chat": "0.0.1",
    	"erpnext": "14.27.12",
    	"frappe": "14.40.3",
    	"posawesome": "6.0.3"
    }
    

    Route

    query-report/Item Price List
    

    Traceback

    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: ')'\",)"
    }
    
  6. 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.

  7. User

    result = frappe.db.get_all("Item Price", fields=["*"], filters={"item_code": "item_code", "price_list": "price_list"}) )

  8. Assistant

    In the code you provided, there seems to be an extra closing parenthesis ) at the end of the get_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.

  9. User

    App Versions

    {
    	"chat": "0.0.1",
    	"erpnext": "14.27.12",
    	"frappe": "14.40.3",
    	"posawesome": "6.0.3"
    }
    

    Route

    query-report/Item Price List
    

    Traceback

    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”})'\",)"
    }
    
  10. 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.

  11. User

    App Versions

    {
    	"chat": "0.0.1",
    	"erpnext": "14.27.12",
    	"frappe": "14.40.3",
    	"posawesome": "6.0.3"
    }
    

    Route

    query-report/Item Price List
    

    Traceback

    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”,'\",)"
    }
    
  12. 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.

  13. User

    in report doctype there is part name client code < is this i should write here to filter run

  14. Assistant

    To filter the report's results based on the client_code field 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 the client_code is 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.

  15. User

    no there is text box in the bottom name client code

  16. Assistant

    Apologies for the confusion. If there is a textbox in the report UI for filtering based on the client_code field, 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 the filters dictionary. 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.

  17. User

    JavaScript Format: frappe.query_reports['REPORTNAME'] = {}

  18. 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
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.