pymysql.err.ProgrammingError: (1064, “You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘)\n\n group by sli.item_code’ at line 20”)
iam sorry my friend i dont understand , you can see all script mybe you take good idea about my issue
sql_brand_filter = ""
if filters.get("brand"):
escaped_input in str(tuple(filters.get("brand")))
sql_brand_filter = f"AND i.brand in {escaped_input}"
res = frappe.db.sql(f"""SELECT
sli.item_code,
i.item_name,
i.item_master_barcode,
sum(CASE WHEN sli.warehouse ='s1' THEN sli.actual_qty ELSE 0 END) AS A,
sum(CASE WHEN sli.warehouse ='s2' THEN sli.actual_qty ELSE 0 END) AS B
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
I think it will satisfy your query and conditions. Replicate them and try this. Also, add your customizations like ‘barcode_master_filter’.
This code will run SQL like this
SELECT `tabBin`.`item_code`,`tabItem`.`item_name`,SUM(CASE WHEN `tabBin`.`warehouse`='s1' THEN `tabBin`.`actual_qty` ELSE 0 END) `A`,SUM(CASE WHEN `tabBin`.`warehouse`='s2' THEN `tabBin`.`actual_qty` ELSE 0 END) `B` FROM `tabBin` JOIN `tabItem` ON `tabBin`.`item_code`=`tabItem`.`name` WHERE `tabItem`.`brand` IN ('brand1','brand2') AND `tabItem`.`item_group` IN ('Discaount Group','With Out Discaount')
I believe this query is exactly what you need.
If Pypika seems confusing to you or you hesitate to use it, try using this query instead
@osk You need to write code in your_custom_app/app_module/report/custom_report/custom_report.py. If you’re using a script field, you’ll need to write the code slightly differently
Please refer to this tutorial for getting familiar with script reports and specifically using multiselect data (towards the end of the tutorial) [Tutorial] Script Report / Chart