feat(abm): abm completo de ciclos lectivos, aulas y reservas con proteccion de integridad y pruebas automatizadas
This commit is contained in:
@@ -1387,6 +1387,53 @@ def set_current_academic_term(id):
|
||||
'message': f'"{term.name}" establecido como ciclo activo.'
|
||||
}), 200
|
||||
|
||||
@api_admin_bp.route('/academic-terms/<int:id>/toggle', methods=['POST'])
|
||||
@jwt_required
|
||||
def toggle_academic_term(id):
|
||||
term = AcademicTerm.query.get_or_404(id)
|
||||
if term.is_current and term.is_active:
|
||||
return jsonify({
|
||||
'error': 'Conflict',
|
||||
'message': 'No se puede desactivar el ciclo lectivo actualmente activo. Seleccione otro ciclo activo primero.'
|
||||
}), 400
|
||||
term.is_active = not term.is_active
|
||||
db.session.commit()
|
||||
return jsonify({
|
||||
'status': 'success',
|
||||
'id': term.id,
|
||||
'is_active': term.is_active,
|
||||
'message': f'Ciclo lectivo {"habilitado" if term.is_active else "desactivado"} correctamente.'
|
||||
}), 200
|
||||
|
||||
@api_admin_bp.route('/academic-terms/<int:id>', methods=['DELETE'])
|
||||
@jwt_required
|
||||
def delete_academic_term(id):
|
||||
term = AcademicTerm.query.get_or_404(id)
|
||||
if term.is_current:
|
||||
return jsonify({
|
||||
'error': 'Conflict',
|
||||
'message': 'No se puede eliminar el ciclo lectivo actualmente activo. Seleccione otro ciclo activo primero.'
|
||||
}), 400
|
||||
|
||||
commissions_count = Commission.query.filter_by(academic_term_id=id).count()
|
||||
if commissions_count > 0:
|
||||
# Soft delete para preservar integridad de comisiones
|
||||
term.is_active = False
|
||||
db.session.commit()
|
||||
return jsonify({
|
||||
'status': 'success',
|
||||
'soft_deleted': True,
|
||||
'message': f'El ciclo lectivo tiene {commissions_count} comisiones asociadas. Ha sido desactivado para proteger el historial académico.'
|
||||
}), 200
|
||||
|
||||
db.session.delete(term)
|
||||
db.session.commit()
|
||||
return jsonify({
|
||||
'status': 'success',
|
||||
'soft_deleted': False,
|
||||
'message': 'Ciclo lectivo eliminado permanentemente.'
|
||||
}), 200
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# MILESTONE TYPES CRUD
|
||||
# ---------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user