Add inventory correction stuff
This commit is contained in:
parent
bbd51978cb
commit
58ed948975
3
py/jon/db/create_correction.sql
Normal file
3
py/jon/db/create_correction.sql
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
INSERT INTO garfield.inventory_correction (item_id, delta, correction_comment)
|
||||||
|
VALUES (%(item_id)s, %(correction_delta)s, %(correction_comment)s)
|
||||||
|
|
9
py/jon/db/deactivate_item.sql
Normal file
9
py/jon/db/deactivate_item.sql
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
UPDATE garfield.inventory_items
|
||||||
|
SET available = FALSE
|
||||||
|
WHERE item_id = %(item_id)s;
|
||||||
|
|
||||||
|
-- Call garfield.snack_delete for every snack entry associated with this item.
|
||||||
|
SELECT snack_id
|
||||||
|
FROM garfield.inventory_map,
|
||||||
|
LATERAL garfield.snack_delete(snack_id::integer)
|
||||||
|
WHERE inventory_id = %(item_id)s
|
@ -1,4 +1,4 @@
|
|||||||
from flask import Blueprint, render_template, session
|
from flask import Blueprint, redirect, render_template, request, session
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ def index():
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@bp.get("/<item_id>")
|
@bp.get("/item/<item_id>")
|
||||||
def read_item(item_id: int):
|
def read_item(item_id: int):
|
||||||
item = db.run_query("get_item_by_id.sql", {
|
item = db.run_query("get_item_by_id.sql", {
|
||||||
"item_id": item_id
|
"item_id": item_id
|
||||||
@ -38,3 +38,45 @@ def read_item(item_id: int):
|
|||||||
"snacks": snacks,
|
"snacks": snacks,
|
||||||
"same_barcode_items": same_barcode_items
|
"same_barcode_items": same_barcode_items
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@bp.post("/item/<item_id>/deactivate")
|
||||||
|
def deactivate_item(item_id: int):
|
||||||
|
item = db.run_query("get_item_by_id.sql", {
|
||||||
|
"item_id": item_id
|
||||||
|
}).fetchone()
|
||||||
|
|
||||||
|
if item["units_left"] != 0:
|
||||||
|
return "Only items without stock can be deactivated", 400
|
||||||
|
|
||||||
|
db.run_query("deactivate_item.sql", {
|
||||||
|
"item_id": item_id
|
||||||
|
})
|
||||||
|
db.get_db().commit()
|
||||||
|
|
||||||
|
return redirect(request.referrer)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.post("/correction")
|
||||||
|
def create_correction():
|
||||||
|
try:
|
||||||
|
item_id = int(request.form.get("item_id"))
|
||||||
|
correction_delta = int(request.form.get("correction_delta"))
|
||||||
|
correction_comment = request.form.get("correction_comment")
|
||||||
|
except:
|
||||||
|
return "Incomplete or mistyped form", 400
|
||||||
|
|
||||||
|
if correction_delta == 0:
|
||||||
|
return "Correction delta may not be 0", 400
|
||||||
|
|
||||||
|
if correction_comment == "":
|
||||||
|
return "Correction comment may not be empty", 400
|
||||||
|
|
||||||
|
db.run_query("create_correction.sql", {
|
||||||
|
"item_id": item_id,
|
||||||
|
"correction_delta": correction_delta,
|
||||||
|
"correction_comment": correction_comment
|
||||||
|
})
|
||||||
|
db.get_db().commit()
|
||||||
|
|
||||||
|
return redirect(request.referrer)
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% for item in items %}
|
{% for item in items %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="/inventory/{{ item.item_id }}">{{ item.item_id }}</a></td>
|
<td><a href="/inventory/item/{{ item.item_id }}">{{ item.item_id }}</a></td>
|
||||||
<td><code>{{ item.item_barcode }}</code></td>
|
<td><code>{{ item.item_barcode }}</code></td>
|
||||||
<td>{{ item.name }}</td>
|
<td>{{ item.name }}</td>
|
||||||
<td class="--align-right">{{ format_currency(item.unit_price) }}</td>
|
<td class="--align-right">{{ format_currency(item.unit_price) }}</td>
|
||||||
|
@ -53,6 +53,28 @@
|
|||||||
</table>
|
</table>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<legend>Aktionen</legend>
|
||||||
|
|
||||||
|
<form method="POST" action="/inventory/correction">
|
||||||
|
<input name="item_id" type="hidden" value="{{ item.item_id }}">
|
||||||
|
<input name="correction_comment" type="hidden" value="Verlust">
|
||||||
|
<input name="correction_delta" type="hidden" value="{{ -item.units_left }}">
|
||||||
|
<button{% if item.units_left == 0 %} disabled{% endif %}>Inventar zu 0 korrigieren</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form method="POST" action="/inventory/correction">
|
||||||
|
<input name="item_id" type="hidden" value="{{ item.item_id }}">
|
||||||
|
<input name="correction_comment" type="text" value="" placeholder="Kommentar">
|
||||||
|
<input name="correction_delta" type="number" value="" placeholder="Delta">
|
||||||
|
<button>Inventar korrigieren</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form method="POST" action="/inventory/item/{{ item.item_id }}/deactivate">
|
||||||
|
<button{% if item.units_left != 0 %} disabled{% endif %}>Inventar- und Snackeintrag deaktivieren</button>
|
||||||
|
</form>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Snackeinträge für {{ item.item_id }}</legend>
|
<legend>Snackeinträge für {{ item.item_id }}</legend>
|
||||||
|
|
||||||
@ -101,7 +123,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% for item in same_barcode_items %}
|
{% for item in same_barcode_items %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="/inventory/{{ item.item_id }}">{{ item.item_id }}</a></td>
|
<td><a href="/inventory/item/{{ item.item_id }}">{{ item.item_id }}</a></td>
|
||||||
<td><code>{{ item.item_barcode }}</code></td>
|
<td><code>{{ item.item_barcode }}</code></td>
|
||||||
<td>{{ item.name }}</td>
|
<td>{{ item.name }}</td>
|
||||||
<td class="--align-right">{{ format_currency(item.unit_price) }}</td>
|
<td class="--align-right">{{ format_currency(item.unit_price) }}</td>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user