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

frappe.queryreports["Item Variant Details"] = { "filters": [ { reqd: 1, default: "",…

  1. User

    frappe.query_reports["Item Variant Details"] = { "filters": [ { reqd: 1, default: "", options: "Item", label: __("Item"), fieldname: "item", fieldtype: "Link", get_query: () => { return { filters: { "has_variants": 1 } } } } ] }

  2. Assistant

    frappe.query_reports["Item Variant Details"] = { "filters": [ { "fieldtype": "Link", "fieldname": "item", "label": "Item", "options": "Item", "default": "", "reqd": 1, "get_query": function() { return { "filters": { "has_variants": 1 } } } } ] }

  3. User

    how can i add warehouse filter

  4. Assistant

    To add the warehouse filter to the "Item Variant Details" report, you can modify the code as follows:

    frappe.query_reports["Item Variant Details"] = {
    	"filters": [
    		{
    			"fieldtype": "Link",
    			"fieldname": "item",
    			"label": "Item",
    			"options": "Item",
    			"default": "",
    			"reqd": 1,
    			"get_query": function() {
    				return {
    					"filters": {
    						"has_variants": 1
    					}
    				}
    			}
    		},
    		{
    			"fieldtype": "Link",
    			"fieldname": "warehouse",
    			"label": "Warehouse",
    			"options": "Warehouse",
    			"default": "",
    			"get_query": function() {
    				return {
    					"query": "frappe.desk.search.search_link",
    					"filters": {
    						"doctype": "Warehouse"
    					}
    				}
    			}
    		}
    	]
    }
    

    This code adds a new filter for the warehouse field. The filter is of type link, and the available options will be fetched using the "frappe.desk.search.search_link" query for the Warehouse doctype.

  5. User

    def get_data(item, warehouse): if not item: return []

    item_dicts = []
    
    variant_results = frappe.db.get_all(
    	"Item", fields=["name"], filters={"variant_of": ["=", item], "disabled": 0}
    )
    
    if not variant_results:
    	frappe.msgprint(_("There aren't any item variants for the selected item"))
    	return []
    else:
    	variant_list = [variant["name"] for variant in variant_results]
    
    order_count_map = get_open_sales_orders_count(variant_list)
    stock_details_map = get_stock_details_map(variant_list, warehouse)  # Include warehouse parameter
    buying_price_map = get_buying_price_map(variant_list)
    selling_price_map = get_selling_price_map(variant_list)
    attr_val_map = get_attribute_values_map(variant_list)
    
    attributes = frappe.db.get_all(
    	"Item Variant Attribute",
    	fields=["attribute"],
    	filters={"parent": ["in", variant_list]},
    	group_by="attribute",
    )
    attribute_list = [row.get("attribute") for row in attributes]
    
    # Prepare dicts
    variant_dicts = [{"variant_name": d["name"]} for d in variant_results]
    for item_dict in variant_dicts:
    	name = item_dict.get("variant_name")
    	
    	for attribute in attribute_list:
    		attr_dict = attr_val_map.get(name)
    		if attr_dict and attr_dict.get(attribute):
    			item_dict[frappe.scrub(attribute)] = attr_val_map.get(name).get(attribute)
    			
    	item_dict["open_orders"] = order_count_map.get(name) or 0
    	
    	if stock_details_map.get(name):
    		stock_details = stock_details_map.get(name).get(warehouse, {})  # Include warehouse parameter
    		item_dict["current_stock"] = stock_details.get("Inventory") or 0
    		item_dict["in_production"] = stock_details.get("In Production") or 0
    	else:
    		item_dict["current_stock"] = item_dict["in_production"] = 0
    	
    	item_dict["avg_buying_price_list_rate"] = buying_price_map.get(name) or 0
    	item_dict["avg_selling_price_list_rate"] = selling_price_map.get(name) or 0
    	
    	item_dicts.append(item_dict)
    	
    return item_dicts     how i make method take value for warehouse from warehouse filed that i make it
    
  6. Assistant

    To make the get_data method take the value for the warehouse from the warehouse field, you can modify the method signature and add the warehouse parameter as shown below:

    def get_data(item, warehouse):
        if not item:
            return []
    
        # Rest of the code remains the same...
    

    Next, you need to modify the way the get_stock_details_map function is called and pass the warehouse parameter to it. Find the following line in your code:

    stock_details_map = get_stock_details_map(variant_list, warehouse)
    

    Replace it with the following line:

    stock_details_map = get_stock_details_map(variant_list, warehouse.name if warehouse else None)
    

    This passes the name property of the warehouse object if it exists, or None otherwise.

    Finally, make sure to update the method call to get_data in your code to pass the warehouse value from the filter. For example:

    data = get_data(item, filters.get("warehouse"))
    

    With these changes, the get_data method will now take the value for the warehouse from the warehouse field, enabling you to retrieve stock details specific to the selected warehouse.

  7. User

    variant_results = frappe.db.get_all( "Item", fields=["name"], filters={"variant_of": ["=", item], "disabled": 0} ) i want give parameter wharehouse value from that colume warehouse like item

  8. Assistant

    To pass the warehouse value from the warehouse field as a parameter to the frappe.db.get_all function, you can modify the filters as shown below:

    variant_results = frappe.db.get_all(
        "Item",
        fields=["name"],
        filters={"variant_of": ["=", item], "disabled": 0, "warehouse": ["=", warehouse]}
    )
    

    This adds the warehouse filter to the query, comparing the value of the warehouse column to the selected warehouse. This way, only items with a matching warehouse will be returned.

    Make sure to update the method signature of get_data to include the warehouse parameter as well:

    def get_data(item, warehouse):
        # Rest of the code...
    

    By passing the warehouse value from the warehouse field as a filter, you will retrieve only the items that belong to the selected warehouse.

  9. User

    App Versions

    {
    	"erpnext": "14.27.12",
    	"frappe": "14.49.0"
    }
    

    Route

    query-report/Item Variant Details
    

    Traceback

    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/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 232, 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 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 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/stock/report/item_variant_details/item_variant_details.py", line 11, in execute
        data = get_data(filters.item, filters.warehouse)
      File "apps/erpnext/erpnext/stock/report/item_variant_details/item_variant_details.py", line 31, in get_data
        stock_details_map = get_stock_details_map(variant_list, warehouse)  # Include warehouse parameter
    TypeError: get_stock_details_map() missing 1 required positional argument: 'warehouse'
    
    

    Request Data

    {
    	"type": "GET",
    	"args": {
    		"report_name": "Item Variant Details",
    		"filters": "{\"item\":\"STO-ITEM-2023-00001\",\"warehouse\":\"Stores - R\"}",
    		"ignore_prepared_report": false,
    		"are_default_filters": false
    	},
    	"headers": {},
    	"error_handlers": {},
    	"url": "/api/method/frappe.desk.query_report.run"
    }
    

    Response Data

    {
    	"exception": "TypeError: get_stock_details_map() missing 1 required positional argument: 'warehouse'"
    }
    
  10. Assistant

    The error indicates that the get_stock_details_map() function is missing a required positional argument: 'warehouse'. To resolve this issue, you need to update the function definition and calls to ensure the 'warehouse' parameter is included.

    In the item_variant_details.py file, locate the get_stock_details_map() function definition and modify it as follows:

    def get_stock_details_map(variant_list, warehouse=None):
        # Rest of the code...
    

    By adding warehouse=None as a parameter with a default value of None, it becomes an optional parameter.

    Next, find all the calls to the get_stock_details_map() function and pass the warehouse parameter accordingly. In your case, you need to modify the line where the get_stock_details_map() function is called in the get_data() method. Replace the line:

    stock_details_map = get_stock_details_map(variant_list, warehouse)
    

    With the following line:

    stock_details_map = get_stock_details_map(variant_list, warehouse=warehouse)
    

    This passes the warehouse value explicitly as a keyword argument, ensuring it is mapped to the correct parameter in the function.

    After making these changes, the get_stock_details_map() function should receive the warehouse value correctly, and the error should be resolved.

  11. User

    App Versions

    {
    	"erpnext": "14.27.12",
    	"frappe": "14.49.0"
    }
    

    Route

    query-report/Item Variant Details
    

    Traceback

    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/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 232, 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 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 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/stock/report/item_variant_details/item_variant_details.py", line 11, in execute
        data = get_data(filters.item, filters.warehouse)
      File "apps/erpnext/erpnext/stock/report/item_variant_details/item_variant_details.py", line 31, in get_data
        stock_details_map = get_stock_details_map(variant_list,  warehouse=warehouse)  # Include warehouse parameter
      File "apps/erpnext/erpnext/stock/report/item_variant_details/item_variant_details.py", line 144, in get_stock_details_map
        stock_details = frappe.db.get_all(
      File "apps/frappe/frappe/database/database.py", line 737, in get_all
        return frappe.get_all(*args, **kwargs)
      File "apps/frappe/frappe/__init__.py", line 1939, in get_all
        return get_list(doctype, *args, **kwargs)
      File "apps/frappe/frappe/__init__.py", line 1911, in get_list
        return frappe.model.db_query.DatabaseQuery(doctype).execute(*args, **kwargs)
      File "apps/frappe/frappe/model/db_query.py", line 196, in execute
        result = self.build_and_run()
      File "apps/frappe/frappe/model/db_query.py", line 211, in build_and_run
        args = self.prepare_args()
      File "apps/frappe/frappe/model/db_query.py", line 313, in prepare_args
        self.validate_order_by_and_group_by(self.group_by)
      File "apps/frappe/frappe/model/db_query.py", line 1070, in validate_order_by_and_group_by
        _lower = parameters.lower()
    AttributeError: 'list' object has no attribute 'lower'
    
    

    Request Data

    {
    	"type": "GET",
    	"args": {
    		"report_name": "Item Variant Details",
    		"filters": "{\"item\":\"STO-ITEM-2023-00008\",\"warehouse\":\"Stores - R\"}",
    		"ignore_prepared_report": false,
    		"are_default_filters": false
    	},
    	"headers": {},
    	"error_handlers": {},
    	"url": "/api/method/frappe.desk.query_report.run"
    }
    

    Response Data

    {
    	"exception": "AttributeError: 'list' object has no attribute 'lower'"
    }
    
  12. Assistant

    The error message suggests that there's an issue with converting a list object to lowercase. To resolve this issue, you need to check the group_by attribute in the build_and_run() method of the db_query.py file.

    To fix the error, follow these steps:

    1. Open the db_query.py file located at apps/frappe/frappe/model/db_query.py.
    2. Locate the build_and_run() method.
    3. Within this method, find the line where the prepare_args() method is called, and change the line from:
      args = self.prepare_args()
      
      to:
      args, kwargs = self.prepare_args()
      
      This modification ensures that the prepare_args() method returns a tuple of (args, kwargs) needed for the subsequent line.
    4. Next, find the prepare_args() method within the same file.
    5. Within this method, locate the line where the validate_order_by_and_group_by() method is called, and modify the line from:
      self.validate_order_by_and_group_by(self.group_by)
      
      to:
      self.validate_order_by_and_group_by(*self.group_by)
      
      This change allows the group_by attribute to be passed as separate arguments to the validate_order_by_and_group_by() method.
    6. Save the changes made to the file.

    After making these modifications, the issue related to the list object not having the lower() attribute should be resolved, and you should be able to run the "Item Variant Details" query report without encountering the error.