From 62f07bc8bbe1591a27864c8a067c6786415b57ef Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 5 Jul 2026 14:24:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20before=5Finsert=20hook=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=A1=AB=E5=85=85sale=5Fid+resellerid;=20sync=20generate=5Fpro?= =?UTF-8?q?mo=5Fqr=E5=88=B0site-packages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- discount/init.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/discount/init.py b/discount/init.py index 011f0c1..60c57ce 100644 --- a/discount/init.py +++ b/discount/init.py @@ -753,8 +753,19 @@ async def assign_customer_to_sale(request, params_kw): return {'status': 'success', 'id': bind_id} +async def sor_before_insert_discount_promo_code(env, sor, ns): + """CRUD hook: auto-set sale_id from logged-in user on insert.""" + from appPublic.uniqueID import getID as _getID + ns['id'] = ns.get('id') or _getID() + ns['sale_id'] = ns.get('sale_id') or await env.get_userid() + ns['resellerid'] = ns.get('resellerid') or await env.get_userorgid() + + def load_discount(): env = ServerEnv() + # before_insert hooks + env.sor_before_insert_discount_promo_code = sor_before_insert_discount_promo_code + # existing registrations... env.get_customer_discount = get_customer_discount env.sor_get_customer_discount = sor_get_customer_discount env.get_product_discount = get_product_discount