diff --git a/py/jon/db/transfer_items.sql b/py/jon/db/transfer_items.sql new file mode 100644 index 0000000..3e92f81 --- /dev/null +++ b/py/jon/db/transfer_items.sql @@ -0,0 +1,5 @@ +INSERT INTO garfield.inventory_correction (item_id, delta, correction_comment) +VALUES (%(from_item_id)s, -%(amount)s, CONCAT('Umbuchung auf ', %(to_item_id)s)); + +INSERT INTO garfield.inventory_correction (item_id, delta, correction_comment) +VALUES (%(to_item_id)s, %(amount)s, CONCAT('Umbuchung von ', %(from_item_id)s)); diff --git a/py/jon/inventory.py b/py/jon/inventory.py index de47720..a451049 100644 --- a/py/jon/inventory.py +++ b/py/jon/inventory.py @@ -80,3 +80,28 @@ def create_correction(): db.get_db().commit() return redirect(request.referrer) + + +@bp.post("/transfer") +def transfer_items(): + try: + from_item_id = int(request.form.get("from_item_id")) + to_item_id = int(request.form.get("to_item_id")) + amount = int(request.form.get("amount")) + except: + return "Incomplete or mistyped form", 400 + + if amount == 0: + return "Amount may not be 0", 400 + + if from_item_id == to_item_id: + return "Transfers must be between different items", 400 + + db.run_query("transfer_items.sql", { + "from_item_id": from_item_id, + "to_item_id": to_item_id, + "amount": amount + }) + db.get_db().commit() + + return redirect(request.referrer) diff --git a/py/jon/templates/inventory/read_item.html b/py/jon/templates/inventory/read_item.html index a545199..4143083 100644 --- a/py/jon/templates/inventory/read_item.html +++ b/py/jon/templates/inventory/read_item.html @@ -22,8 +22,7 @@ Einkaufspreis (Netto) {{ format_currency(item.unit_price) }} - - Kaufdatum + Kaufdatum {{ format_date(item.bought) }} @@ -121,25 +120,33 @@ AS Aktiv? - {% for item in same_barcode_items %} + {% for other_item in same_barcode_items %} - {{ item.item_id }} - {{ item.item_barcode }} - {{ item.name }} + {{ other_item.item_id }} + {{ other_item.item_barcode }} + {{ other_item.name }} {{ format_currency(item.unit_price) }} {{ format_date(item.bought) }} - {{ item.group_name }} ({{ item.item_group }}) - {{ item.sales_units }} - {% if item.correction_delta > 0 %}+{% endif %}{{ item.correction_delta }} - {{ item.units_left }} + {{ other_item.group_name }} ({{ other_item.item_group }}) + {{ other_item.sales_units }} + {% if other_item.correction_delta > 0 %}+{% endif %}{{ other_item.correction_delta }} + {{ other_item.units_left }} - {% if item.active_mappings != 0 %} - {{ item.active_mappings_array | join(", ") }} + {% if other_item.active_mappings != 0 %} + {{ other_item.active_mappings_array | join(", ") }} {% else %} - {% endif %} - {{ format_bool(item.available) }} + {{ format_bool(other_item.available) }} + +
+ + + + {{ item.units_left }} Artikel umbuchen + + {% endfor %}