diff --git a/app.py b/app.py index c4e68d0..dbb5ec5 100644 --- a/app.py +++ b/app.py @@ -690,8 +690,9 @@ def materials(): ROUND(COALESCE(SUM(j.weight_g),0),1) as total_used_g FROM materials m LEFT JOIN jobs j ON j.material_id=m.id GROUP BY m.id ORDER BY m.type, m.name''').fetchall() + types = sorted(set(m['type'] for m in mats if m['type'])) conn.close() - return render_template('materials.html', materials=mats) + return render_template('materials.html', materials=mats, types=types) @app.route('/materials/new', methods=['GET','POST']) def new_material(): @@ -746,6 +747,23 @@ def restock_material(id): conn.commit(); conn.close() return redirect(url_for('materials')) +@app.route('/materials//duplicate', methods=['POST']) +def duplicate_material(id): + conn = get_db() + m = conn.execute('SELECT * FROM materials WHERE id=?',(id,)).fetchone() + if m: + conn.execute('''INSERT INTO materials(name,brand,type,color,price_per_kg,stock_g,low_stock_threshold_g,notes) + VALUES(?,?,?,?,?,?,?,?)''', + ('Copie de ' + m['name'], m['brand'], m['type'], m['color'], + m['price_per_kg'], 0, m['low_stock_threshold_g'], m['notes'])) + new_id = conn.execute('SELECT last_insert_rowid()').fetchone()[0] + conn.execute('INSERT INTO material_price_history(material_id,price_per_kg) VALUES(?,?)', + (new_id, m['price_per_kg'])) + conn.commit(); conn.close() + return redirect(url_for('edit_material', id=new_id)) + conn.close() + return redirect(url_for('materials')) + @app.route('/materials//delete', methods=['POST']) def delete_material(id): conn = get_db() diff --git a/templates/materials.html b/templates/materials.html index 358bf98..1af8d55 100644 --- a/templates/materials.html +++ b/templates/materials.html @@ -4,25 +4,97 @@ {% block content %} + + +
+
+
+ +
+ +
+ + + +
+
+ +
+ +
+ + {% for t in types %} + + {% endfor %} +
+
+ +
+ + +
+
+ +
+
{% if materials %} - +
- - + + + + + + + + - + {% for m in materials %} {% set stock_pct = [[(m.stock_g / 1000 * 100)|round(0)|int, 0]|max, 100]|min %} - + @@ -106,6 +183,12 @@ {% endfor %}
NomTypeCouleurPrix/kgStockCommandesUtilisé total + Nom + + Type + Couleur + Prix/kg + + Stock + Commandes + Utilisé total +
{{ m.name }}{% if m.brand %} / {{ m.brand }}{% endif %} {{ m.type }} @@ -49,24 +121,29 @@ {% if m.stock_g <= 0 %}bg-danger {% elif m.stock_g <= m.low_stock_threshold_g %}bg-warning {% else %}bg-success{% endif %}" - style="width:{{ [[(m.stock_g / 1000 * 100)|round(0)|int, 0]|max, 100]|min }}%"> + style="width:{{ stock_pct }}%"> {{ m.job_count }} {{ m.total_used_g }} g -
+
- + +
+ +
- + onsubmit="return confirm('Supprimer {{ m.name }} ?')"> +
+ + {% else %}
@@ -118,3 +201,151 @@
{% endblock %} + +{% block scripts %} + +{% endblock %}