我正在使用 frappe 框架使用 python 和 sql 创建一个报告,但我收到一个我不明白的错误,None 怎么可能是未声明的变量?有人可以向我解释一下吗。希望有人能指出我正确的方向。
这是我的报告.py
def execute(filters=None):
if not filters:
filters = {}
conditions = get_conditions(filters)
columns = get_column(filters,conditions)
data = []
details = get_details(conditions,filters)
return columns, data
def get_details(conditions="", filters={}):
data = frappe.db.sql("""select i.ifw_retailskusuffix, i.item_code, i.item_name, i.image,
s.supplier, s.supplier_part_no, i.disabled, country_of_origin,customs_tariff_number,
ifw_duty_rate,ifw_discontinued,ifw_product_name_ci,ifw_item_notes,ifw_item_notes2,
ifw_po_notes
from `tabItem Supplier` s inner join `tabItem` i on i.name = s.parent
where 1 = 1 %s
"""%(conditions), filters, as_dict=1)
return data
def get_conditions(filters):
conditions = ""
suppliers = []
limit = filters.get("limit")
if filters.get('supplier'):
suppliers = frappe.parse_json(filters.get("supplier"))
suppliers.append("asa")
suppliers.append("asaa")
# format_strings = ','.join(['%s'] * len(suppliers))
conditions += " and s.supplier IN %(supplier)s"
if limit != "All":
conditions += " limit {}".format(str(limit))
return conditions
对应的javascript文件report.js
frappe.query_reports["Sales Report"] = {
"filters": [
{
"fieldname":"supplier",
"label": __("Supplier"),
"fieldtype": "MultiSelectList",
"options": "Supplier",
get_data: function(txt) {
// if (!frappe.query_report.filters) return;
// let party_type = frappe.query_report.get_filter_value('party_type');
// if (!party_type) return;
return frappe.db.get_link_options("Supplier", txt);
},
},
{
"fieldname":"limit",
"label": __("Limit"),
"fieldtype": "Select",
"options": ["20", "500", "1000", "5000", "10000", "All"],
"default": "20"
},
]
};