how can i filter data on the script report () and choosing multi data as i need
example i want to chose specific brand from item by using multi select in the filter
how can i filter data on the script report () and choosing multi data as i need
example i want to chose specific brand from item by using multi select in the filter
thank you for the help but i need more i’m not professional. could you explain to me if it possible
Yeah, it’s possible. Try using this code:
i maked this code but the report is stop appearing data
frappe.query_reports["Close Stock Balance2"] = {
"filters": [
{
'fieldname': 'brand',
'label': 'Brand',
'fieldtype': 'MultiSelectLest',
'get_data': function() {
return frappe.db.get_link_options('Brand')
}
}
]
};
You need to handle the logic in the backend, meaning Python, and return the columns along with the corresponding data for those columns
now i can make multi select but there is no data appering in the table
i use this code for filter
sql_brand_filter = ""
if filters.get("brand"):
escaped_input = frappe.db.escape(filters.get("brand"))
sql_brand_filter = f"AND i.brand = {escaped_input}"
check the console to see if there are any errors. If there are no errors in the console, then verify whether the data and columns are being returned properly from the backend
there is no error also when i remove filter everything is ok and i get data but when i choose multi brand i dont get anything
One more thing, change the query to use LIKE
instead of =
because you are selecting multiple data. Utilize LIKE
or OR
filters to match patterns across multiple values. Consider using the frappe.db
methods to retrieve the data or utilize the frappe.query_builder
to construct the query, as it will be more easy
sql_item_barcode_filter = ""
if filters.get("item_master_barcode"):
escaped_input = frappe.db.escape(filters.get("item_master_barcode"))
sql_item_barcode_filter = f"AND i.item_master_barcode = {escaped_input}"
sql_brand_filter = ""
if filters.get("brand"):
escaped_input = frappe.db.escape(filters.get("brand"))
sql_brand_filter = f"AND i.brand = {escaped_input}"
res = frappe.db.sql(f"""SELECT
sli.item_code,
i.item_name,
i.item_master_barcode,
sum(CASE WHEN sli.warehouse ='st1' THEN sli.actual_qty ELSE 0 END) AS A,
sum(CASE WHEN sli.warehouse ='st2' THEN sli.actual_qty ELSE 0 END) AS B,
sli.ordered_qty AS D,
i.custom_qty_on_the_shelf AS e
from `tabBin` sli
inner join `tabItem` i on sli.item_code = i.item_code
where i.item_group in ('Discaount Group','With Out Discaount')
{sql_brand_filter}
{sql_item_barcode_filter}
group by sli.item_code
""", as_dict=True)
result = res
this is my code the problem is still