Preventive Maintenance in NorfelloCMMS OS
See the ticket #456.
Creating tasks with a ruby script
Because this feature is not implemented in the current code base but needed by many, here is a short script that can be used to create new tasks automatically. The script could be run manually or by some scheduling software such as cron for Unix environments or scheduled tasks in Windows.
The script works as follows:
- Login as some user (must be authorized to create new tasks to the assets)
- Find task type for the new tasks
- Find assets that the tasks are created to
- Create new tasks to assets
You can run the script with the 'runner' script that can be found in the script directory of the CMMS installation. For example if you save the example script to create_tasks.rb in the installation directory you can run it like this:
ruby script/runner create_tasks.rb
# Example script for scheduled maintenance
# Login as some user
User.current_user = User.find_by_login('admin')
# Task type
task_type = TaskType.find_by_name('Preventive Maintenance')
if not task_type
puts 'ERROR: Task type not found'
exit
end
# Example1: Some assets by code
assets = []
codes = ['CMMS-PUMP1', 'CMMS-PUMP2']
codes.each { |c|
a = Asset.find_by_full_code(c)
if not a
puts 'ERROR: Asset %s not found' % c
exit
end
assets.push(a)
}
# Example2: All assets of some type
#assets = AssetType.find_by_name('PistonPump').assets
# Task creation
assets.each { |a|
puts 'Creating new "%s" task to asset %s' % [task_type.name, a.full_code]
new_task = Task.new()
new_task.task_type = task_type
new_task.asset = a
new_task.short_description = "Weekly check"
new_task.long_description = "Check the following:\n* pump pressure\n* seals for leaks\n"
new_task.starting_time = Date.today
new_task.deadline = Date.today + 10
# Priority values
# Highest 6
# Very high 5
# High 4
# Normal 3
# Low 2
# Very low 1
# Lowest 0
new_task.priority = 3
new_task.estimated_working_time = 16
new_task.save!
}