Implemented Custom Lines in Receipts Module

This commit is contained in:
Jadowyne Ulve 2025-08-09 16:01:54 -05:00
parent bc23730394
commit 056d50fff2
5 changed files with 119 additions and 8 deletions

View File

@ -126,7 +126,6 @@ def addSKULine():
site_name = session['selected_site'] site_name = session['selected_site']
item = receipts_database.getItemAllByID(site_name, (item_id, )) item = receipts_database.getItemAllByID(site_name, (item_id, ))
#pprint.pprint(item)
data = { data = {
'cost': item['item_info']['cost'], 'cost': item['item_info']['cost'],
'expires': item['food_info']['expires'] 'expires': item['food_info']['expires']
@ -145,6 +144,33 @@ def addSKULine():
return jsonify({'error': False, "message": "Line added Succesfully"}) return jsonify({'error': False, "message": "Line added Succesfully"})
return jsonify({'error': True, "message": "Something went wrong while add SKU line!"}) return jsonify({'error': True, "message": "Something went wrong while add SKU line!"})
@receipt_api.route('/api/addCustomLine', methods=["POST"])
@access_api.login_required
def addCustomLine():
if request.method == "POST":
receipt_id = int(request.get_json()['receipt_id'])
site_name = session['selected_site']
print(receipt_id)
data = {
'cost': request.get_json()['line_cost'],
'expires': False
}
receipt_item = database_payloads.ReceiptItemPayload(
type="custom",
receipt_id=receipt_id,
barcode=None,
item_uuid=None,
name=request.get_json()['line_name'],
qty=request.get_json()['line_qty'],
uom=request.get_json()['line_UOM'],
data=data
)
receipts_database.insertReceiptItemsTuple(site_name, receipt_item.payload())
return jsonify({'error': False, "message": "Line added Succesfully"})
return jsonify({'error': True, "message": "Something went wrong while add SKU line!"})
@receipt_api.route('/api/deleteLine', methods=["POST"]) @receipt_api.route('/api/deleteLine', methods=["POST"])
@access_api.login_required @access_api.login_required
def deleteLine(): def deleteLine():

View File

@ -195,11 +195,6 @@ async function viewFile(source) {
} }
async function openCustomModal() {
console.log("custom")
}
async function openLineEditModal(line_data) { async function openLineEditModal(line_data) {
console.log(line_data) console.log(line_data)
document.getElementById('lineName').value = line_data.name document.getElementById('lineName').value = line_data.name
@ -287,6 +282,7 @@ async function uploadFile() {
.then(response => response.json()) .then(response => response.json())
.then(data => console.log('File uploaded!', data)) .then(data => console.log('File uploaded!', data))
.catch(error => console.error('Error:', error)); .catch(error => console.error('Error:', error));
await refreshReceipt()
} }
async function saveLine(line_id){ async function saveLine(line_id){
@ -364,6 +360,46 @@ async function getReceipt(id) {
return receipt; return receipt;
} }
// Custom Line Modal Functions
async function openAddCustomLineModal() {
console.log("custom")
document.getElementById('CustomlineName').value = ""
document.getElementById('CustomlineQty').value = 0
document.getElementById('CustomlineUOM').value = 1
document.getElementById('CustomlineCost').value = 0.00
document.getElementById('saveCustomLineButton').innerHTML = "Add"
document.getElementById('saveCustomLineButton').onclick = async function() {
await addCustomLine()
}
UIkit.modal(document.getElementById("CustomLineModal")).show();
}
async function addCustomLine(){
let LineName = document.getElementById('CustomlineName').value
let LineQty = document.getElementById('CustomlineQty').value
let LineUOM = document.getElementById('CustomlineUOM').value
let LineCost = document.getElementById('CustomlineCost').value
console.log(LineName)
UIkit.modal(document.getElementById("CustomLineModal")).hide();
const response = await fetch(`/receipts/api/addCustomLine`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
line_name: LineName,
line_qty: LineQty,
line_UOM: LineUOM,
line_cost: LineCost,
receipt_id: receipt_id
}),
});
await refreshReceipt()
}
// SKU Modal functions // SKU Modal functions
let items_limit = 50; let items_limit = 50;
var ItemsModal_search_string = "" var ItemsModal_search_string = ""

View File

@ -184,7 +184,7 @@
<button id="lineAddButton" class="uk-button uk-button-default" type="button">Add Line <span uk-icon="icon: triangle-down"></span></button> <button id="lineAddButton" class="uk-button uk-button-default" type="button">Add Line <span uk-icon="icon: triangle-down"></span></button>
<div id="addLineDropDown" uk-dropdown="mode: click"> <div id="addLineDropDown" uk-dropdown="mode: click">
<ul class="uk-nav uk-dropdown-nav"> <ul class="uk-nav uk-dropdown-nav">
<li><a onclick="openCustomModal()">Custom</a></li> <li><a onclick="openAddCustomLineModal()">Custom</a></li>
<li><a onclick="openSKUModal()">SKU</a></li> <li><a onclick="openSKUModal()">SKU</a></li>
</ul> </ul>
</div> </div>
@ -336,6 +336,52 @@
</table> </table>
</div> </div>
</div> </div>
<!-- Custom Line Modal-->
<div id="CustomLineModal" class="uk-modal-container" uk-modal>
<div class="uk-modal-dialog uk-modal-body">
<h2 class="uk-modal-title">Add a Custom Line...</h2>
<p class="uk-text-meta">Custom lines are items where you would like to solely track them through receipts and nothing more. That means
that beyond saving the line on the receipt, nothing else will be saved, transacted, or handled by the over
all system. Keep that in mind as you choose to add a custom line.</p>
<p class="uk-text-meta">Edit any fields here for the Custom Line and all the data will be saved.</p>
<table class="uk-table uk-table-responsive uk-table-striped">
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Name</td>
<td><input id="CustomlineName" class="uk-input" type="text"></td>
</tr>
<tr>
<td>QTY</td>
<td><input id="CustomlineQty" class="uk-input" type="number"></td>
</tr>
<tr>
<td>UOM</td>
<td>
<select id="CustomlineUOM" class="uk-select" aria-label="Select">
{% for unit in units %}
<option value="{{unit['id']}}">{{unit['fullname']}}</option>
{% endfor %}
</select>
</td>
</tr>
<tr>
<td>COST</td>
<td><input id="CustomlineCost" class="uk-input" type="text"></td>
</tr>
</tbody>
</table>
<p class="uk-text-right">
<button class="uk-button uk-button-default uk-modal-close" type="button">Cancel</button>
<button id="saveCustomLineButton" class="uk-button uk-button-primary" type="button">Save</button>
</p>
</div>
</div>
<!-- Line Edit Modal--> <!-- Line Edit Modal-->
<div id="lineEditModal" class="uk-modal-container" uk-modal> <div id="lineEditModal" class="uk-modal-container" uk-modal>
<div class="uk-modal-dialog uk-modal-body"> <div class="uk-modal-dialog uk-modal-body">

View File

@ -58,4 +58,7 @@
sql='INSERT INTO test_receipt_items(type, receipt_id, barcode, name, qty, uom, data, status) VALUES (%s, %s, %s, %s, %s, %s, %s, %s) RETURNING *;') sql='INSERT INTO test_receipt_items(type, receipt_id, barcode, name, qty, uom, data, status) VALUES (%s, %s, %s, %s, %s, %s, %s, %s) RETURNING *;')
2025-08-09 14:53:40.869005 --- ERROR --- DatabaseError(message='not all arguments converted during string formatting', 2025-08-09 14:53:40.869005 --- ERROR --- DatabaseError(message='not all arguments converted during string formatting',
payload=('sku', 36, '%078742015101%', '3405b49b-843a-4bca-a235-686e4a9f2e73', '100% grated parmesan cheese', 1, 1, '{"cost": 0, "expires": false}', 'Unresolved'), payload=('sku', 36, '%078742015101%', '3405b49b-843a-4bca-a235-686e4a9f2e73', '100% grated parmesan cheese', 1, 1, '{"cost": 0, "expires": false}', 'Unresolved'),
sql='INSERT INTO test_receipt_items(type, receipt_id, barcode, name, qty, uom, data, status) VALUES (%s, %s, %s, %s, %s, %s, %s, %s) RETURNING *;') sql='INSERT INTO test_receipt_items(type, receipt_id, barcode, name, qty, uom, data, status) VALUES (%s, %s, %s, %s, %s, %s, %s, %s) RETURNING *;')
2025-08-09 15:57:58.332708 --- ERROR --- DatabaseError(message='invalid input syntax for type uuid: ""LINE 3: VALUES ('custom', 36, '', '', 'test1', '1', '2', '{"cost": "... ^',
payload=('custom', 36, '', '', 'test1', '1', '2', '{"cost": "0.99", "expires": false}', 'Unresolved'),
sql='INSERT INTO test_receipt_items(type, receipt_id, barcode, item_uuid, name, qty, uom, data, status) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING *;')