diff --git a/accounting/creditlimit.py b/accounting/creditlimit.py index 83bf0e8..7a40277 100644 --- a/accounting/creditlimit.py +++ b/accounting/creditlimit.py @@ -72,7 +72,7 @@ async def get_all_customer_credits(sor, orgid, status_filter=None): For distributor sales to see all their customers' credit status. """ where_clause = "WHERE cl.orgid = ${orgid}$" - params = {'orgid': orgid} + params = {'orgid': orgid, 'sort': 'update_at desc'} if status_filter and status_filter != 'all': where_clause += " AND cl.status = ${status}$" params['status'] = status_filter @@ -92,9 +92,10 @@ async def get_all_customer_credits(sor, orgid, status_filter=None): LEFT JOIN account acc ON cl.accountid = acc.id COLLATE utf8mb4_unicode_ci LEFT JOIN subject sub ON acc.subjectid = sub.id COLLATE utf8mb4_unicode_ci {where_clause} - ORDER BY cl.updated_at DESC """ - recs = await sor.sqlExe(sql, params) + recs = await sor.sqlExe(sql, params.copy()) + if len(recs) == 0: + debug(f'{sql=}, {params=} get no data') return recs diff --git a/accounting/init.py b/accounting/init.py index e9ae4b8..df9de65 100644 --- a/accounting/init.py +++ b/accounting/init.py @@ -105,6 +105,6 @@ async def get_all_credits_web(request): """Web wrapper for get_all_customer_credits - used in Jinja2 .ui templates""" env = request._run_ns userorgid = await env.get_userorgid() - status_filter = getattr(request, '_params_kw', {}).get('status', None) if hasattr(request, '_params_kw') else None + status_filter = env.params_kw.get('status', None) async with get_sor_context(env, 'accounting') as sor: return await get_all_customer_credits(sor, userorgid, status_filter)