feat(non-loanable-devices): implement non-loanable device management
- Add non_loanable_devices table to database schema - Add web interface routes: /non_loanable_devices, /add_non_loanable_device, /edit_non_loanable_device, /delete_non_loanable_device - Add CLI menu options 8-10 for non-loanable device management - Add templates for non-loanable device CRUD operations - Update README.md with new feature documentation - Update REQUIREMENTS.md marking non-loanable devices as implemented - Add gestiontablets.sh script Implements: #porDefinir Registrar nuevos dispositivos no prestables
This commit is contained in:
parent
ac73e5dc93
commit
d3d1fb1b32
10 changed files with 417 additions and 6 deletions
109
app.py
109
app.py
|
|
@ -63,6 +63,22 @@ def init_db():
|
|||
)
|
||||
''')
|
||||
|
||||
# Create non_loanable_devices table for devices that cannot be loaned
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS non_loanable_devices (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
brand TEXT NOT NULL,
|
||||
model TEXT NOT NULL,
|
||||
serial_number TEXT UNIQUE NOT NULL,
|
||||
device_type TEXT NOT NULL,
|
||||
location TEXT,
|
||||
status TEXT DEFAULT 'available',
|
||||
notes TEXT,
|
||||
purchase_date TEXT,
|
||||
purchase_cost REAL
|
||||
)
|
||||
''')
|
||||
|
||||
conn.commit()
|
||||
|
||||
@app.route('/')
|
||||
|
|
@ -319,6 +335,99 @@ def user_loans():
|
|||
return render_template('user_loans.html', users_with_loans=user_loans_list)
|
||||
|
||||
|
||||
@app.route('/non_loanable_devices')
|
||||
def non_loanable_devices():
|
||||
"""Show all non-loanable devices"""
|
||||
with get_db() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT * FROM non_loanable_devices ORDER BY device_type, brand, model")
|
||||
devices = cursor.fetchall()
|
||||
|
||||
return render_template('non_loanable_devices.html', devices=devices)
|
||||
|
||||
|
||||
@app.route('/add_non_loanable_device', methods=['GET', 'POST'])
|
||||
def add_non_loanable_device():
|
||||
"""Add a new non-loanable device to inventory"""
|
||||
if request.method == 'POST':
|
||||
brand = request.form['brand']
|
||||
model = request.form['model']
|
||||
serial_number = request.form['serial_number']
|
||||
device_type = request.form['device_type']
|
||||
location = request.form['location']
|
||||
notes = request.form['notes']
|
||||
purchase_date = request.form.get('purchase_date', '')
|
||||
purchase_cost = request.form.get('purchase_cost', '')
|
||||
|
||||
try:
|
||||
with get_db() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
INSERT INTO non_loanable_devices
|
||||
(brand, model, serial_number, device_type, location, status, notes, purchase_date, purchase_cost)
|
||||
VALUES (?, ?, ?, ?, ?, 'available', ?, ?, ?)
|
||||
''', (brand, model, serial_number, device_type, location, notes, purchase_date, purchase_cost))
|
||||
conn.commit()
|
||||
flash('Non-loanable device added successfully!', 'success')
|
||||
except sqlite3.IntegrityError:
|
||||
flash('Error: Serial number already exists!', 'error')
|
||||
|
||||
return redirect(url_for('non_loanable_devices'))
|
||||
|
||||
return render_template('add_non_loanable_device.html')
|
||||
|
||||
|
||||
@app.route('/edit_non_loanable_device/<int:device_id>', methods=['GET', 'POST'])
|
||||
def edit_non_loanable_device(device_id):
|
||||
"""Edit a non-loanable device"""
|
||||
with get_db() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT * FROM non_loanable_devices WHERE id = ?", (device_id,))
|
||||
device = cursor.fetchone()
|
||||
|
||||
if not device:
|
||||
flash('Error: Device not found!', 'error')
|
||||
return redirect(url_for('non_loanable_devices'))
|
||||
|
||||
if request.method == 'POST':
|
||||
brand = request.form['brand']
|
||||
model = request.form['model']
|
||||
serial_number = request.form['serial_number']
|
||||
device_type = request.form['device_type']
|
||||
location = request.form['location']
|
||||
status = request.form['status']
|
||||
notes = request.form['notes']
|
||||
purchase_date = request.form.get('purchase_date', '')
|
||||
purchase_cost = request.form.get('purchase_cost', '')
|
||||
|
||||
try:
|
||||
cursor.execute('''
|
||||
UPDATE non_loanable_devices SET
|
||||
brand = ?, model = ?, serial_number = ?, device_type = ?,
|
||||
location = ?, status = ?, notes = ?, purchase_date = ?, purchase_cost = ?
|
||||
WHERE id = ?
|
||||
''', (brand, model, serial_number, device_type, location, status, notes, purchase_date, purchase_cost, device_id))
|
||||
conn.commit()
|
||||
flash('Device updated successfully!', 'success')
|
||||
return redirect(url_for('non_loanable_devices'))
|
||||
except sqlite3.IntegrityError:
|
||||
flash('Error: Serial number already exists!', 'error')
|
||||
|
||||
return render_template('edit_non_loanable_device.html', device=device)
|
||||
|
||||
|
||||
@app.route('/delete_non_loanable_device/<int:device_id>')
|
||||
def delete_non_loanable_device(device_id):
|
||||
"""Delete a non-loanable device"""
|
||||
with get_db() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("DELETE FROM non_loanable_devices WHERE id = ?", (device_id,))
|
||||
conn.commit()
|
||||
flash('Device deleted successfully!', 'success')
|
||||
|
||||
return redirect(url_for('non_loanable_devices'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Initialize database
|
||||
init_db()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue