This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user