Implemented conv_factors into recipe receipts
This commit is contained in:
parent
1212473c48
commit
94f7bad2e6
Binary file not shown.
Binary file not shown.
@ -226,6 +226,34 @@ def selectItemTupleByUUID(site, payload, convert=True, conn=None):
|
|||||||
except Exception as error:
|
except Exception as error:
|
||||||
raise postsqldb.DatabaseError(error, payload, sql)
|
raise postsqldb.DatabaseError(error, payload, sql)
|
||||||
|
|
||||||
|
def selectConversionTuple(site, payload, convert=True, conn=None):
|
||||||
|
"""payload=(item_id, uom_id)"""
|
||||||
|
selected = ()
|
||||||
|
self_conn = False
|
||||||
|
sql = f"SELECT conversions.conv_factor FROM {site}_conversions conversions WHERE item_id = %s AND uom_id = %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:
|
||||||
|
selected = postsqldb.tupleDictionaryFactory(cur.description, rows)
|
||||||
|
elif rows and not convert:
|
||||||
|
selected = rows
|
||||||
|
|
||||||
|
if self_conn:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
return selected
|
||||||
|
except Exception as error:
|
||||||
|
raise postsqldb.DatabaseError(error, payload, sql)
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
@ -46,9 +46,9 @@ def postTransaction(site_name, user_id, data: dict, conn=None):
|
|||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
location = database_recipes.selectItemLocationsTuple(site_name, (data['item_id'], data['location_id']), conn=conn)
|
location = database_recipes.selectItemLocationsTuple(site_name, (data['item_id'], data['location_id']), conn=conn)
|
||||||
site_location = database_recipes.selectLocationsTuple(site_name, (location['location_id'], ), conn=conn)
|
site_location = database_recipes.selectLocationsTuple(site_name, (location['location_id'], ), conn=conn)
|
||||||
print(location)
|
|
||||||
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 = database_recipes.insertCostLayersTuple(site_name, cost_layer.payload(), conn=conn)
|
cost_layer = database_recipes.insertCostLayersTuple(site_name, cost_layer.payload(), conn=conn)
|
||||||
@ -58,7 +58,6 @@ def postTransaction(site_name, user_id, data: dict, conn=None):
|
|||||||
if float(location['quantity_on_hand']) < float(data['quantity']):
|
if float(location['quantity_on_hand']) < float(data['quantity']):
|
||||||
raise Exception(f"The quantity on hand for {data['item_name']} in {site_location['uuid']} is not enough to satisfy your transaction!")
|
raise Exception(f"The quantity on hand for {data['item_name']} in {site_location['uuid']} is not enough to satisfy your transaction!")
|
||||||
cost_layers = database_recipes.selectCostLayersTuple(site_name, payload=(location['id'], ))
|
cost_layers = database_recipes.selectCostLayersTuple(site_name, payload=(location['id'], ))
|
||||||
|
|
||||||
new_cost_layers = []
|
new_cost_layers = []
|
||||||
qty = float(data['quantity'])
|
qty = float(data['quantity'])
|
||||||
for layer in cost_layers:
|
for layer in cost_layers:
|
||||||
@ -82,19 +81,17 @@ 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'])
|
||||||
database_recipes.updateItemLocation(site_name, updated_item_location_payload, conn=conn)
|
database_recipes.updateItemLocation(site_name, updated_item_location_payload, conn=conn)
|
||||||
|
|
||||||
#site_location = database_recipes.selectLocationsTuple(site_name, (location['location_id'], ), conn=conn)
|
#site_location = database_recipes.selectLocationsTuple(site_name, (location['location_id'], ), conn=conn)
|
||||||
|
|
||||||
transaction.data = {'location': site_location['uuid']}
|
transaction.data = {'location': site_location['uuid']}
|
||||||
|
|
||||||
database_recipes.insertTransactionsTuple(site_name, transaction.payload(), conn=conn)
|
transaction_tuple = database_recipes.insertTransactionsTuple(site_name, transaction.payload(), conn=conn)
|
||||||
|
|
||||||
if self_conn:
|
if self_conn:
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
return {"error": False, "message":f"Transaction Successful!"}
|
return conn
|
||||||
|
|
||||||
def process_recipe_receipt(site_name, user_id, data:dict, conn=None):
|
def process_recipe_receipt(site_name, user_id, data:dict, conn=None):
|
||||||
"""data={'recipe_id': recipe_id}"""
|
"""data={'recipe_id': recipe_id}"""
|
||||||
@ -110,29 +107,28 @@ def process_recipe_receipt(site_name, user_id, data:dict, conn=None):
|
|||||||
|
|
||||||
sku_items = [rp_item for rp_item in recipe['recipe_items'] if rp_item['item_type'] == "sku"]
|
sku_items = [rp_item for rp_item in recipe['recipe_items'] if rp_item['item_type'] == "sku"]
|
||||||
for item in sku_items:
|
for item in sku_items:
|
||||||
""" dict_keys(['item_id', 'logistics_info_id', 'barcode', 'item_name', 'transaction_type',
|
rp_item_uom = item['uom']['id']
|
||||||
'quantity', 'description', 'cost', 'vendor', 'expires', 'location_id'])"""
|
|
||||||
item_stuff = database_recipes.selectItemTupleByUUID(site_name, (item['item_uuid'],), conn=conn)
|
item_stuff = database_recipes.selectItemTupleByUUID(site_name, (item['item_uuid'],), conn=conn)
|
||||||
print(item_stuff)
|
conv_factor = database_recipes.selectConversionTuple(site_name, (item_stuff['item_id'], rp_item_uom))
|
||||||
|
qty = float(item['qty']) / float(conv_factor['conv_factor'])
|
||||||
payload = {
|
payload = {
|
||||||
'item_id': item_stuff['item_id'],
|
'item_id': item_stuff['item_id'],
|
||||||
'logistics_info_id': item_stuff['logistics_info_id'],
|
'logistics_info_id': item_stuff['logistics_info_id'],
|
||||||
'barcode': "",
|
'barcode': "",
|
||||||
'item_name': item_stuff['item_name'],
|
'item_name': item_stuff['item_name'],
|
||||||
'transaction_type': "Adjust Out",
|
'transaction_type': "Adjust Out",
|
||||||
'quantity': item['qty'],
|
'quantity': qty,
|
||||||
'description': f"Recipe Receipt - {data['recipe_id']}",
|
'description': f"Recipe Receipt - {data['recipe_id']}",
|
||||||
'cost': 0.00,
|
'cost': 0.00,
|
||||||
'vendor': 0,
|
'vendor': 0,
|
||||||
'expires': False,
|
'expires': False,
|
||||||
'location_id': item_stuff['auto_issue_location']
|
'location_id': item_stuff['auto_issue_location']
|
||||||
}
|
}
|
||||||
print(payload)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
postTransaction(site_name, user_id, payload, conn=conn)
|
postTransaction(site_name, user_id, payload, conn=conn)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
conn.rollback()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
return False, str(error)
|
return False, str(error)
|
||||||
|
|
||||||
|
|||||||
@ -115,7 +115,7 @@ async function openLineItemModal(item){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function deleteLineItem(index){
|
async function deleteLineItem(index){
|
||||||
const response = await fetch(`/recipe/deleteRecipeItem`, {
|
const response = await fetch(`/recipes/deleteRecipeItem`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
@ -45,7 +45,7 @@ async function replenishIngrediantsTable() {
|
|||||||
} else if (qty_needed > quantity_on_hand && item_type === "sku") {
|
} else if (qty_needed > quantity_on_hand && item_type === "sku") {
|
||||||
markerCell.innerHTML = `<span class="uk-label uk-label-danger">Missing</span>`
|
markerCell.innerHTML = `<span class="uk-label uk-label-danger">Missing</span>`
|
||||||
} else {
|
} else {
|
||||||
markerCell.innerHTML = ""
|
markerCell.innerHTML = `<span class="uk-label uk-label-default">Untracked</span>`
|
||||||
}
|
}
|
||||||
|
|
||||||
let nameCell = document.createElement('td')
|
let nameCell = document.createElement('td')
|
||||||
@ -140,4 +140,6 @@ async function receiptRecipe(){
|
|||||||
pos: 'top-right',
|
pos: 'top-right',
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
});
|
});
|
||||||
|
UIkit.modal(document.getElementById('receiptRecipeModal')).hide();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -140,3 +140,9 @@
|
|||||||
2025-08-10 09:26:25.470903 --- ERROR --- DatabaseError(message='syntax error at or near "{"LINE 1: SELECT items.*, lginf.* AS logistics_info FROM {site}_items ... ^',
|
2025-08-10 09:26:25.470903 --- ERROR --- DatabaseError(message='syntax error at or near "{"LINE 1: SELECT items.*, lginf.* AS logistics_info FROM {site}_items ... ^',
|
||||||
payload=('44c41878-e645-4e16-a402-e480936ac4aa',),
|
payload=('44c41878-e645-4e16-a402-e480936ac4aa',),
|
||||||
sql='SELECT items.*, lginf.* AS logistics_info FROM {site}_items items LEFT JOIN {site}_logistics_info lginf ON lginf.id = items.logistics_info_id WHERE item_uuid=%s;')
|
sql='SELECT items.*, lginf.* AS logistics_info FROM {site}_items items LEFT JOIN {site}_logistics_info lginf ON lginf.id = items.logistics_info_id WHERE item_uuid=%s;')
|
||||||
|
2025-08-10 10:17:09.169270 --- ERROR --- DatabaseError(message='syntax error at or near ","LINE 1: ... test_conversions conversions WHERE part_id = 2016, uom_id =... ^',
|
||||||
|
payload=(2016, 6),
|
||||||
|
sql='SELECT conversions.conv_factor FROM test_conversions conversions WHERE part_id = %s, uom_id = %s;')
|
||||||
|
2025-08-10 10:18:03.658146 --- ERROR --- DatabaseError(message='column "part_id" does not existLINE 1: ...nv_factor FROM test_conversions conversions WHERE part_id = ... ^',
|
||||||
|
payload=(2016, 6),
|
||||||
|
sql='SELECT conversions.conv_factor FROM test_conversions conversions WHERE part_id = %s AND uom_id = %s;')
|
||||||
Loading…
x
Reference in New Issue
Block a user