diff --git a/discount/init.py b/discount/init.py index f8df9e5..4904d67 100644 --- a/discount/init.py +++ b/discount/init.py @@ -732,6 +732,7 @@ def load_discount(): env.assign_customer_to_sale = assign_customer_to_sale # Discount setting products list env.get_discount_setting_products = get_discount_setting_products + env.get_discount_info = get_discount_info async def get_discount_setting_products(request): @@ -771,3 +772,26 @@ async def get_discount_setting_products(request): async with db.sqlorContext(dbname) as sor: recs = await sor.sqlExe(sql, ns) return recs if recs else [] + + +async def get_discount_info(request): + """Get discount name and customer name for display header.""" + env = request._run_ns + discountid = (request._run_ns.params_kw or {}).get('discountid', '') + if not discountid: + return {} + dbname = env.get_module_dbname('discount') + db = DBPools() + config = getConfig() + db.databases = config.databases + sql = """ + SELECT d.name, o.orgname + FROM discount d + LEFT JOIN organization o ON d.customerid = o.id + WHERE d.id = ${discountid}$ + """ + async with db.sqlorContext(dbname) as sor: + recs = await sor.sqlExe(sql, {'discountid': discountid}) + if recs: + return {'name': recs[0].name or '', 'customer': recs[0].orgname or ''} + return {} diff --git a/wwwroot/discount_setting/index.ui b/wwwroot/discount_setting/index.ui index 531e75e..a604a08 100644 --- a/wwwroot/discount_setting/index.ui +++ b/wwwroot/discount_setting/index.ui @@ -1,4 +1,5 @@ {% set products = get_discount_setting_products(request) %} +{% set info = get_discount_info(request) %} { "widgettype": "VBox", "options": { @@ -10,7 +11,7 @@ { "widgettype": "Text", "options": { - "text": "产品折扣设置", + "text": "产品折扣设置 - {{info.name or ''}}{% if info.customer %} ({{info.customer}}){% endif %}", "fontSize": "16px", "fontWeight": "600", "color": "#F1F5F9",