feat: profils par défaut par client + fix marge 0% + fix: suggest-slot ignore les créneaux déjà passés
Deploy via Portainer / deploy (push) Successful in 0s
Deploy via Portainer / deploy (push) Successful in 0s
This commit is contained in:
@@ -173,6 +173,10 @@ def init_db():
|
||||
'ALTER TABLE jobs ADD COLUMN pieces_per_plate INTEGER DEFAULT 1',
|
||||
'ALTER TABLE jobs ADD COLUMN order_qty INTEGER DEFAULT 1',
|
||||
'ALTER TABLE jobs ADD COLUMN price_per_piece REAL',
|
||||
'ALTER TABLE clients ADD COLUMN default_machine_profile_id INTEGER',
|
||||
'ALTER TABLE clients ADD COLUMN default_handling_profile_id INTEGER',
|
||||
'ALTER TABLE clients ADD COLUMN default_material_profile_id INTEGER',
|
||||
'ALTER TABLE clients ADD COLUMN default_pricing_profile_id INTEGER',
|
||||
]
|
||||
for sql in migrations:
|
||||
try:
|
||||
@@ -453,7 +457,10 @@ def find_next_slot(print_time_s):
|
||||
candidates.append(datetime(d.year, d.month, d.day, h0, m0))
|
||||
candidates.append(datetime(d.year, d.month, d.day, h1, m1))
|
||||
|
||||
now = datetime.now()
|
||||
for start_dt in candidates:
|
||||
if start_dt <= now: # ignorer les créneaux déjà passés
|
||||
continue
|
||||
end_dt = start_dt + timedelta(seconds=total_sec)
|
||||
for printer in printers:
|
||||
pid = printer['id']
|
||||
@@ -516,30 +523,64 @@ def clients():
|
||||
conn.close()
|
||||
return render_template('clients.html', clients=clients)
|
||||
|
||||
def _get_all_profiles(conn):
|
||||
return {
|
||||
'machine_profiles': conn.execute('SELECT id,name FROM machine_profiles ORDER BY name').fetchall(),
|
||||
'handling_profiles': conn.execute('SELECT id,name FROM handling_profiles ORDER BY name').fetchall(),
|
||||
'material_profiles': conn.execute('SELECT id,name FROM material_profiles ORDER BY name').fetchall(),
|
||||
'pricing_profiles': conn.execute('SELECT id,name FROM pricing_profiles ORDER BY name').fetchall(),
|
||||
}
|
||||
|
||||
@app.route('/clients/new', methods=['GET','POST'])
|
||||
def new_client():
|
||||
conn = get_db()
|
||||
if request.method == 'POST':
|
||||
conn = get_db()
|
||||
conn.execute('INSERT INTO clients(name,email,design_multiplier,notes) VALUES(?,?,?,?)',
|
||||
(request.form['name'], request.form.get('email',''),
|
||||
float(request.form.get('design_multiplier', 1.80)), request.form.get('notes','')))
|
||||
def _int(k): return int(request.form[k]) if request.form.get(k) else None
|
||||
conn.execute('''INSERT INTO clients
|
||||
(name,email,notes,default_machine_profile_id,default_handling_profile_id,
|
||||
default_material_profile_id,default_pricing_profile_id)
|
||||
VALUES(?,?,?,?,?,?,?)''',
|
||||
(request.form['name'], request.form.get('email',''), request.form.get('notes',''),
|
||||
_int('default_machine_profile_id'), _int('default_handling_profile_id'),
|
||||
_int('default_material_profile_id'), _int('default_pricing_profile_id')))
|
||||
conn.commit(); conn.close()
|
||||
return redirect(url_for('clients'))
|
||||
return render_template('client_form.html', client=None)
|
||||
profiles = _get_all_profiles(conn)
|
||||
conn.close()
|
||||
return render_template('client_form.html', client=None, **profiles)
|
||||
|
||||
@app.route('/clients/<int:id>/edit', methods=['GET','POST'])
|
||||
def edit_client(id):
|
||||
conn = get_db()
|
||||
client = conn.execute('SELECT * FROM clients WHERE id=?',(id,)).fetchone()
|
||||
if request.method == 'POST':
|
||||
conn.execute('UPDATE clients SET name=?,email=?,design_multiplier=?,notes=? WHERE id=?',
|
||||
(request.form['name'], request.form.get('email',''),
|
||||
float(request.form.get('design_multiplier', client['design_multiplier'])),
|
||||
request.form.get('notes',''), id))
|
||||
def _int(k): return int(request.form[k]) if request.form.get(k) else None
|
||||
conn.execute('''UPDATE clients SET name=?,email=?,notes=?,
|
||||
default_machine_profile_id=?,default_handling_profile_id=?,
|
||||
default_material_profile_id=?,default_pricing_profile_id=? WHERE id=?''',
|
||||
(request.form['name'], request.form.get('email',''), request.form.get('notes',''),
|
||||
_int('default_machine_profile_id'), _int('default_handling_profile_id'),
|
||||
_int('default_material_profile_id'), _int('default_pricing_profile_id'), id))
|
||||
conn.commit(); conn.close()
|
||||
return redirect(url_for('clients'))
|
||||
profiles = _get_all_profiles(conn)
|
||||
conn.close()
|
||||
return render_template('client_form.html', client=client)
|
||||
return render_template('client_form.html', client=client, **profiles)
|
||||
|
||||
@app.route('/api/client/<int:id>/defaults')
|
||||
def api_client_defaults(id):
|
||||
conn = get_db()
|
||||
c = conn.execute('SELECT default_machine_profile_id, default_handling_profile_id, \
|
||||
default_material_profile_id, default_pricing_profile_id FROM clients WHERE id=?',(id,)).fetchone()
|
||||
conn.close()
|
||||
if not c:
|
||||
return jsonify({})
|
||||
return jsonify({
|
||||
'machine_profile_id': c['default_machine_profile_id'],
|
||||
'handling_profile_id': c['default_handling_profile_id'],
|
||||
'material_profile_id': c['default_material_profile_id'],
|
||||
'pricing_profile_id': c['default_pricing_profile_id'],
|
||||
})
|
||||
|
||||
@app.route('/clients/<int:id>/delete', methods=['POST'])
|
||||
def delete_client(id):
|
||||
|
||||
Reference in New Issue
Block a user