feat: dupliquer un matiere et filtre
Deploy via Portainer / deploy (push) Successful in 0s

This commit is contained in:
Jo
2026-07-06 23:42:15 +02:00
parent d6c53479cf
commit 6ee16797db
2 changed files with 265 additions and 16 deletions
+19 -1
View File
@@ -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/<int:id>/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/<int:id>/delete', methods=['POST'])
def delete_material(id):
conn = get_db()