Spaces:
Running
Running
Update main.py
Browse files2350 unmodified lines2351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223837 unmodified lines2391239223932394239523962350 unmodified linesoffset: int = Query(0, ge=0),user_data: Tuple[str, str, str] = Depends(require_role(["owner", "admin", "inventory_manager", "sales_rep"]))):"""Server‑side search across inventory.description, item_code, and product_group.Returns paginated results with location_stocks for each item."""await rate_limit(get_client_ip(request), user_data[1])_, org_id, _ = user_dataclient = get_supabase()# Formulate the sub-clauses for the query string cleanlyfilter_str = f"description.ilike.%{q}%,item_code.ilike.%{q}%,product_group.ilike.%{q}%"# 1. Build the base query structurequery = (client.table("inventory").select("*, location_stocks!left(location_id, quantity, reserved_quantity)", count="exact").eq("org_id", org_id))# 2. Force append the raw query parameter directly into the request payload.# This completely eliminates SDK translation errors.query.params["or"] = f"({filter_str})"# 3. Add conditional location constraints if providedif location_id is not None:query = query.eq("location_stocks.location_id", location_id)# Execute pagination range smoothlyresult = await run_sync_db_call(query.range(offset, offset + limit - 1).execute)7 unmodified lines"limit": limit,"offset": offset}# ------------------------------------------------------------------# STOCK TRANSFER ENDPOINTS2350 unmodified lines23512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723787 unmodified lines23862387238823892390239123922350 unmodified linesoffset: int = Query(0, ge=0),user_data: Tuple[str, str, str] = Depends(require_role(["owner", "admin", "inventory_manager", "sales_rep"]))):await rate_limit(get_client_ip(request), user_data[1])_, org_id, _ = user_dataclient = get_supabase()# Build the OR condition for search fieldsor_condition = f"description.ilike.%{q}%,item_code.ilike.%{q}%,product_group.ilike.%{q}%"# Start the query with the left join to location_stocksquery = (client.table("inventory").select("*, location_stocks!left(location_id, quantity, reserved_quantity)", count="exact").eq("org_id", org_id))# Apply the OR filter using .set() – this is the crucial fixquery.params = query.params.set("or", f"({or_condition})")# If a location is specified, filter by that locationif location_id is not None:query = query.eq("location_stocks.location_id", location_id)# Execute with paginationresult = await run_sync_db_call(query.range(offset, offset + limit - 1).execute)7 unmodified lines"limit": limit,"offset": offset}}# ------------------------------------------------------------------# STOCK TRANSFER ENDPOINTS
main.py+8-12