items_API.getSkuPrefixes updated to new schema
This commit is contained in:
parent
5fadebb2e4
commit
84544cc48f
Binary file not shown.
Binary file not shown.
@ -106,3 +106,25 @@ def getModalSKUs(site:str, payload:tuple, convert:bool=True):
|
||||
return recordset, count
|
||||
except Exception as error:
|
||||
raise postsqldb.DatabaseError(error, payload, sql)
|
||||
|
||||
def getPrefixes(site:str, payload:tuple, convert:bool=True):
|
||||
database_config = config.config()
|
||||
recordset = []
|
||||
count = 0
|
||||
with open(f"application/items/sql/getSkuPrefixes.sql", "r+") as file:
|
||||
sql = file.read().replace("%%site_name%%", site)
|
||||
try:
|
||||
with psycopg2.connect(**database_config) as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(sql, payload)
|
||||
rows = cur.fetchall()
|
||||
if rows and convert:
|
||||
recordset = [postsqldb.tupleDictionaryFactory(cur.description, row) for row in rows]
|
||||
if rows and not convert:
|
||||
recordset = rows
|
||||
|
||||
cur.execute(f"SELECT COUNT(*) FROM {site}_sku_prefix;")
|
||||
count = cur.fetchone()[0]
|
||||
return recordset, count
|
||||
except (Exception, psycopg2.DatabaseError) as error:
|
||||
raise postsqldb.DatabaseError(error, payload, sql)
|
||||
|
||||
@ -190,19 +190,38 @@ def getModalItems():
|
||||
@items_api.route('/item/getPrefixes', methods=["GET"])
|
||||
@login_required
|
||||
def getModalPrefixes():
|
||||
""" GET prefixes from the system by passing page and limit.
|
||||
---
|
||||
parameters:
|
||||
- in: query
|
||||
name: page
|
||||
schema:
|
||||
type: integer
|
||||
minimum: 1
|
||||
default: 1
|
||||
description: page of the database records
|
||||
- in: query
|
||||
name: limit
|
||||
schema:
|
||||
type: integer
|
||||
minimum: 1
|
||||
default: 10
|
||||
description: number of database records to GET
|
||||
responses:
|
||||
200:
|
||||
description: Prefixes received from the system successfully!
|
||||
"""
|
||||
recordset = []
|
||||
count = {'count': 0}
|
||||
count = 0
|
||||
if request.method == "GET":
|
||||
page = int(request.args.get('page', 1))
|
||||
limit = int(request.args.get('limit', 10))
|
||||
site_name = session['selected_site']
|
||||
offset = (page - 1) * limit
|
||||
database_config = config()
|
||||
with psycopg2.connect(**database_config) as conn:
|
||||
payload = (limit, offset)
|
||||
recordset, count = db.SKUPrefixTable.paginatePrefixes(conn, site_name, payload, convert=True)
|
||||
recordset, count = database_items.getPrefixes(site_name, (limit, offset))
|
||||
print(recordset, count)
|
||||
return jsonify({"prefixes":recordset, "end":math.ceil(count/limit), "error":False, "message":"items fetched succesfully!"})
|
||||
return jsonify({"prefixes":recordset, "end":math.ceil(count/limit), "error":True, "message":"There was an error with this GET statement"})
|
||||
return jsonify({"prefixes":recordset, "end":math.ceil(count/limit), "error":True, "message":f"method {request.method} is not allowed!"})
|
||||
|
||||
|
||||
@items_api.route('/item/getZones', methods=['GET'])
|
||||
|
||||
1
application/items/sql/getSkuPrefixes.sql
Normal file
1
application/items/sql/getSkuPrefixes.sql
Normal file
@ -0,0 +1 @@
|
||||
SELECT * FROM %%site_name%%_sku_prefix LIMIT %s OFFSET %s;
|
||||
@ -1899,3 +1899,6 @@
|
||||
2025-04-27 13:32:50.773052 --- ERROR --- DatabaseError(message='syntax error at or near "5"LINE 15: LIMIT 5 OFFSET 5; ^',
|
||||
payload=['', 5, 5],
|
||||
sql='WITH sum_cte AS ( SELECT mi.id, SUM(mil.quantity_on_hand)::FLOAT8 AS total_sum FROM main_item_locations mil JOIN main_items mi ON mil.part_id = mi.id GROUP BY mi.id )SELECT item.id, item.description, item.item_name, sum_cte.total_sum as total_qoh, u.fullnameFROM main_items itemLEFT JOIN sum_cte ON item.id = sum_cte.idLEFT JOIN main_item_info item_info ON item.item_info_id = item_info.idLEFT JOIN units u ON item_info.uom = u.idWHERE item.search_string LIKE '%%' || %s || '%%'ORDER BY item. LIMIT %s OFFSET %s;')
|
||||
2025-04-27 16:28:48.252706 --- ERROR --- DatabaseError(message='tuple index out of range',
|
||||
payload=(2, 0),
|
||||
sql='SELECT item.id, item.barcode, item.item_name FROM test_items itemWHERE item.search_string LIKE '%%' || %s || '%%'LIMIT %s OFFSET %s;')
|
||||
Loading…
x
Reference in New Issue
Block a user