feat(config): allow admin/owner to delete branches
- Added DELETE /pos/api/config/branches/<id> that soft-deletes the branch (is_active=false). - Restricted to owner/admin; main branch cannot be deleted. - Added 'Eliminar' button in the branches grid for admin/owner.
This commit is contained in:
@@ -150,6 +150,33 @@ def update_branch(branch_id):
|
||||
return jsonify({'ok': True, 'message': 'Branch updated'})
|
||||
|
||||
|
||||
@config_bp.route('/branches/<int:branch_id>', methods=['DELETE'])
|
||||
@require_auth('config.edit')
|
||||
def delete_branch(branch_id):
|
||||
"""Soft-delete a branch. Only owner/admin can delete; main branch cannot be deleted."""
|
||||
if g.employee_role not in ('owner', 'admin'):
|
||||
return jsonify({'error': 'Solo administradores pueden eliminar sucursales'}), 403
|
||||
|
||||
conn = get_tenant_conn(g.tenant_id)
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute("SELECT is_main FROM branches WHERE id = %s", (branch_id,))
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
cur.close(); conn.close()
|
||||
return jsonify({'error': 'Branch not found'}), 404
|
||||
|
||||
if row[0]:
|
||||
cur.close(); conn.close()
|
||||
return jsonify({'error': 'No se puede eliminar la sucursal principal'}), 403
|
||||
|
||||
cur.execute("UPDATE branches SET is_active = false WHERE id = %s", (branch_id,))
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
return jsonify({'ok': True, 'message': 'Sucursal eliminada'})
|
||||
|
||||
|
||||
@config_bp.route('/employees', methods=['GET'])
|
||||
@require_auth()
|
||||
def list_employees():
|
||||
|
||||
Reference in New Issue
Block a user