#NEWLINE# @ staticmethod #NEWLINE# def ireport_onaccept( form ) : #NEWLINE# #INDENT# '\n            Assign the appropriate vehicle & on-shift team to the incident\n            @ToDo: Specialist teams\n            @ToDo: Make more generic (currently Porto-specific)\n        ' #NEWLINE# settings = current . deployment_settings #NEWLINE# if ( settings . has_module ( 'fire' ) and settings . has_module ( 'vehicle' ) ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# db = current . db #NEWLINE# s3db = current . s3db #NEWLINE# vars = form . vars #NEWLINE# ireport = vars . id #NEWLINE# category = vars . category #NEWLINE# if ( category == '1100' ) : #NEWLINE# #INDENT# types = [ 'VUCI' , 'ABSC' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( category == '6102' ) : #NEWLINE# #INDENT# types = [ 'VUCI' , 'VCOT' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( category == '8201' ) : #NEWLINE# #INDENT# types = [ 'VLCI' , 'ABSC' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# types = [ 'VLCI' ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# table = s3db . irs_ireport_vehicle #NEWLINE# stable = s3db . org_site #NEWLINE# atable = s3db . asset_asset #NEWLINE# vtable = s3db . vehicle_vehicle #NEWLINE# ftable = s3db . fire_station #NEWLINE# fvtable = s3db . fire_station_vehicle #NEWLINE# for type in types : #NEWLINE# #INDENT# query = ( ( ( ( ( atable . type == s3db . asset_types [ 'VEHICLE' ] ) & ( vtable . type == type ) ) & ( vtable . asset_id == atable . id ) ) & ( atable . deleted == False ) ) & ( ( ( table . id == None ) | ( table . closed == True ) ) | ( table . deleted == True ) ) ) #NEWLINE# left = table . on ( ( atable . id == table . asset_id ) ) #NEWLINE# vehicle = db ( query ) . select ( atable . id , left = left , limitby = ( 0 , 1 ) ) . first ( ) #NEWLINE# if vehicle : #NEWLINE# #INDENT# vehicle = vehicle . id #NEWLINE# query = ( ( ( ( vtable . asset_id == vehicle ) & ( fvtable . vehicle_id == vtable . id ) ) & ( ftable . id == fvtable . station_id ) ) & ( stable . id == ftable . site_id ) ) #NEWLINE# site = db ( query ) . select ( stable . id , limitby = ( 0 , 1 ) ) . first ( ) #NEWLINE# if site : #NEWLINE# #INDENT# site = site . id #NEWLINE# #UNINDENT# table . insert ( ireport_id = ireport , asset_id = vehicle , site_id = site ) #NEWLINE# if settings . has_module ( 'hrm' ) : #NEWLINE# #INDENT# table = s3db . irs_ireport_vehicle_human_resource #NEWLINE# htable = s3db . hrm_human_resource #NEWLINE# on_shift = s3db . fire_staff_on_duty ( ) #NEWLINE# query = ( on_shift & ( ( ( table . id == None ) | ( table . closed == True ) ) | ( table . deleted == True ) ) ) #NEWLINE# left = table . on ( ( htable . id == table . human_resource_id ) ) #NEWLINE# people = db ( query ) . select ( htable . id , left = left , limitby = ( 0 , 5 ) ) #NEWLINE# leader = people . first ( ) #NEWLINE# if leader : #NEWLINE# #INDENT# leader = leader . id #NEWLINE# #UNINDENT# for person in people : #NEWLINE# #INDENT# if ( person . id == leader . id ) : #NEWLINE# #INDENT# table . insert ( ireport_id = ireport , asset_id = vehicle , human_resource_id = person . id , incident_commander = True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# table . insert ( ireport_id = ireport , asset_id = vehicle , human_resource_id = person . id )