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