items_API.getPossLocations updated to new schema
This commit is contained in:
parent
b75376899d
commit
780c43cd73
Binary file not shown.
Binary file not shown.
@ -169,7 +169,27 @@ def paginateZonesBySku(site: str, payload: tuple, convert=True):
|
|||||||
return zones, count
|
return zones, count
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
raise postsqldb.DatabaseError(error, payload, sql)
|
raise postsqldb.DatabaseError(error, payload, sql)
|
||||||
|
|
||||||
|
def paginateLocationsWithZone(site:str, payload:tuple, convert:bool=True):
|
||||||
|
recordset, count = (), 0
|
||||||
|
database_config = config.config()
|
||||||
|
with open(f"application/items/sql/getLocationsWithZone.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]
|
||||||
|
elif rows and not convert:
|
||||||
|
recordset = rows
|
||||||
|
cur.execute(f"SELECT COUNT(*) FROM {site}_locations;")
|
||||||
|
count = cur.fetchone()[0]
|
||||||
|
return recordset, count
|
||||||
|
except Exception as error:
|
||||||
|
raise postsqldb.DatabaseError(error, (), sql)
|
||||||
|
|
||||||
def paginateLocationsBySkuZone(site: str, payload: tuple, convert=True):
|
def paginateLocationsBySkuZone(site: str, payload: tuple, convert=True):
|
||||||
database_config = config.config()
|
database_config = config.config()
|
||||||
locations, count = (), 0
|
locations, count = (), 0
|
||||||
@ -306,6 +326,12 @@ def postUpdateItem(site:str, payload:dict):
|
|||||||
raise postsqldb.DatabaseError(error, payload, "MULTICALL!")
|
raise postsqldb.DatabaseError(error, payload, "MULTICALL!")
|
||||||
|
|
||||||
def postUpdateItemLink(site: str, payload: dict):
|
def postUpdateItemLink(site: str, payload: dict):
|
||||||
|
""" POST update to ItemLink
|
||||||
|
|
||||||
|
Args:
|
||||||
|
site (str): _description_
|
||||||
|
payload (dict): {id, update, old_conv_factor, user_id}
|
||||||
|
"""
|
||||||
def postUpdateData(conn, table, payload, convert=True):
|
def postUpdateData(conn, table, payload, convert=True):
|
||||||
updated = ()
|
updated = ()
|
||||||
set_clause, values = postsqldb.updateStringFactory(payload['update'])
|
set_clause, values = postsqldb.updateStringFactory(payload['update'])
|
||||||
@ -358,4 +384,5 @@ def postUpdateItemLink(site: str, payload: dict):
|
|||||||
)
|
)
|
||||||
|
|
||||||
postUpdateData(conn, f"{site}_itemlinks", {'id': payload['id'], 'update': {'conv_factor': payload['update']['conv_factor']}})
|
postUpdateData(conn, f"{site}_itemlinks", {'id': payload['id'], 'update': {'conv_factor': payload['update']['conv_factor']}})
|
||||||
postAddTransaction(conn, site, transaction.payload())
|
postAddTransaction(conn, site, transaction.payload())
|
||||||
|
|
||||||
|
|||||||
@ -379,6 +379,7 @@ def updateItem():
|
|||||||
return jsonify({'error': True, 'message': f'method {request.method} is not allowed!'})
|
return jsonify({'error': True, 'message': f'method {request.method} is not allowed!'})
|
||||||
|
|
||||||
@items_api.route('/item/updateItemLink', methods=['POST'])
|
@items_api.route('/item/updateItemLink', methods=['POST'])
|
||||||
|
@login_required
|
||||||
def updateItemLink():
|
def updateItemLink():
|
||||||
""" UPDATE item link by passing id, conv_factor, barcode, old_conv
|
""" UPDATE item link by passing id, conv_factor, barcode, old_conv
|
||||||
---
|
---
|
||||||
@ -428,15 +429,36 @@ def updateItemLink():
|
|||||||
@items_api.route('/item/getPossibleLocations', methods=["GET"])
|
@items_api.route('/item/getPossibleLocations', methods=["GET"])
|
||||||
@login_required
|
@login_required
|
||||||
def getPossibleLocations():
|
def getPossibleLocations():
|
||||||
|
""" GET locations with zones by passing a page and limit
|
||||||
|
---
|
||||||
|
parameters:
|
||||||
|
- in: query
|
||||||
|
name: page
|
||||||
|
schema:
|
||||||
|
type: interger
|
||||||
|
minimum: 1
|
||||||
|
default: 1
|
||||||
|
description: page in the records to GET
|
||||||
|
- in: query
|
||||||
|
name: limit
|
||||||
|
schema:
|
||||||
|
type: interger
|
||||||
|
minimum: 1
|
||||||
|
default: 1
|
||||||
|
description: number of records to GET
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: Locations GET successful.
|
||||||
|
"""
|
||||||
|
locations, count = (), 0
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
page = int(request.args.get('page', 1))
|
page = int(request.args.get('page', 1))
|
||||||
limit = int(request.args.get('limit', 1))
|
limit = int(request.args.get('limit', 1))
|
||||||
offset = (page-1)*limit
|
offset = (page-1)*limit
|
||||||
database_config = config()
|
|
||||||
site_name = session['selected_site']
|
site_name = session['selected_site']
|
||||||
with psycopg2.connect(**database_config) as conn:
|
locations, count = database_items.paginateLocationsWithZone(site_name, (limit, offset))
|
||||||
locations, count = db.LocationsTable.paginateLocationsWithZone(conn, site_name, (limit, offset))
|
return jsonify({'locations': locations, 'end':math.ceil(count/limit), 'error':False, 'message': f'Locations received successfully!'})
|
||||||
return jsonify(locations=locations, end=math.ceil(count/limit))
|
return jsonify({'locations': locations, 'end':math.ceil(count/limit), 'error':True, 'message': f'method {request.method} not allowed.'})
|
||||||
|
|
||||||
@items_api.route('/item/getLinkedItem', methods=["GET"])
|
@items_api.route('/item/getLinkedItem', methods=["GET"])
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
5
application/items/sql/getLocationsWithZone.sql
Normal file
5
application/items/sql/getLocationsWithZone.sql
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
SELECT %%site_name%%_locations.*,
|
||||||
|
row_to_json(%%site_name%%_zones.*) as zone
|
||||||
|
FROM %%site_name%%_locations
|
||||||
|
LEFT JOIN %%site_name%%_zones ON %%site_name%%_zones.id = %%site_name%%_locations.zone_id
|
||||||
|
LIMIT %s OFFSET %s;
|
||||||
Loading…
x
Reference in New Issue
Block a user