Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

result = frappe.db.get_all("Item Price", fields=["*"], filters={"itemcode": ["=",…

  1. User

    result = frappe.db.get_all("Item Price", fields=["*"], filters={"item_code": ["=", filters.item_code], "price_list": ["=", filters.price_list]} ) i use this script now but if i didn't put the 2 filters it's nothing get

  2. Assistant

    If you don't specify any filters, the script will return all records for the "Item Price" doctype. To avoid this, you can modify the script to include an additional check before executing the query. Here's an example:

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

    Now, if either filters.item_code or filters.price_list is not provided, it will return an empty list as the result.

  3. User

    if filters.item_code and filters.price_list: result = frappe.db.get_all("Item Price",
    fields=[""], filters={"item_code": ["=", filters.item_code], "price_list": ["=", filters.price_list]} ) else: result = frappe.db.get_all("Item Price", fields=[""]) this work but if i but 2 filters i want good code

  4. Assistant

    I apologize for the confusion. If you want to include the second filter when both filters.item_code and filters.price_list are provided, you can modify the code as follows:

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

    This code checks the presence of both filters first. If both filters are present, it includes both in the filter dictionary. If only one filter is present, it includes that filter only. If none of the filters are provided, it will return all records.

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