System Setup and Role Configuration
Overview
This module is responsible for configuring system defaults and permissions required for the logistics tracking system during system migration.
It performs three main tasks:
- Creates required fleet manager roles
- Configures default settings for logistics operations
- Assigns permissions to specific DocTypes for fleet management roles
Migration Hook
def after_migrate():
create_user_roles_and_profiles()
add_permission_to_fleet_manager_doctype()
Purpose
This function is triggered automatically after the system migration process. It ensures that all required roles and permissions are created when the application is installed or updated.
Technical Behavior
- Creates predefined fleet manager roles
- Applies required permissions to logistics-related DocTypes
Default Logistics Settings Configuration
def execute():
defaults = [
("set_geofence_radius", "50", "Int"),
("tracking_link_expiry_threshold", "4", "Float"),
("stoppage_threshold", "5", "Int"),
("deviation_threshold", "2000", "Int"),
("pickup_location_threshold", "200", "Int"),
("destination_location_threshold", "200", "Int"),
("deviation_gap_threshold", "100", "Int"),
]
Purpose
This function sets default values for important logistics configuration fields in the Logistics Settings DocType using property setters.
Technical Explanation
The function iterates through predefined configuration values and applies them as default values using the system's property setter mechanism.
make_property_setter(
"Logistics Settings",
fieldname,
"default",
value,
fieldtype
)
Configured Default Values
| Setting | Default Value | Description |
|---|---|---|
| set_geofence_radius | 50 | Defines the default geofence radius for location detection |
| tracking_link_expiry_threshold | 4 hours | Defines how long a tracking link remains active |
| stoppage_threshold | 5 minutes | Minimum duration required to detect vehicle stoppage |
| deviation_threshold | 2000 meters | Maximum route deviation distance allowed |
| pickup_location_threshold | 200 meters | Distance threshold to detect arrival at pickup location |
| destination_location_threshold | 200 meters | Distance threshold to detect arrival at destination |
| deviation_gap_threshold | 100 meters | Minimum gap distance used for route deviation calculation |
Fleet Manager Role Creation
def create_user_roles_and_profiles():
roles = [
"Block Fleet Manager",
"AAC Fleet Manager",
"RMC Fleet Manager"
]
Purpose
This function ensures that required fleet management roles exist in the system. If the roles are not present, they are automatically created.
Roles Created
- Block Fleet Manager
- AAC Fleet Manager
- RMC Fleet Manager
Technical Flow
- Define required roles
- Check if the role exists in the system
- If the role does not exist, create a new Role document
frappe.get_doc({
"doctype": "Role",
"role_name": role_name,
"desk_access": 1
}).insert()
The desk_access property ensures that users with this role can access the system dashboard.
Fleet Manager Permission Configuration
def add_permission_to_fleet_manager_doctype():
Purpose
This function assigns required permissions for fleet manager roles on specific system DocTypes.
DocTypes Configured
- Vehicle
- Page
- Address
Permissions Granted
| Permission | Description |
|---|---|
| Read | Allows viewing records |
| Write | Allows editing records |
| Create | Allows creation of new records |
| Delete | Allows deletion of records |
| Allows document printing | |
| Share | Allows sharing records with other users |
Permission Assignment Process
def set_permissions_for_doctype(doctype, role, permissions):
Technical Flow
- Add permission rule for the specified role
- Update individual permission properties
- Apply the permission settings to the DocType
frappe.permissions.add_permission(doctype, role, 0)
After adding the permission entry, individual permission properties are updated using:
frappe.permissions.update_permission_property(
doctype=doctype,
role=role,
permlevel=0,
ptype=perm_type,
value=value
)
Database Commit
After permissions are configured, the changes are committed to the database to ensure they are persisted.
frappe.db.commit()
Technical Benefits
- Automates system setup during installation
- Ensures consistent default configuration values
- Automatically creates required fleet management roles
- Configures access permissions for logistics operations
- Reduces manual system configuration effort
Summary
This module ensures that the logistics system is properly configured during deployment by automatically creating roles, applying permissions, and setting default configuration values for logistics operations.