Finished basic migration for POE module
This commit is contained in:
parent
109c7fbd31
commit
1018414200
@ -4,19 +4,10 @@ from flask import (
|
|||||||
)
|
)
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import math
|
import math
|
||||||
import json
|
|
||||||
import datetime
|
|
||||||
import copy
|
|
||||||
import requests
|
|
||||||
import pprint
|
|
||||||
|
|
||||||
# applications imports
|
# applications imports
|
||||||
from config import config, sites_config
|
from config import config
|
||||||
from main import unfoldCostLayers
|
|
||||||
import process
|
|
||||||
import database
|
|
||||||
import main
|
|
||||||
import MyDataclasses
|
|
||||||
from user_api import login_required
|
from user_api import login_required
|
||||||
import application.postsqldb as db
|
import application.postsqldb as db
|
||||||
from application.items import database_items
|
from application.items import database_items
|
||||||
@ -36,7 +27,7 @@ def update_session_user():
|
|||||||
@login_required
|
@login_required
|
||||||
def items():
|
def items():
|
||||||
update_session_user()
|
update_session_user()
|
||||||
sites = [site[1] for site in main.get_sites(session['user']['sites'])]
|
sites = [site[1] for site in db.get_sites(session['user']['sites'])]
|
||||||
return render_template("index.html",
|
return render_template("index.html",
|
||||||
current_site=session['selected_site'],
|
current_site=session['selected_site'],
|
||||||
sites=sites)
|
sites=sites)
|
||||||
@ -44,7 +35,7 @@ def items():
|
|||||||
@items_api.route("/<id>")
|
@items_api.route("/<id>")
|
||||||
@login_required
|
@login_required
|
||||||
def item(id):
|
def item(id):
|
||||||
sites = [site[1] for site in main.get_sites(session['user']['sites'])]
|
sites = [site[1] for site in db.get_sites(session['user']['sites'])]
|
||||||
database_config = config()
|
database_config = config()
|
||||||
with psycopg2.connect(**database_config) as conn:
|
with psycopg2.connect(**database_config) as conn:
|
||||||
units = db.UnitsTable.getAll(conn)
|
units = db.UnitsTable.getAll(conn)
|
||||||
@ -53,7 +44,7 @@ def item(id):
|
|||||||
@items_api.route("/transaction")
|
@items_api.route("/transaction")
|
||||||
@login_required
|
@login_required
|
||||||
def transaction():
|
def transaction():
|
||||||
sites = [site[1] for site in main.get_sites(session['user']['sites'])]
|
sites = [site[1] for site in db.get_sites(session['user']['sites'])]
|
||||||
database_config = config()
|
database_config = config()
|
||||||
with psycopg2.connect(**database_config) as conn:
|
with psycopg2.connect(**database_config) as conn:
|
||||||
units = db.UnitsTable.getAll(conn)
|
units = db.UnitsTable.getAll(conn)
|
||||||
@ -74,13 +65,13 @@ def transactions(id):
|
|||||||
200:
|
200:
|
||||||
description: Returns the transactions.html webpage for the item with passed ID
|
description: Returns the transactions.html webpage for the item with passed ID
|
||||||
"""
|
"""
|
||||||
sites = [site[1] for site in main.get_sites(session['user']['sites'])]
|
sites = [site[1] for site in db.get_sites(session['user']['sites'])]
|
||||||
return render_template("transactions.html", id=id, current_site=session['selected_site'], sites=sites)
|
return render_template("transactions.html", id=id, current_site=session['selected_site'], sites=sites)
|
||||||
|
|
||||||
@items_api.route("/<parent_id>/itemLink/<id>")
|
@items_api.route("/<parent_id>/itemLink/<id>")
|
||||||
@login_required
|
@login_required
|
||||||
def itemLink(parent_id, id):
|
def itemLink(parent_id, id):
|
||||||
sites = [site[1] for site in main.get_sites(session['user']['sites'])]
|
sites = [site[1] for site in db.get_sites(session['user']['sites'])]
|
||||||
return render_template("itemlink.html", current_site=session['selected_site'], sites=sites, proto={'referrer': request.referrer}, id=id)
|
return render_template("itemlink.html", current_site=session['selected_site'], sites=sites, proto={'referrer': request.referrer}, id=id)
|
||||||
|
|
||||||
@items_api.route("/getTransactions", methods=["GET"])
|
@items_api.route("/getTransactions", methods=["GET"])
|
||||||
|
|||||||
@ -1,103 +1,55 @@
|
|||||||
from flask import Blueprint, request, render_template, redirect, session, url_for, send_file, jsonify, Response
|
# 3rd Party imports
|
||||||
import psycopg2, math, json, datetime, main, copy, requests, process, database, pprint, MyDataclasses
|
from flask import (
|
||||||
from config import config, sites_config
|
Blueprint, request, render_template, redirect, session, url_for, send_file, jsonify, Response
|
||||||
from main import unfoldCostLayers
|
)
|
||||||
from threading import Thread
|
import psycopg2
|
||||||
from queue import Queue
|
|
||||||
import time, process
|
# applications imports
|
||||||
|
from config import config
|
||||||
from user_api import login_required
|
from user_api import login_required
|
||||||
import webpush
|
from application.poe import poe_processes, poe_database
|
||||||
from application.poe import poe_processes
|
|
||||||
from application import postsqldb
|
from application import postsqldb
|
||||||
|
|
||||||
|
|
||||||
point_of_ease = Blueprint('poe', __name__, template_folder="templates", static_folder="static")
|
point_of_ease = Blueprint('poe', __name__, template_folder="templates", static_folder="static")
|
||||||
|
|
||||||
|
|
||||||
@point_of_ease.route('/scanner', methods=["GET"])
|
@point_of_ease.route('/scanner', methods=["GET"])
|
||||||
|
@login_required
|
||||||
def scannerEndpoint():
|
def scannerEndpoint():
|
||||||
sites = [site[1] for site in main.get_sites(session['user']['sites'])]
|
sites = [site[1] for site in postsqldb.get_sites(session['user']['sites'])]
|
||||||
return render_template('scanner.html', current_site=session['selected_site'],
|
return render_template('scanner.html', current_site=session['selected_site'],
|
||||||
sites=sites)
|
sites=sites)
|
||||||
|
|
||||||
@point_of_ease.route('/receipts', methods=["GET"])
|
@point_of_ease.route('/receipts', methods=["GET"])
|
||||||
|
@login_required
|
||||||
def receiptsEndpoint():
|
def receiptsEndpoint():
|
||||||
sites = [site[1] for site in main.get_sites(session['user']['sites'])]
|
sites = [site[1] for site in postsqldb.get_sites(session['user']['sites'])]
|
||||||
database_config = config()
|
database_config = config()
|
||||||
with psycopg2.connect(**database_config) as conn:
|
with psycopg2.connect(**database_config) as conn:
|
||||||
units = postsqldb.UnitsTable.getAll(conn)
|
units = postsqldb.UnitsTable.getAll(conn)
|
||||||
#units = db.UnitsTable.getAll(conn)
|
|
||||||
return render_template('receipts.html', current_site=session['selected_site'],
|
return render_template('receipts.html', current_site=session['selected_site'],
|
||||||
sites=sites, units=units)
|
sites=sites, units=units)
|
||||||
|
|
||||||
# DONT NEED
|
|
||||||
@point_of_ease.route('/getItemLocations', methods=["GET"])
|
|
||||||
def getItemLocations():
|
|
||||||
recordset = []
|
|
||||||
count = 0
|
|
||||||
if request.method == "GET":
|
|
||||||
item_id = int(request.args.get('id', 1))
|
|
||||||
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:
|
|
||||||
recordset, count = database.getItemLocations(conn, site_name, (item_id, limit, offset), convert=True)
|
|
||||||
return jsonify({"locations":recordset, "end":math.ceil(count/limit), "error":False, "message":"item fetched succesfully!"})
|
|
||||||
return jsonify({"locations":recordset, "end": math.ceil(count/limit), "error":True, "message":"There was an error with this GET statement"})
|
|
||||||
|
|
||||||
|
|
||||||
# in item api, DONT NEED
|
|
||||||
@point_of_ease.route('/getItem', methods=["GET"])
|
|
||||||
def getItem():
|
|
||||||
record = {}
|
|
||||||
if request.method == "GET":
|
|
||||||
item_id = int(request.args.get('id', 1))
|
|
||||||
site_name = session['selected_site']
|
|
||||||
database_config = config()
|
|
||||||
with psycopg2.connect(**database_config) as conn:
|
|
||||||
record = database.getItemAllByID(conn, site_name, (item_id, ), convert=True)
|
|
||||||
return jsonify({"item":record, "error":False, "message":"item fetched succesfully!"})
|
|
||||||
return jsonify({"item":record, "error":True, "message":"There was an error with this GET statement"})
|
|
||||||
|
|
||||||
@point_of_ease.route('/getItem/barcode', methods=["GET"])
|
@point_of_ease.route('/getItem/barcode', methods=["GET"])
|
||||||
|
@login_required
|
||||||
def getItemBarcode():
|
def getItemBarcode():
|
||||||
record = {}
|
record = {}
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
item_barcode = f"%{str(request.args.get('barcode', 1))}%"
|
item_barcode = f"%{str(request.args.get('barcode', 1))}%"
|
||||||
site_name = session['selected_site']
|
site_name = session['selected_site']
|
||||||
database_config = config()
|
record = poe_database.selectItemAllByBarcode(site_name, (item_barcode,))
|
||||||
with psycopg2.connect(**database_config) as conn:
|
|
||||||
record = database.getItemAllByBarcode(conn, site_name, (item_barcode, ), convert=True)
|
|
||||||
if record == {}:
|
if record == {}:
|
||||||
return jsonify({"item":None, "error":True, "message":"Item either does not exist or there was a larger problem!"})
|
return jsonify({"item":None, "error":True, "message":"Item either does not exist or there was a larger problem!"})
|
||||||
else:
|
else:
|
||||||
return jsonify({"item":record, "error":False, "message":"item fetched succesfully!"})
|
return jsonify({"item":record, "error":False, "message":"item fetched succesfully!"})
|
||||||
return jsonify({"item":record, "error":True, "message":"There was an error with this GET statement"})
|
return jsonify({"item":record, "error":True, "message":"There was an error with this GET statement"})
|
||||||
|
|
||||||
# in items api DONT NEED
|
|
||||||
@point_of_ease.route('/getModalItems', methods=["GET"])
|
|
||||||
@login_required
|
|
||||||
def getModalItems():
|
|
||||||
recordset = []
|
|
||||||
count = {'count': 0}
|
|
||||||
if request.method == "GET":
|
|
||||||
page = int(request.args.get('page', 1))
|
|
||||||
limit = int(request.args.get('limit', 10))
|
|
||||||
search_string = request.args.get('search_string', '')
|
|
||||||
site_name = session['selected_site']
|
|
||||||
offset = (page - 1) * limit
|
|
||||||
database_config = config()
|
|
||||||
with psycopg2.connect(**database_config) as conn:
|
|
||||||
payload = (search_string, limit, offset)
|
|
||||||
recordset, count = database.getItemsForModal(conn, site_name, payload, convert=True)
|
|
||||||
return jsonify({"items":recordset, "end":math.ceil(count['count']/limit), "error":False, "message":"items fetched succesfully!"})
|
|
||||||
return jsonify({"items":recordset, "end":math.ceil(count['count']/limit), "error":True, "message":"There was an error with this GET statement"})
|
|
||||||
|
|
||||||
@point_of_ease.route('/postTransaction', methods=["POST"])
|
@point_of_ease.route('/postTransaction', methods=["POST"])
|
||||||
|
@login_required
|
||||||
def post_transaction():
|
def post_transaction():
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
print('test two')
|
|
||||||
result = poe_processes.postTransaction(
|
result = poe_processes.postTransaction(
|
||||||
site_name=session['selected_site'],
|
site_name=session['selected_site'],
|
||||||
user_id=session['user_id'],
|
user_id=session['user_id'],
|
||||||
@ -108,6 +60,7 @@ def post_transaction():
|
|||||||
|
|
||||||
|
|
||||||
@point_of_ease.route('/postReceipt', methods=["POST"])
|
@point_of_ease.route('/postReceipt', methods=["POST"])
|
||||||
|
@login_required
|
||||||
def post_receipt():
|
def post_receipt():
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
site_name = session['selected_site']
|
site_name = session['selected_site']
|
||||||
|
|||||||
@ -156,6 +156,96 @@ def selectItemLocationsTuple(site_name, payload, convert=True, conn=None):
|
|||||||
except Exception as error:
|
except Exception as error:
|
||||||
return error
|
return error
|
||||||
|
|
||||||
|
def selectLinkedItemByBarcode(site, payload, convert=True, conn=None):
|
||||||
|
item = ()
|
||||||
|
self_conn = False
|
||||||
|
sql = f"SELECT * FROM {site}_itemlinks WHERE barcode=%s;"
|
||||||
|
try:
|
||||||
|
if not conn:
|
||||||
|
database_config = config.config()
|
||||||
|
conn = psycopg2.connect(**database_config)
|
||||||
|
conn.autocommit = True
|
||||||
|
self_conn = True
|
||||||
|
|
||||||
|
with conn.cursor() as cur:
|
||||||
|
cur.execute(sql, payload)
|
||||||
|
rows = cur.fetchone()
|
||||||
|
if rows and convert:
|
||||||
|
item = postsqldb.tupleDictionaryFactory(cur.description, rows)
|
||||||
|
if rows and not convert:
|
||||||
|
item = rows
|
||||||
|
|
||||||
|
if self_conn:
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
return item
|
||||||
|
except (Exception, psycopg2.DatabaseError) as error:
|
||||||
|
raise postsqldb.DatabaseError(error, payload, sql)
|
||||||
|
|
||||||
|
def selectItemAllByID(site, payload, convert=True, conn=None):
|
||||||
|
item = ()
|
||||||
|
self_conn = False
|
||||||
|
|
||||||
|
with open(f"application/poe/sql/getItemAllByID.sql", "r+") as file:
|
||||||
|
getItemAllByID_sql = file.read().replace("%%site_name%%", site)
|
||||||
|
try:
|
||||||
|
if not conn:
|
||||||
|
database_config = config.config()
|
||||||
|
conn = psycopg2.connect(**database_config)
|
||||||
|
conn.autocommit = True
|
||||||
|
self_conn = True
|
||||||
|
|
||||||
|
with conn.cursor() as cur:
|
||||||
|
cur.execute(getItemAllByID_sql, payload)
|
||||||
|
rows = cur.fetchone()
|
||||||
|
if rows and convert:
|
||||||
|
item = postsqldb.tupleDictionaryFactory(cur.description, rows)
|
||||||
|
if rows and not convert:
|
||||||
|
item = rows
|
||||||
|
|
||||||
|
if self_conn:
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
return item
|
||||||
|
except (Exception, psycopg2.DatabaseError) as error:
|
||||||
|
raise postsqldb.DatabaseError(error, payload, getItemAllByID_sql)
|
||||||
|
|
||||||
|
def selectItemAllByBarcode(site, payload, convert=True, conn=None):
|
||||||
|
item = ()
|
||||||
|
self_conn = False
|
||||||
|
linked_item = selectLinkedItemByBarcode(site, (payload[0],))
|
||||||
|
|
||||||
|
if len(linked_item) > 1:
|
||||||
|
item = selectItemAllByID(site, payload=(linked_item['link'], ), convert=convert)
|
||||||
|
item['item_info']['uom_quantity'] = linked_item['conv_factor']
|
||||||
|
else:
|
||||||
|
with open(f"application/poe/sql/getItemAllByBarcode.sql", "r+") as file:
|
||||||
|
getItemAllByBarcode_sql = file.read().replace("%%site_name%%", site)
|
||||||
|
try:
|
||||||
|
if not conn:
|
||||||
|
database_config = config.config()
|
||||||
|
conn = psycopg2.connect(**database_config)
|
||||||
|
conn.autocommit = True
|
||||||
|
self_conn = True
|
||||||
|
|
||||||
|
with conn.cursor() as cur:
|
||||||
|
cur.execute(getItemAllByBarcode_sql, payload)
|
||||||
|
rows = cur.fetchone()
|
||||||
|
if rows and convert:
|
||||||
|
item = postsqldb.tupleDictionaryFactory(cur.description, rows)
|
||||||
|
if rows and not convert:
|
||||||
|
item = rows
|
||||||
|
|
||||||
|
if self_conn:
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
except (Exception, psycopg2.DatabaseError) as error:
|
||||||
|
raise postsqldb.DatabaseError(error, payload, getItemAllByBarcode_sql)
|
||||||
|
return item
|
||||||
|
|
||||||
def insertCostLayersTuple(site, payload, convert=True, conn=None):
|
def insertCostLayersTuple(site, payload, convert=True, conn=None):
|
||||||
cost_layer = ()
|
cost_layer = ()
|
||||||
self_conn = False
|
self_conn = False
|
||||||
|
|||||||
@ -1,12 +1,18 @@
|
|||||||
from application import postsqldb, database_payloads
|
# 3rd Party imports
|
||||||
from application.poe import poe_database
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import psycopg2
|
import psycopg2
|
||||||
|
|
||||||
|
# applications imports
|
||||||
|
from application import postsqldb, database_payloads
|
||||||
|
from application.poe import poe_database
|
||||||
import config
|
import config
|
||||||
|
|
||||||
|
""" This module will hold all the multilayerd/complex process used in the
|
||||||
|
point of ease module. """
|
||||||
|
|
||||||
|
|
||||||
def postTransaction(site_name, user_id, data: dict, conn=None):
|
def postTransaction(site_name, user_id, data: dict, conn=None):
|
||||||
|
'''Takes a set of data as a dictionary and inserts them into the system for passed site_name. '''
|
||||||
#dict_keys(['item_id', 'logistics_info_id', 'barcode', 'item_name', 'transaction_type',
|
#dict_keys(['item_id', 'logistics_info_id', 'barcode', 'item_name', 'transaction_type',
|
||||||
# 'quantity', 'description', 'cost', 'vendor', 'expires', 'location_id'])
|
# 'quantity', 'description', 'cost', 'vendor', 'expires', 'location_id'])
|
||||||
def quantityFactory(quantity_on_hand:float, quantity:float, transaction_type:str):
|
def quantityFactory(quantity_on_hand:float, quantity:float, transaction_type:str):
|
||||||
@ -47,18 +53,15 @@ def postTransaction(site_name, user_id, data: dict, conn=None):
|
|||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
#location = database.selectItemLocationsTuple(conn, site_name, payload=(data['item_id'], data['location_id']), convert=True)
|
|
||||||
location = poe_database.selectItemLocationsTuple(site_name, payload=(data['item_id'], data['location_id']), conn=conn)
|
location = poe_database.selectItemLocationsTuple(site_name, payload=(data['item_id'], data['location_id']), conn=conn)
|
||||||
cost_layers: list = location['cost_layers']
|
cost_layers: list = location['cost_layers']
|
||||||
if data['transaction_type'] == "Adjust In":
|
if data['transaction_type'] == "Adjust In":
|
||||||
cost_layer = poe_database.insertCostLayersTuple(site_name, cost_layer.payload(), conn=conn)
|
cost_layer = poe_database.insertCostLayersTuple(site_name, cost_layer.payload(), conn=conn)
|
||||||
#cost_layer = database.insertCostLayersTuple(conn, site_name, cost_layer.payload(), convert=True)
|
|
||||||
cost_layers.append(cost_layer['id'])
|
cost_layers.append(cost_layer['id'])
|
||||||
|
|
||||||
if data['transaction_type'] == "Adjust Out":
|
if data['transaction_type'] == "Adjust Out":
|
||||||
if float(location['quantity_on_hand']) < float(data['quantity']):
|
if float(location['quantity_on_hand']) < float(data['quantity']):
|
||||||
return {"error":True, "message":f"The quantity on hand in the chosen location is not enough to satisfy your transaction!"}
|
return {"error":True, "message":f"The quantity on hand in the chosen location is not enough to satisfy your transaction!"}
|
||||||
#cost_layers = database.selectCostLayersTuple(conn, site_name, (location['id'], ), convert=True)
|
|
||||||
cost_layers = poe_database.selectCostLayersTuple(site_name, payload=(location['id'], ))
|
cost_layers = poe_database.selectCostLayersTuple(site_name, payload=(location['id'], ))
|
||||||
|
|
||||||
new_cost_layers = []
|
new_cost_layers = []
|
||||||
@ -73,12 +76,10 @@ def postTransaction(site_name, user_id, data: dict, conn=None):
|
|||||||
layer['quantity'] -= qty
|
layer['quantity'] -= qty
|
||||||
new_cost_layers.append(layer['id'])
|
new_cost_layers.append(layer['id'])
|
||||||
poe_database.updateCostLayersTuple(site_name, {'id': layer['id'], 'update': {'quantity': layer['quantity']}}, conn=conn)
|
poe_database.updateCostLayersTuple(site_name, {'id': layer['id'], 'update': {'quantity': layer['quantity']}}, conn=conn)
|
||||||
#database.__updateTuple(conn, site_name, f"{site_name}_cost_layers", {'id': layer['id'], 'update': {'quantity': layer['quantity']}})
|
|
||||||
qty = 0.0
|
qty = 0.0
|
||||||
|
|
||||||
if layer['quantity'] == 0.0:
|
if layer['quantity'] == 0.0:
|
||||||
poe_database.deleteCostLayersTuple(site_name, (layer['id'],), conn=conn)
|
poe_database.deleteCostLayersTuple(site_name, (layer['id'],), conn=conn)
|
||||||
#database.deleteCostLayersTuple(conn, site_name, (layer['id'], ))
|
|
||||||
|
|
||||||
cost_layers = new_cost_layers
|
cost_layers = new_cost_layers
|
||||||
|
|
||||||
@ -86,15 +87,12 @@ def postTransaction(site_name, user_id, data: dict, conn=None):
|
|||||||
|
|
||||||
updated_item_location_payload = (cost_layers, quantity_on_hand, data['item_id'], data['location_id'])
|
updated_item_location_payload = (cost_layers, quantity_on_hand, data['item_id'], data['location_id'])
|
||||||
poe_database.updateItemLocation(site_name, updated_item_location_payload, conn=conn)
|
poe_database.updateItemLocation(site_name, updated_item_location_payload, conn=conn)
|
||||||
#database.updateItemLocation(conn, site_name, updated_item_location_payload)
|
|
||||||
|
|
||||||
site_location = poe_database.selectLocationsTuple(site_name, (location['location_id'], ), conn=conn)
|
site_location = poe_database.selectLocationsTuple(site_name, (location['location_id'], ), conn=conn)
|
||||||
#site_location = database.__selectTuple(conn, site_name, f"{site_name}_locations", (location['location_id'], ), convert=True)
|
|
||||||
|
|
||||||
transaction.data = {'location': site_location['uuid']}
|
transaction.data = {'location': site_location['uuid']}
|
||||||
|
|
||||||
poe_database.insertTransactionsTuple(site_name, transaction.payload(), conn=conn)
|
poe_database.insertTransactionsTuple(site_name, transaction.payload(), conn=conn)
|
||||||
#database.insertTransactionsTuple(conn, site_name, transaction.payload())
|
|
||||||
|
|
||||||
if self_conn:
|
if self_conn:
|
||||||
conn.commit()
|
conn.commit()
|
||||||
@ -103,6 +101,8 @@ def postTransaction(site_name, user_id, data: dict, conn=None):
|
|||||||
return {"error": False, "message":f"Transaction Successful!"}
|
return {"error": False, "message":f"Transaction Successful!"}
|
||||||
|
|
||||||
def post_receipt(site_name, user_id, data: dict, conn=None):
|
def post_receipt(site_name, user_id, data: dict, conn=None):
|
||||||
|
'''Takes a list of items and opens and creates a SIR (SCANNED IN RECEIPT) into the system with the items linked
|
||||||
|
to said receipt.'''
|
||||||
# data = {'items': items}
|
# data = {'items': items}
|
||||||
self_conn = False
|
self_conn = False
|
||||||
items = data['items']
|
items = data['items']
|
||||||
@ -118,10 +118,9 @@ def post_receipt(site_name, user_id, data: dict, conn=None):
|
|||||||
receipt_id=receipt_id,
|
receipt_id=receipt_id,
|
||||||
submitted_by=user_id
|
submitted_by=user_id
|
||||||
)
|
)
|
||||||
#receipt = database.insertReceiptsTuple(conn, site_name, receipt.payload(), convert=True)
|
|
||||||
receipt = poe_database.insertReceiptsTuple(site_name, receipt.payload(), conn=conn)
|
receipt = poe_database.insertReceiptsTuple(site_name, receipt.payload(), conn=conn)
|
||||||
for item in items:
|
|
||||||
|
|
||||||
|
for item in items:
|
||||||
receipt_item = database_payloads.ReceiptItemPayload(
|
receipt_item = database_payloads.ReceiptItemPayload(
|
||||||
type=item['type'],
|
type=item['type'],
|
||||||
receipt_id=receipt['id'],
|
receipt_id=receipt['id'],
|
||||||
@ -131,10 +130,7 @@ def post_receipt(site_name, user_id, data: dict, conn=None):
|
|||||||
uom=item['item']['uom'],
|
uom=item['item']['uom'],
|
||||||
data=item['item']['data']
|
data=item['item']['data']
|
||||||
)
|
)
|
||||||
#database.insertReceiptItemsTuple(conn, site_name, receipt_item.payload())
|
|
||||||
poe_database.insertReceiptItemsTuple(site_name, receipt_item.payload(), conn=conn)
|
poe_database.insertReceiptItemsTuple(site_name, receipt_item.payload(), conn=conn)
|
||||||
#webpush.push_notifications('New Receipt', f"Receipt {receipt['receipt_id']} was added to Site -> {site_name}!")
|
|
||||||
#webpush.push_ntfy('New Receipt', f"Receipt {receipt['receipt_id']} was added to Site -> {site_name}!")
|
|
||||||
|
|
||||||
if self_conn:
|
if self_conn:
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|||||||
75
application/poe/sql/getItemAllByBarcode.sql
Normal file
75
application/poe/sql/getItemAllByBarcode.sql
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
WITH passed_id AS (SELECT id AS passed_id FROM %%site_name%%_items WHERE barcode=%s),
|
||||||
|
logistics_id AS (SELECT logistics_info_id FROM %%site_name%%_items WHERE id=(SELECT passed_id FROM passed_id)),
|
||||||
|
info_id AS (SELECT item_info_id FROM %%site_name%%_items WHERE id=(SELECT passed_id FROM passed_id)),
|
||||||
|
cte_item_info AS (
|
||||||
|
SELECT
|
||||||
|
%%site_name%%_item_info.*,
|
||||||
|
row_to_json(units.*) as uom
|
||||||
|
FROM %%site_name%%_item_info
|
||||||
|
LEFT JOIN units ON %%site_name%%_item_info.uom = units.id
|
||||||
|
WHERE %%site_name%%_item_info.id = (SELECT item_info_id FROM info_id)
|
||||||
|
),
|
||||||
|
cte_groups AS (
|
||||||
|
SELECT
|
||||||
|
%%site_name%%_groups.*,
|
||||||
|
%%site_name%%_group_items.uuid,
|
||||||
|
%%site_name%%_group_items.item_type,
|
||||||
|
%%site_name%%_group_items.qty
|
||||||
|
FROM %%site_name%%_groups
|
||||||
|
JOIN %%site_name%%_group_items ON %%site_name%%_groups.id = %%site_name%%_group_items.gr_id
|
||||||
|
WHERE %%site_name%%_group_items.item_id = (SELECT passed_id FROM passed_id)
|
||||||
|
),
|
||||||
|
cte_shopping_lists AS (
|
||||||
|
SELECT
|
||||||
|
%%site_name%%_shopping_lists.*,
|
||||||
|
%%site_name%%_shopping_list_items.uuid,
|
||||||
|
%%site_name%%_shopping_list_items.item_type,
|
||||||
|
%%site_name%%_shopping_list_items.qty
|
||||||
|
FROM %%site_name%%_shopping_lists
|
||||||
|
JOIN %%site_name%%_shopping_list_items ON %%site_name%%_shopping_lists.id = %%site_name%%_shopping_list_items.sl_id
|
||||||
|
WHERE %%site_name%%_shopping_list_items.item_id = (SELECT passed_id FROM passed_id)
|
||||||
|
),
|
||||||
|
cte_itemlinks AS (
|
||||||
|
SELECT * FROM %%site_name%%_itemlinks WHERE link=(SELECT passed_id FROM passed_id)
|
||||||
|
),
|
||||||
|
cte_item_locations AS (
|
||||||
|
SELECT * FROM %%site_name%%_item_locations
|
||||||
|
LEFT JOIN %%site_name%%_locations ON %%site_name%%_locations.id = %%site_name%%_item_locations.location_id
|
||||||
|
WHERE part_id = (SELECT passed_id FROM passed_id)
|
||||||
|
),
|
||||||
|
cte_logistics_info AS (
|
||||||
|
SELECT
|
||||||
|
li.*,
|
||||||
|
row_to_json(pl) AS primary_location,
|
||||||
|
row_to_json(ail) AS auto_issue_location,
|
||||||
|
row_to_json(pz) AS primary_zone,
|
||||||
|
row_to_json(aiz) AS auto_issue_zone
|
||||||
|
FROM %%site_name%%_logistics_info AS li
|
||||||
|
LEFT JOIN %%site_name%%_locations AS pl ON li.primary_location = pl.id
|
||||||
|
LEFT JOIN %%site_name%%_locations AS ail ON li.auto_issue_location = ail.id
|
||||||
|
LEFT JOIN %%site_name%%_zones AS pz ON li.primary_zone = pz.id
|
||||||
|
LEFT JOIN %%site_name%%_zones AS aiz ON li.auto_issue_zone = aiz.id
|
||||||
|
WHERE li.id=(SELECT logistics_info_id FROM logistics_id)
|
||||||
|
)
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
(SELECT passed_id FROM passed_id) AS passed_id,
|
||||||
|
%%site_name%%_items.*,
|
||||||
|
(SELECT COALESCE(row_to_json(logis), '{}') FROM cte_logistics_info logis) AS logistics_info,
|
||||||
|
row_to_json(%%site_name%%_food_info.*) as food_info,
|
||||||
|
row_to_json(%%site_name%%_brands.*) as brand,
|
||||||
|
(SELECT COALESCE(row_to_json(ii), '{}') FROM cte_item_info ii) AS item_info,
|
||||||
|
(SELECT COALESCE(array_agg(row_to_json(g)), '{}') FROM cte_groups g) AS item_groups,
|
||||||
|
(SELECT COALESCE(array_agg(row_to_json(sl)), '{}') FROM cte_shopping_lists sl) AS item_shopping_lists,
|
||||||
|
(SELECT COALESCE(array_agg(row_to_json(il)), '{}') FROM cte_itemlinks il) AS linked_items,
|
||||||
|
(SELECT COALESCE(array_agg(row_to_json(ils)), '{}') FROM cte_item_locations ils) AS item_locations
|
||||||
|
FROM %%site_name%%_items
|
||||||
|
LEFT JOIN %%site_name%%_item_info ON %%site_name%%_items.item_info_id = %%site_name%%_item_info.id
|
||||||
|
LEFT JOIN %%site_name%%_food_info ON %%site_name%%_items.food_info_id = %%site_name%%_food_info.id
|
||||||
|
LEFT JOIN %%site_name%%_brands ON %%site_name%%_items.brand = %%site_name%%_brands.id
|
||||||
|
LEFT JOIN units ON %%site_name%%_item_info.uom = units.id
|
||||||
|
LEFT JOIN cte_groups ON %%site_name%%_items.id = cte_groups.id
|
||||||
|
LEFT JOIN cte_shopping_lists ON %%site_name%%_items.id = cte_shopping_lists.id
|
||||||
|
WHERE %%site_name%%_items.id=(SELECT passed_id FROM passed_id)
|
||||||
|
GROUP BY
|
||||||
|
%%site_name%%_items.id, %%site_name%%_item_info.id, %%site_name%%_food_info.id, %%site_name%%_brands.id;
|
||||||
86
application/poe/sql/getItemAllByID.sql
Normal file
86
application/poe/sql/getItemAllByID.sql
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
WITH passed_id AS (SELECT %s AS passed_id),
|
||||||
|
logistics_id AS (SELECT logistics_info_id FROM %%site_name%%_items WHERE id=(SELECT passed_id FROM passed_id)),
|
||||||
|
info_id AS (SELECT item_info_id FROM %%site_name%%_items WHERE id=(SELECT passed_id FROM passed_id)),
|
||||||
|
cte_conversions AS (
|
||||||
|
SELECT
|
||||||
|
%%site_name%%_conversions.id as conv_id,
|
||||||
|
%%site_name%%_conversions.conv_factor as conv_factor,
|
||||||
|
units.* as uom
|
||||||
|
FROM %%site_name%%_conversions
|
||||||
|
LEFT JOIN units ON %%site_name%%_conversions.uom_id = units.id
|
||||||
|
WHERE %%site_name%%_conversions.item_id = (SELECT passed_id FROM passed_id)
|
||||||
|
),
|
||||||
|
cte_item_info AS (
|
||||||
|
SELECT
|
||||||
|
%%site_name%%_item_info.*,
|
||||||
|
row_to_json(units.*) as uom,
|
||||||
|
COALESCE((SELECT json_agg(convs) FROM cte_conversions convs), '[]'::json) AS conversions,
|
||||||
|
COALESCE((SELECT json_agg(p.*) FROM %%site_name%%_sku_prefix as p WHERE p.id = ANY(%%site_name%%_item_info.prefixes)), '[]'::json) as prefixes
|
||||||
|
FROM %%site_name%%_item_info
|
||||||
|
LEFT JOIN units ON %%site_name%%_item_info.uom = units.id
|
||||||
|
WHERE %%site_name%%_item_info.id = (SELECT item_info_id FROM info_id)
|
||||||
|
),
|
||||||
|
cte_groups AS (
|
||||||
|
SELECT
|
||||||
|
%%site_name%%_groups.*,
|
||||||
|
%%site_name%%_group_items.uuid,
|
||||||
|
%%site_name%%_group_items.item_type,
|
||||||
|
%%site_name%%_group_items.qty
|
||||||
|
FROM %%site_name%%_groups
|
||||||
|
JOIN %%site_name%%_group_items ON %%site_name%%_groups.id = %%site_name%%_group_items.gr_id
|
||||||
|
WHERE %%site_name%%_group_items.item_id = (SELECT passed_id FROM passed_id)
|
||||||
|
),
|
||||||
|
cte_shopping_lists AS (
|
||||||
|
SELECT
|
||||||
|
%%site_name%%_shopping_lists.*,
|
||||||
|
%%site_name%%_shopping_list_items.uuid,
|
||||||
|
%%site_name%%_shopping_list_items.item_type,
|
||||||
|
%%site_name%%_shopping_list_items.qty
|
||||||
|
FROM %%site_name%%_shopping_lists
|
||||||
|
JOIN %%site_name%%_shopping_list_items ON %%site_name%%_shopping_lists.id = %%site_name%%_shopping_list_items.sl_id
|
||||||
|
WHERE %%site_name%%_shopping_list_items.item_id = (SELECT passed_id FROM passed_id)
|
||||||
|
),
|
||||||
|
cte_itemlinks AS (
|
||||||
|
SELECT * FROM %%site_name%%_itemlinks WHERE link=(SELECT passed_id FROM passed_id)
|
||||||
|
),
|
||||||
|
cte_item_locations AS (
|
||||||
|
SELECT * FROM %%site_name%%_item_locations
|
||||||
|
LEFT JOIN %%site_name%%_locations ON %%site_name%%_locations.id = %%site_name%%_item_locations.location_id
|
||||||
|
WHERE part_id = (SELECT passed_id FROM passed_id)
|
||||||
|
),
|
||||||
|
cte_logistics_info AS (
|
||||||
|
SELECT
|
||||||
|
li.*,
|
||||||
|
row_to_json(pl) AS primary_location,
|
||||||
|
row_to_json(ail) AS auto_issue_location,
|
||||||
|
row_to_json(pz) AS primary_zone,
|
||||||
|
row_to_json(aiz) AS auto_issue_zone
|
||||||
|
FROM %%site_name%%_logistics_info AS li
|
||||||
|
LEFT JOIN %%site_name%%_locations AS pl ON li.primary_location = pl.id
|
||||||
|
LEFT JOIN %%site_name%%_locations AS ail ON li.auto_issue_location = ail.id
|
||||||
|
LEFT JOIN %%site_name%%_zones AS pz ON li.primary_zone = pz.id
|
||||||
|
LEFT JOIN %%site_name%%_zones AS aiz ON li.auto_issue_zone = aiz.id
|
||||||
|
WHERE li.id=(SELECT logistics_info_id FROM logistics_id)
|
||||||
|
)
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
(SELECT passed_id FROM passed_id) AS passed_id,
|
||||||
|
%%site_name%%_items.*,
|
||||||
|
(SELECT COALESCE(row_to_json(logis), '{}') FROM cte_logistics_info logis) AS logistics_info,
|
||||||
|
row_to_json(%%site_name%%_food_info.*) as food_info,
|
||||||
|
row_to_json(%%site_name%%_brands.*) as brand,
|
||||||
|
(SELECT COALESCE(row_to_json(ii), '{}') FROM cte_item_info ii) AS item_info,
|
||||||
|
(SELECT COALESCE(array_agg(row_to_json(g)), '{}') FROM cte_groups g) AS item_groups,
|
||||||
|
(SELECT COALESCE(array_agg(row_to_json(sl)), '{}') FROM cte_shopping_lists sl) AS item_shopping_lists,
|
||||||
|
(SELECT COALESCE(array_agg(row_to_json(il)), '{}') FROM cte_itemlinks il) AS linked_items,
|
||||||
|
(SELECT COALESCE(array_agg(row_to_json(ils)), '{}') FROM cte_item_locations ils) AS item_locations
|
||||||
|
FROM %%site_name%%_items
|
||||||
|
LEFT JOIN %%site_name%%_item_info ON %%site_name%%_items.item_info_id = %%site_name%%_item_info.id
|
||||||
|
LEFT JOIN %%site_name%%_food_info ON %%site_name%%_items.food_info_id = %%site_name%%_food_info.id
|
||||||
|
LEFT JOIN %%site_name%%_brands ON %%site_name%%_items.brand = %%site_name%%_brands.id
|
||||||
|
LEFT JOIN units ON %%site_name%%_item_info.uom = units.id
|
||||||
|
LEFT JOIN cte_groups ON %%site_name%%_items.id = cte_groups.id
|
||||||
|
LEFT JOIN cte_shopping_lists ON %%site_name%%_items.id = cte_shopping_lists.id
|
||||||
|
WHERE %%site_name%%_items.id=(SELECT passed_id FROM passed_id)
|
||||||
|
GROUP BY
|
||||||
|
%%site_name%%_items.id, %%site_name%%_item_info.id, %%site_name%%_food_info.id, %%site_name%%_brands.id;
|
||||||
@ -86,9 +86,8 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li style="cursor: default; user-select: none;"><span>Logistics</span></li>
|
<li class="uk-disabled"><span>Point of Ease</span></li>
|
||||||
<li><a href="/items">Items</a></li>
|
<li class="uk-disabled"><span>Scan to Receipt</span></li>
|
||||||
<li class="uk-disabled"><span>Add Transaction</span></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="uk-navbar-right">
|
<div class="uk-navbar-right">
|
||||||
|
|||||||
@ -73,7 +73,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="uk-navbar-center uk-margin-small uk-visible@s">
|
<div class="uk-navbar-center uk-margin-small uk-visible@s">
|
||||||
<ul class="uk-breadcrumb">
|
<ul class="uk-breadcrumb">
|
||||||
<li style="cursor: default;"><span><strong>{{current_site}}</strong></span>
|
<li style="cursor: pointer;"><span><strong>{{current_site}}</strong></span>
|
||||||
<div uk-dropdown="mode: hover">
|
<div uk-dropdown="mode: hover">
|
||||||
<ul class="uk-nav uk-dropdown-nav">
|
<ul class="uk-nav uk-dropdown-nav">
|
||||||
{% for site in sites %}
|
{% for site in sites %}
|
||||||
@ -86,9 +86,8 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li style="cursor: default; user-select: none;"><span>Logistics</span></li>
|
<li class="uk-disabled"><span>Point of Ease</span></li>
|
||||||
<li><a href="/items">Items</a></li>
|
<li class="uk-disabled"><span>Scan To Transaction</span></li>
|
||||||
<li class="uk-disabled"><span>Add Transaction</span></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="uk-navbar-right">
|
<div class="uk-navbar-right">
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import psycopg2.extras
|
|||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
import config
|
||||||
|
|
||||||
class DatabaseError(Exception):
|
class DatabaseError(Exception):
|
||||||
def __init__(self, message, payload=[], sql=""):
|
def __init__(self, message, payload=[], sql=""):
|
||||||
@ -44,6 +45,22 @@ def getUUID(n):
|
|||||||
random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=n))
|
random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=n))
|
||||||
return random_string
|
return random_string
|
||||||
|
|
||||||
|
def get_sites(sites=[]):
|
||||||
|
database_config = config.config()
|
||||||
|
with psycopg2.connect(**database_config) as conn:
|
||||||
|
try:
|
||||||
|
with conn.cursor() as cur:
|
||||||
|
site_rows = []
|
||||||
|
for each in sites:
|
||||||
|
cur.execute(f"SELECT * FROM sites WHERE id=%s;", (each, ))
|
||||||
|
site_rows.append(cur.fetchone())
|
||||||
|
return site_rows
|
||||||
|
except (Exception, psycopg2.DatabaseError) as error:
|
||||||
|
print(error)
|
||||||
|
conn.rollback()
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class ConversionsTable:
|
class ConversionsTable:
|
||||||
@dataclass
|
@dataclass
|
||||||
class Payload:
|
class Payload:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user