Overview
Locations represent physical facilities, sites, or buildings within your organization. Users, assets, work orders, and other resources can be assigned to locations for organizational and access control purposes.Managing locations requires
locations:full_access. Viewing locations only requires locations:read.Location Data Model
| Field | Type | Description |
|---|---|---|
id | Integer | Unique location identifier |
name | String | Location name (e.g., “Edificio Central”) |
code | String | Short code for the location (e.g., “EC01”) |
description | Text | Optional description |
is_active | Boolean | Whether the location is available for use |
created_at | Timestamp | Creation date |
updated_at | Timestamp | Last modification date |
created_by | UUID | User who created the location |
updated_by | UUID | User who last updated the location |
Location Management Workflows
Creating a Location
Fill in Location Details
- Name: Descriptive location name (required)
- Code: Short identifier code (required, must be unique)
- Description: Optional detailed description
- Active: Whether the location is active (default:
true)
Location codes are often used in filters and dropdowns, so choose concise, meaningful codes (e.g., “HQ”, “WH01”, “FAC-A”).
Editing a Location
Activating/Deactivating a Location
Deactivating a location hides it from dropdowns and filters without deleting it:
Effects of Deactivation:
- Location no longer appears in user assignment dropdowns
- Existing users/resources remain assigned to the location
- Historical data is preserved
- Location can be reactivated at any time
Requires
locations:disable permission.Deleting a Location
Check Dependencies
Verify that no critical resources are assigned to the location:
- Users
- Assets
- Active work orders
locations:delete permission.
Using Locations for Access Control
User Location Assignment
Users can be assigned to a location during creation or editing:- Open the user creation/edit form
- Select a location from the “Ubicación” dropdown
- Save the user
Location-Based Filtering
Many modules support location filtering:- User Management: Filter users by location
- Work Orders: Filter work orders by location
- Assets: Filter assets by location
- Reports: Generate reports for specific locations
Row-Level Security (RLS) with Locations
Locations can be used in RLS policies to restrict data access:Location-based RLS policies must be implemented in the database schema. Consult your database administrator.
Service Layer Reference
Location operations are handled bylocationService.ts:
Key Functions
Example: Fetching Active Locations
Example: Creating a Location
Database Schema
locations Table
RLS Policies
Best Practices
Use Consistent Naming
Adopt a naming convention for location codes (e.g., building prefix + number).
Deactivate Instead of Delete
Preserve historical data by deactivating unused locations rather than deleting them.
Assign Users to Locations
Ensure all users have a location assignment for better filtering and reporting.
Review Location Assignments Regularly
Audit user and asset location assignments to ensure accuracy.
Use Descriptions for Context
Add descriptions to locations to clarify their purpose or physical address.
Limit Location Count
Too many locations can complicate navigation. Group similar locations when possible.
Permissions Required
| Action | Permission Code |
|---|---|
| View locations | locations:read |
| Create locations | locations:create |
| Edit locations | locations:update |
| Activate/deactivate | locations:disable |
| Delete locations | locations:delete |
| Full access (all operations) | locations:full_access |
Troubleshooting
”Code already exists”
Cause: Location codes must be unique. Solution: Choose a different code or update the existing location.Location Not Appearing in Dropdowns
Cause: The location is marked asis_active = false.
Solution: Activate the location or use the “Include inactive” filter.
Cannot Delete Location
Possible causes:- Users are assigned to the location → Reassign users first
- Assets are assigned to the location → Reassign assets
- Missing
locations:deletepermission → Request permission from admin
Location Filter Not Working
Cause: The filter may be comparing by name, code, or ID inconsistently. Solution: Verify that the filter is using the correct field (usuallylocation_id).