<s> """<STR_LIT>""" <EOL> module = request . controller <EOL> resourcename = request . function <EOL> if not settings . has_module ( module ) : <EOL> raise HTTP ( <NUM_LIT> , body = "<STR_LIT>" % module ) <EOL> def index ( ) : <EOL> """<STR_LIT>""" <EOL> return s3db . cms_index ( module , alt_function = "<STR_LIT>" ) <EOL> def index_alt ( ) : <EOL> """<STR_LIT>""" <EOL> s3_redirect_default ( URL ( f = "<STR_LIT>" ) ) <EOL> def is_affiliated ( ) : <EOL> """<STR_LIT>""" <EOL> if not auth . is_logged_in ( ) : <EOL> return False <EOL> elif s3_has_role ( ADMIN ) : <EOL> return True <EOL> else : <EOL> table = auth . settings . table_user <EOL> auth_user = db ( table . id == auth . user . id ) . select ( table . organisation_id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> ) . first ( ) <EOL> if auth_user and auth_user . organisation_id : <EOL> return True <EOL> else : <EOL> return False <EOL> def create ( ) : <EOL> """<STR_LIT>""" <EOL> redirect ( URL ( f = "<STR_LIT>" , args = "<STR_LIT>" ) ) <EOL> def marker_fn ( record ) : <EOL> """<STR_LIT>""" <EOL> type = record . type <EOL> if type in ( <NUM_LIT:1> , <NUM_LIT:8> ) : <EOL> marker = "<STR_LIT>" <EOL> elif type == <NUM_LIT:3> : <EOL> marker = "<STR_LIT>" <EOL> else : <EOL> marker = "<STR_LIT>" <EOL> priority = record . priority <EOL> if priority == <NUM_LIT:3> : <EOL> marker = "<STR_LIT>" % marker <EOL> elif priority == <NUM_LIT:2> : <EOL> marker = "<STR_LIT>" % marker <EOL> mtable = db . gis_marker <EOL> marker = db ( mtable . name == marker ) . select ( mtable . image , <EOL> mtable . height , <EOL> mtable . width , <EOL> cache = s3db . cache , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> return marker <EOL> def req ( ) : <EOL> """<STR_LIT>""" <EOL> s3 . filter = ( s3db . req_req . is_template == False ) <EOL> output = req_controller ( ) <EOL> return output <EOL> def req_template ( ) : <EOL> """<STR_LIT>""" <EOL> table = s3db . req_req <EOL> field = table . is_template <EOL> field . default = True <EOL> field . readable = field . writable = False <EOL> s3 . filter = ( field == True ) <EOL> settings . req . prompt_match = False <EOL> if "<STR_LIT>" in request . args : <EOL> table = s3db . req_req_item <EOL> list_fields = [ "<STR_LIT:id>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> s3db . configure ( "<STR_LIT>" , <EOL> list_fields = list_fields , <EOL> ) <EOL> elif "<STR_LIT>" in request . args : <EOL> table = s3db . req_req_skill <EOL> list_fields = [ "<STR_LIT:id>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> s3db . configure ( "<STR_LIT>" , <EOL> list_fields = list_fields , <EOL> ) <EOL> else : <EOL> fields = [ "<STR_LIT>" , <EOL> "<STR_LIT:date>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> for fieldname in fields : <EOL> field = table [ fieldname ] <EOL> field . readable = field . writable = False <EOL> table . purpose . label = T ( "<STR_LIT>" ) <EOL> list_fields = [ "<STR_LIT:id>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> if len ( settings . get_req_req_type ( ) ) > <NUM_LIT:1> : <EOL> list_fields . append ( "<STR_LIT:type>" ) <EOL> list_fields . append ( "<STR_LIT>" ) <EOL> list_fields . append ( "<STR_LIT>" ) <EOL> list_fields . append ( "<STR_LIT>" ) <EOL> s3db . configure ( "<STR_LIT>" , <EOL> list_fields = list_fields , <EOL> ) <EOL> s3 . crud_strings [ "<STR_LIT>" ] = Storage ( <EOL> label_create = T ( "<STR_LIT>" ) , <EOL> title_display = T ( "<STR_LIT>" ) , <EOL> title_list = T ( "<STR_LIT>" ) , <EOL> title_update = T ( "<STR_LIT>" ) , <EOL> label_list_button = T ( "<STR_LIT>" ) , <EOL> label_delete_button = T ( "<STR_LIT>" ) , <EOL> msg_record_created = T ( "<STR_LIT>" ) , <EOL> msg_record_modified = T ( "<STR_LIT>" ) , <EOL> msg_record_deleted = T ( "<STR_LIT>" ) , <EOL> msg_list_empty = T ( "<STR_LIT>" ) ) <EOL> output = req_controller ( template = True ) <EOL> return output <EOL> def req_controller ( template = False ) : <EOL> """<STR_LIT>""" <EOL> REQ_STATUS_PARTIAL = <NUM_LIT:1> <EOL> REQ_STATUS_COMPLETE = <NUM_LIT:2> <EOL> def prep ( r ) : <EOL> table = r . table <EOL> s3 . req_prep ( r ) <EOL> req_type = ( r . record and r . record . type ) or ( get_vars . type and int ( get_vars . type ) ) <EOL> if r . interactive : <EOL> if "<STR_LIT>" in get_vars and "<STR_LIT>" in get_vars : <EOL> iitable = s3db . inv_inv_item <EOL> inv_item = db ( iitable . id == get_vars . inv_item_id ) . select ( iitable . site_id , <EOL> iitable . item_id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> ) . first ( ) <EOL> site_id = inv_item . site_id <EOL> db ( s3db . req_req_item . id == get_vars . req_item_id ) . update ( site_id = site_id ) <EOL> response . confirmation = T ( "<STR_LIT>" ) % { "<STR_LIT>" : s3db . supply_ItemRepresent ( ) ( inv_item . item_id ) , <EOL> "<STR_LIT>" : s3db . org_SiteRepresent ( ) ( site_id ) <EOL> } <EOL> elif "<STR_LIT>" in get_vars : <EOL> table . site_id . default = get_vars . get ( "<STR_LIT>" ) <EOL> table . site_id . writable = False <EOL> if r . http == "<STR_LIT:POST>" : <EOL> del r . get_vars [ "<STR_LIT>" ] <EOL> table . requester_id . represent = requester_represent <EOL> if req_type : <EOL> table . type . default = req_type <EOL> table . type . readable = table . type . writable = False <EOL> crud_strings = settings . get_req_req_crud_strings ( req_type ) <EOL> if crud_strings : <EOL> s3 . crud_strings [ "<STR_LIT>" ] = crud_strings <EOL> elif req_type == <NUM_LIT:1> : <EOL> s3 . crud_strings [ "<STR_LIT>" ] . label_create = T ( "<STR_LIT>" ) <EOL> elif req_type == <NUM_LIT:3> : <EOL> s3 . crud_strings [ "<STR_LIT>" ] . label_create = T ( "<STR_LIT>" ) <EOL> r . resource . add_filter ( table . type == req_type ) <EOL> if req_type == <NUM_LIT:1> : <EOL> table . date_recv . readable = table . date_recv . writable = True <EOL> if settings . get_req_items_ask_purpose ( ) : <EOL> table . purpose . label = T ( "<STR_LIT>" ) <EOL> table . site_id . label = T ( "<STR_LIT>" ) <EOL> table . request_for_id . label = T ( "<STR_LIT>" ) <EOL> table . recv_by_id . label = T ( "<STR_LIT>" ) <EOL> elif req_type == <NUM_LIT:3> : <EOL> table . date_required_until . readable = table . date_required_until . writable = True <EOL> table . purpose . label = T ( "<STR_LIT>" ) <EOL> table . purpose . comment = DIV ( _class = "<STR_LIT>" , <EOL> _title = "<STR_LIT>" % ( T ( "<STR_LIT>" ) , <EOL> T ( "<STR_LIT>" ) ) ) <EOL> table . site_id . label = T ( "<STR_LIT>" ) <EOL> table . requester_id . label = T ( "<STR_LIT>" ) <EOL> table . request_for_id . label = T ( "<STR_LIT>" ) <EOL> table . recv_by_id . label = T ( "<STR_LIT>" ) <EOL> if r . component : <EOL> if r . component_name == "<STR_LIT>" : <EOL> s3 . crud . submit_button = T ( "<STR_LIT>" ) <EOL> elif r . component_name == "<STR_LIT>" : <EOL> ctable = r . component . table <EOL> ctable . site_id . writable = ctable . site_id . readable = False <EOL> s3 . req_hide_quantities ( ctable ) <EOL> elif r . component_name == "<STR_LIT>" : <EOL> s3 . req_hide_quantities ( r . component . table ) <EOL> elif r . component . alias == "<STR_LIT>" : <EOL> s3task . configure_tasktable_crud ( <EOL> function = "<STR_LIT>" , <EOL> args = [ r . id ] , <EOL> vars = dict ( user_id = auth . user is not None and auth . user . id or <NUM_LIT:0> ) , <EOL> period = <NUM_LIT> , <EOL> ) <EOL> db . scheduler_task . timeout . writable = False <EOL> else : <EOL> if r . id : <EOL> table . is_template . readable = table . is_template . writable = False <EOL> keyvalue = settings . get_ui_auto_keyvalue ( ) <EOL> if keyvalue : <EOL> kvtable = s3db . req_req_tag <EOL> keys = db ( kvtable . deleted == False ) . select ( kvtable . tag , <EOL> distinct = True ) <EOL> if keys : <EOL> tablename = "<STR_LIT>" <EOL> crud_fields = [ f for f in table . fields if table [ f ] . readable ] <EOL> cappend = crud_fields . append <EOL> add_component = s3db . add_components <EOL> list_fields = s3db . get_config ( tablename , <EOL> "<STR_LIT>" ) <EOL> lappend = list_fields . append <EOL> for key in keys : <EOL> tag = key . tag <EOL> label = T ( tag . title ( ) ) <EOL> cappend ( S3SQLInlineComponent ( "<STR_LIT>" , <EOL> label = label , <EOL> name = tag , <EOL> multiple = False , <EOL> fields = [ ( "<STR_LIT>" , "<STR_LIT:value>" ) ] , <EOL> filterby = dict ( field = "<STR_LIT>" , <EOL> options = tag , <EOL> ) <EOL> ) ) <EOL> add_component ( tablename , <EOL> org_organisation_tag = { "<STR_LIT:name>" : tag , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : ( tag , ) , <EOL> } , <EOL> ) <EOL> lappend ( ( label , "<STR_LIT>" % tag ) ) <EOL> crud_form = S3SQLCustomForm ( * crud_fields ) <EOL> s3db . configure ( tablename , <EOL> crud_form = crud_form , <EOL> ) <EOL> method = r . method <EOL> if method in ( None , "<STR_LIT>" ) : <EOL> s3db . req_create_form_mods ( ) <EOL> if req_type and settings . get_req_inline_forms ( ) : <EOL> s3db . req_inline_form ( req_type , method ) <EOL> if auth . is_logged_in ( ) and not table . site_id . default : <EOL> table . site_id . default = auth . user . site_id <EOL> elif method == "<STR_LIT>" : <EOL> if settings . get_req_inline_forms ( ) : <EOL> s3db . req_inline_form ( req_type , method ) <EOL> s3 . scripts . append ( "<STR_LIT>" % appname ) <EOL> elif method == "<STR_LIT>" : <EOL> s3db . configure ( "<STR_LIT>" , <EOL> marker_fn = marker_fn , <EOL> ) <EOL> elif r . representation == "<STR_LIT>" : <EOL> pass <EOL> elif r . representation == "<STR_LIT>" : <EOL> req_ref_represent = table . req_ref . represent <EOL> table . req_ref . represent = lambda v , show_link = False , pdf = False : req_ref_represent ( v , show_link ) <EOL> mtable = s3db . gis_marker <EOL> s3db . configure ( "<STR_LIT>" , <EOL> marker_fn = marker_fn , <EOL> ) <EOL> if r . component : <EOL> if r . component . name == "<STR_LIT>" : <EOL> record = r . record <EOL> if record : <EOL> if record . fulfil_status == REQ_STATUS_COMPLETE or record . transit_status == REQ_STATUS_COMPLETE or record . req_status == REQ_STATUS_COMPLETE or record . fulfil_status == REQ_STATUS_PARTIAL or record . transit_status == REQ_STATUS_PARTIAL or record . req_status == REQ_STATUS_PARTIAL or record . closed or record . cancel : <EOL> s3db . configure ( "<STR_LIT>" , <EOL> deletable = False , <EOL> insertable = False , <EOL> ) <EOL> elif r . component . name == "<STR_LIT>" : <EOL> table = r . component . table <EOL> record = r . record <EOL> record_id = record . id <EOL> stable = s3db . org_site <EOL> rtype = record . type <EOL> if ( rtype == <NUM_LIT:3> ) and settings . get_req_commit_people ( ) : <EOL> insertable = False <EOL> else : <EOL> commit_status = record . commit_status <EOL> if ( commit_status == <NUM_LIT:2> ) and settings . get_req_restrict_on_complete ( ) : <EOL> insertable = False <EOL> else : <EOL> insertable = True <EOL> rsites = [ ] <EOL> query = ( table . deleted == False ) & ( table . req_id == record_id ) <EOL> req_sites = db ( query ) . select ( table . site_id ) <EOL> for req_site in req_sites : <EOL> rsites . append ( req_site . site_id ) <EOL> commit_sites = db ( ( stable . deleted == False ) ) . select ( stable . id , <EOL> stable . code ) <EOL> site_opts = { } <EOL> for site in commit_sites : <EOL> if ( site . id not in site_opts ) and ( site . id not in rsites ) : <EOL> site_opts [ site . id ] = site . code <EOL> table . site_id . requires = IS_IN_SET ( site_opts ) <EOL> s3db . configure ( table , <EOL> filter_widgets = None , <EOL> insertable = insertable , <EOL> ) <EOL> if req_type == <NUM_LIT:1> : <EOL> auth . permitted_facilities ( table = r . table , <EOL> error_msg = T ( "<STR_LIT>" ) ) <EOL> if r . interactive : <EOL> itable = s3db . req_commit_item <EOL> itable . req_item_id . widget = None <EOL> itable . req_item_id . requires = IS_ONE_OF ( db , "<STR_LIT>" , <EOL> s3db . req_item_represent , <EOL> filterby = "<STR_LIT>" , <EOL> filter_opts = [ r . id ] , <EOL> orderby = "<STR_LIT>" , <EOL> sort = True , <EOL> ) <EOL> s3 . jquery_ready . append ( '''<STR_LIT>''' ) <EOL> s3forms = s3base . s3forms <EOL> crud_form = s3forms . S3SQLCustomForm ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:date>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> s3forms . S3SQLInlineComponent ( <EOL> "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> fields = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> ) , <EOL> "<STR_LIT>" , <EOL> ) <EOL> s3db . configure ( "<STR_LIT>" , <EOL> crud_form = crud_form , <EOL> ) <EOL> elif req_type == <NUM_LIT:3> : <EOL> auth . permitted_facilities ( table = r . table , <EOL> error_msg = T ( "<STR_LIT>" ) ) <EOL> if r . interactive : <EOL> skills_filter ( record_id ) <EOL> s3forms = s3base . s3forms <EOL> crud_form = s3forms . S3SQLCustomForm ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:date>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> s3forms . S3SQLInlineComponent ( <EOL> "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> fields = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> ) , <EOL> "<STR_LIT>" , <EOL> ) <EOL> s3db . configure ( "<STR_LIT>" , <EOL> crud_form = crud_form , <EOL> ) <EOL> else : <EOL> if is_affiliated ( ) : <EOL> auth . permitted_organisations ( table = r . table , <EOL> redirect_on_error = False ) <EOL> table . organisation_id . readable = table . organisation_id . writable = True <EOL> else : <EOL> field = r . component . table . committer_id <EOL> field . writable = False <EOL> field . comment = None <EOL> table . site_id . readable = table . site_id . writable = False <EOL> else : <EOL> auth . permitted_facilities ( table = r . table , <EOL> error_msg = T ( "<STR_LIT>" ) ) <EOL> if r . id : <EOL> record = r . record <EOL> if record . fulfil_status == REQ_STATUS_COMPLETE or record . transit_status == REQ_STATUS_COMPLETE or record . req_status == REQ_STATUS_COMPLETE or record . fulfil_status == REQ_STATUS_PARTIAL or record . transit_status == REQ_STATUS_PARTIAL or record . req_status == REQ_STATUS_PARTIAL or record . closed : <EOL> s3db . configure ( "<STR_LIT>" , <EOL> deletable = False , <EOL> ) <EOL> return True <EOL> s3 . prep = prep <EOL> def postp ( r , output ) : <EOL> if r . interactive : <EOL> if r . method is None : <EOL> if r . component : <EOL> s3_action_buttons ( r , deletable = s3db . get_config ( r . component . tablename , "<STR_LIT>" ) ) <EOL> if r . component . name == "<STR_LIT>" and settings . get_req_prompt_match ( ) : <EOL> s3 . actions . append ( <EOL> dict ( label = s3_unicode ( T ( "<STR_LIT>" ) ) . encode ( "<STR_LIT:utf8>" ) , <EOL> url = URL ( c = "<STR_LIT>" , <EOL> f = "<STR_LIT>" , <EOL> args = [ "<STR_LIT>" ] <EOL> ) , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> ) <EOL> elif r . component . name == "<STR_LIT>" : <EOL> if "<STR_LIT>" in output : <EOL> req_id = r . record . id <EOL> ctable = s3db . req_commit <EOL> query = ( ctable . deleted == False ) & ( ctable . req_id == req_id ) <EOL> exists = current . db ( query ) . select ( ctable . id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> if not exists : <EOL> s3 . rfooter = A ( T ( "<STR_LIT>" ) , <EOL> _href = URL ( args = [ req_id , <EOL> "<STR_LIT>" ] ) , <EOL> _class = "<STR_LIT>" , <EOL> _id = "<STR_LIT>" , <EOL> ) <EOL> s3 . jquery_ready . append ( <EOL> '''<STR_LIT>''' % T ( "<STR_LIT>" ) ) <EOL> elif r . record . type == <NUM_LIT:1> : <EOL> s3 . actions . append ( <EOL> dict ( label = s3_unicode ( T ( "<STR_LIT>" ) ) . encode ( "<STR_LIT:utf8>" ) , <EOL> url = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ "<STR_LIT>" ] ) , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> ) <EOL> s3 . jquery_ready . append ( <EOL> '''<STR_LIT>''' % T ( "<STR_LIT>" ) ) <EOL> elif r . component . alias == "<STR_LIT>" : <EOL> record_id = r . id <EOL> s3 . actions = [ <EOL> dict ( label = s3_unicode ( T ( "<STR_LIT>" ) ) . encode ( "<STR_LIT:utf8>" ) , <EOL> url = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ record_id , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ) , <EOL> dict ( label = s3_unicode ( T ( "<STR_LIT>" ) ) . encode ( "<STR_LIT:utf8>" ) , <EOL> url = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ record_id , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> _class = "<STR_LIT>" , <EOL> ) , <EOL> dict ( label = s3_unicode ( T ( "<STR_LIT>" ) ) . encode ( "<STR_LIT:utf8>" ) , <EOL> url = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ record_id , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> _class = "<STR_LIT>" , <EOL> ) , <EOL> ] <EOL> else : <EOL> if r . http == "<STR_LIT:POST>" : <EOL> if not settings . get_req_inline_forms ( ) : <EOL> form_vars = output [ "<STR_LIT>" ] . vars <EOL> type = form_vars . type <EOL> if type == "<STR_LIT:1>" : <EOL> r . next = URL ( args = [ form_vars . id , "<STR_LIT>" ] ) <EOL> elif type == "<STR_LIT:3>" : <EOL> r . next = URL ( args = [ form_vars . id , "<STR_LIT>" ] ) <EOL> else : <EOL> s3_action_buttons ( r , deletable = False ) <EOL> table = r . table <EOL> query = ( table . fulfil_status != REQ_STATUS_COMPLETE ) & ( table . transit_status != REQ_STATUS_COMPLETE ) & ( table . req_status != REQ_STATUS_COMPLETE ) & ( table . fulfil_status != REQ_STATUS_PARTIAL ) & ( table . transit_status != REQ_STATUS_PARTIAL ) & ( table . req_status != REQ_STATUS_PARTIAL ) <EOL> rows = db ( query ) . select ( table . id ) <EOL> restrict = [ str ( row . id ) for row in rows ] <EOL> s3 . actions . append ( <EOL> dict ( label = s3_unicode ( s3 . crud_labels . DELETE ) . encode ( "<STR_LIT:utf8>" ) , <EOL> url = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> _class = "<STR_LIT>" , <EOL> restrict = restrict , <EOL> ) <EOL> ) <EOL> if not template and settings . get_req_use_commit ( ) : <EOL> s3 . actions . append ( <EOL> dict ( label = s3_unicode ( T ( "<STR_LIT>" ) ) . encode ( "<STR_LIT:utf8>" ) , <EOL> url = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> ) <EOL> s3 . jquery_ready . append ( <EOL> '''<STR_LIT>''' % T ( "<STR_LIT>" ) ) <EOL> if settings . get_req_copyable ( ) : <EOL> s3 . actions . append ( <EOL> dict ( label = s3_unicode ( T ( "<STR_LIT>" ) ) . encode ( "<STR_LIT:utf8>" ) , <EOL> url = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> ) <EOL> confirm = T ( "<STR_LIT>" ) <EOL> s3 . jquery_ready . append ( '''<STR_LIT>''' % confirm ) <EOL> req_types = settings . get_req_req_type ( ) <EOL> if not template : <EOL> if "<STR_LIT>" in req_types : <EOL> if len ( req_types ) != <NUM_LIT:1> and ( get_vars . type != "<STR_LIT:1>" ) : <EOL> table = r . table <EOL> query = ( table . deleted == False ) & ( table . type == <NUM_LIT:1> ) <EOL> rows = db ( query ) . select ( table . id ) <EOL> restrict = [ str ( row . id ) for row in rows ] <EOL> else : <EOL> restrict = None <EOL> if settings . get_req_use_commit ( ) : <EOL> action = dict ( label = s3_unicode ( T ( "<STR_LIT>" ) ) . encode ( "<STR_LIT:utf8>" ) , <EOL> url = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> if restrict is not None : <EOL> action [ "<STR_LIT>" ] = restrict <EOL> s3 . actions . append ( action ) <EOL> confirm = T ( "<STR_LIT>" ) <EOL> s3 . jquery_ready . append ( '''<STR_LIT>''' % confirm ) <EOL> elif auth . user and auth . user . site_id : <EOL> action = dict ( <EOL> label = s3_unicode ( T ( "<STR_LIT>" ) ) . encode ( "<STR_LIT:utf8>" ) , <EOL> url = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> ) , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> if restrict is not None : <EOL> action [ "<STR_LIT>" ] = restrict <EOL> s3 . actions . append ( action ) <EOL> confirm = T ( "<STR_LIT>" ) <EOL> s3 . jquery_ready . append ( '''<STR_LIT>''' % confirm ) <EOL> if "<STR_LIT>" in req_types and settings . get_req_commit_people ( ) : <EOL> if len ( req_types ) != <NUM_LIT:1> and ( get_vars . type != "<STR_LIT:3>" ) : <EOL> table = r . table <EOL> query = ( table . deleted == False ) & ( table . type == <NUM_LIT:3> ) <EOL> rows = db ( query ) . select ( table . id ) <EOL> restrict = [ str ( row . id ) for row in rows ] <EOL> else : <EOL> restrict = None <EOL> if auth . user and auth . user . organisation_id : <EOL> action = dict ( label = s3_unicode ( T ( "<STR_LIT>" ) ) . encode ( "<STR_LIT:utf8>" ) , <EOL> url = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> ) , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> if restrict is not None : <EOL> action [ "<STR_LIT>" ] = restrict <EOL> s3 . actions . append ( action ) <EOL> elif r . method == "<STR_LIT>" and r . http == "<STR_LIT:POST>" : <EOL> if not settings . get_req_inline_forms ( ) : <EOL> form_vars = output [ "<STR_LIT>" ] . vars <EOL> req_type = form_vars . type <EOL> if req_type == "<STR_LIT:1>" : <EOL> r . next = URL ( args = [ form_vars . id , "<STR_LIT>" ] ) <EOL> elif req_type == "<STR_LIT:3>" : <EOL> r . next = URL ( args = [ form_vars . id , "<STR_LIT>" ] ) <EOL> return output <EOL> s3 . postp = postp <EOL> return s3_rest_controller ( "<STR_LIT>" , "<STR_LIT>" , <EOL> rheader = s3db . req_rheader , <EOL> ) <EOL> def requester_represent ( id , show_link = True ) : <EOL> """<STR_LIT>""" <EOL> if not id : <EOL> return current . messages [ "<STR_LIT>" ] <EOL> if settings . has_module ( "<STR_LIT>" ) : <EOL> has_hrm = True <EOL> else : <EOL> has_hrm = False <EOL> ptable = s3db . pr_person <EOL> ctable = s3db . pr_contact <EOL> query = ( ptable . id == id ) <EOL> left = ctable . on ( ( ctable . pe_id == ptable . pe_id ) & ( ctable . contact_method == "<STR_LIT>" ) ) <EOL> fields = [ ptable . first_name , <EOL> ptable . middle_name , <EOL> ptable . last_name , <EOL> ctable . value , <EOL> ] <EOL> if has_hrm : <EOL> htable = s3db . hrm_human_resource <EOL> left = [ left , htable . on ( htable . person_id == ptable . id ) ] <EOL> fields . append ( htable . type ) <EOL> row = db ( query ) . select ( * fields , <EOL> left = left , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> repr = s3_fullname ( row . pr_person ) <EOL> contact = row [ "<STR_LIT>" ] <EOL> if contact : <EOL> repr = "<STR_LIT>" % ( repr , contact ) <EOL> if show_link : <EOL> hr_type = row . get ( "<STR_LIT>" ) <EOL> if hr_type : <EOL> if hr_type == <NUM_LIT:1> : <EOL> controller = "<STR_LIT>" <EOL> else : <EOL> controller = "<STR_LIT>" <EOL> else : <EOL> controller = "<STR_LIT>" <EOL> request . extension = "<STR_LIT:html>" <EOL> return A ( repr , <EOL> _href = URL ( c = controller , <EOL> f = "<STR_LIT>" , <EOL> args = [ id , "<STR_LIT>" ] <EOL> ) <EOL> ) <EOL> return repr <EOL> def req_item ( ) : <EOL> """<STR_LIT>""" <EOL> if request . function != "<STR_LIT>" : <EOL> s3 . filter = ( FS ( "<STR_LIT>" ) == False ) <EOL> def prep ( r ) : <EOL> if r . interactive or r . representation == "<STR_LIT>" : <EOL> list_fields = s3db . get_config ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> list_fields . insert ( <NUM_LIT:1> , "<STR_LIT>" ) <EOL> levels = gis . get_relevant_hierarchy_levels ( ) <EOL> levels . reverse ( ) <EOL> for level in levels : <EOL> lfield = "<STR_LIT>" % level <EOL> list_fields . insert ( <NUM_LIT:1> , lfield ) <EOL> s3db . configure ( "<STR_LIT>" , <EOL> insertable = False , <EOL> list_fields = list_fields , <EOL> ) <EOL> s3 . crud_strings [ "<STR_LIT>" ] . title_list = T ( "<STR_LIT>" ) <EOL> if r . method != None and r . method != "<STR_LIT>" and r . method != "<STR_LIT>" : <EOL> s3db . req_hide_quantities ( r . table ) <EOL> return True <EOL> s3 . prep = prep <EOL> output = s3_rest_controller ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if settings . get_req_prompt_match ( ) : <EOL> req_item_inv_item_btn = dict ( url = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ "<STR_LIT>" ] ) , <EOL> _class = "<STR_LIT>" , <EOL> label = str ( T ( "<STR_LIT>" ) ) , <EOL> ) <EOL> if s3 . actions : <EOL> s3 . actions . append ( req_item_inv_item_btn ) <EOL> else : <EOL> s3 . actions = [ req_item_inv_item_btn ] <EOL> return output <EOL> def req_item_packs ( ) : <EOL> """<STR_LIT>""" <EOL> req_item_id = None <EOL> args = request . args <EOL> if len ( args ) == <NUM_LIT:1> and args [ <NUM_LIT:0> ] . isdigit ( ) : <EOL> req_item_id = args [ <NUM_LIT:0> ] <EOL> else : <EOL> for v in request . vars : <EOL> if "<STR_LIT:.>" in v and v . split ( "<STR_LIT:.>" , <NUM_LIT:1> ) [ <NUM_LIT:1> ] == "<STR_LIT>" : <EOL> req_item_id = request . vars [ v ] <EOL> break <EOL> table = s3db . supply_item_pack <EOL> ritable = s3db . req_req_item <EOL> query = ( ritable . id == req_item_id ) & ( ritable . item_id == table . item_id ) <EOL> response . headers [ "<STR_LIT:Content-Type>" ] = "<STR_LIT:application/json>" <EOL> return db ( query ) . select ( table . id , <EOL> table . name , <EOL> table . quantity ) . json ( ) <EOL> def req_item_inv_item ( ) : <EOL> """<STR_LIT>""" <EOL> req_item_id = request . args [ <NUM_LIT:0> ] <EOL> request . args = [ ] <EOL> ritable = s3db . req_req_item <EOL> req_item = ritable [ req_item_id ] <EOL> rtable = s3db . req_req <EOL> req = rtable [ req_item . req_id ] <EOL> output = { } <EOL> output [ "<STR_LIT:title>" ] = T ( "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = A ( T ( "<STR_LIT>" ) , <EOL> _href = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ req_item . req_id , "<STR_LIT>" ] ) , <EOL> _class = "<STR_LIT>" <EOL> ) <EOL> output [ "<STR_LIT>" ] = TABLE ( TR ( TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , <EOL> rtable . site_id . represent ( req . site_id ) , <EOL> TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , <EOL> ritable . item_id . represent ( req_item . item_id ) , <EOL> ) , <EOL> TR ( TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , <EOL> rtable . requester_id . represent ( req . requester_id ) , <EOL> TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , <EOL> req_item . quantity , <EOL> ) , <EOL> TR ( TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , <EOL> rtable . date . represent ( req . date ) , <EOL> TH ( T ( "<STR_LIT>" ) ) , <EOL> req_item . quantity_commit , <EOL> ) , <EOL> TR ( TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , <EOL> rtable . date_required . represent ( req . date_required ) , <EOL> TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , <EOL> req_item . quantity_transit , <EOL> ) , <EOL> TR ( TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , <EOL> rtable . priority . represent ( req . priority ) , <EOL> TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , <EOL> req_item . quantity_fulfil , <EOL> ) <EOL> ) <EOL> s3 . no_sspag = True <EOL> itable = s3db . inv_inv_item <EOL> s3 . filter = ( itable . item_id == req_item . item_id ) <EOL> s3 . crud_strings [ "<STR_LIT>" ] . msg_list_empty = T ( "<STR_LIT>" ) <EOL> inv_items = s3_rest_controller ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = inv_items [ "<STR_LIT>" ] <EOL> if settings . get_supply_use_alt_name ( ) : <EOL> atable = s3db . supply_item_alt <EOL> query = ( atable . item_id == req_item . item_id ) & ( atable . deleted == False ) <EOL> alt_item_rows = db ( query ) . select ( atable . alt_item_id ) <EOL> alt_item_ids = [ alt_item_row . alt_item_id for alt_item_row in alt_item_rows ] <EOL> if alt_item_ids : <EOL> s3 . filter = ( itable . item_id . belongs ( alt_item_ids ) ) <EOL> inv_items_alt = s3_rest_controller ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> output [ "<STR_LIT>" ] = inv_items_alt [ "<STR_LIT>" ] <EOL> else : <EOL> output [ "<STR_LIT>" ] = T ( "<STR_LIT>" ) <EOL> response . view = "<STR_LIT>" <EOL> s3 . actions = [ dict ( url = URL ( c = request . controller , <EOL> f = "<STR_LIT>" , <EOL> args = [ req_item . req_id , "<STR_LIT>" ] , <EOL> vars = dict ( req_item_id = req_item_id , <EOL> inv_item_id = "<STR_LIT>" ) <EOL> ) , <EOL> _class = "<STR_LIT>" , <EOL> label = str ( T ( "<STR_LIT>" ) ) , <EOL> ) ] <EOL> return output <EOL> def req_skill ( ) : <EOL> """<STR_LIT>""" <EOL> s3 . filter = ( FS ( "<STR_LIT>" ) == False ) <EOL> def prep ( r ) : <EOL> if r . interactive or r . representation == "<STR_LIT>" : <EOL> list_fields = s3db . get_config ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> list_fields . insert ( <NUM_LIT:1> , "<STR_LIT>" ) <EOL> list_fields . insert ( <NUM_LIT:1> , "<STR_LIT>" ) <EOL> list_fields . insert ( <NUM_LIT:1> , "<STR_LIT>" ) <EOL> s3db . configure ( "<STR_LIT>" , <EOL> insertable = False , <EOL> list_fields = list_fields , <EOL> ) <EOL> if r . method != "<STR_LIT>" and r . method != "<STR_LIT>" : <EOL> s3db . req_hide_quantities ( r . table ) <EOL> return True <EOL> s3 . prep = prep <EOL> def postp ( r , output ) : <EOL> if r . interactive : <EOL> s3 . actions = [ <EOL> dict ( url = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> _class = "<STR_LIT>" , <EOL> label = str ( READ ) <EOL> ) <EOL> ] <EOL> return output <EOL> s3 . postp = postp <EOL> return s3_rest_controller ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def summary_option ( ) : <EOL> """<STR_LIT>""" <EOL> return s3_rest_controller ( ) <EOL> def skills_filter ( req_id ) : <EOL> """<STR_LIT>""" <EOL> rstable = s3db . req_req_skill <EOL> rows = db ( rstable . req_id == req_id ) . select ( rstable . skill_id ) <EOL> filter_opts = [ ] <EOL> for r in rows : <EOL> multi_skill_id = r . skill_id <EOL> for skill_id in multi_skill_id : <EOL> filter_opts . append ( skill_id ) <EOL> if len ( filter_opts ) == <NUM_LIT:1> : <EOL> field = s3db . req_commit_skill . skill_id <EOL> field . default = skill_id <EOL> field . writable = False <EOL> return <EOL> s3db . req_commit_skill . skill_id . requires = IS_ONE_OF ( db , "<STR_LIT>" , <EOL> s3db . hrm_multi_skill_represent , <EOL> filterby = "<STR_LIT:id>" , <EOL> filter_opts = filter_opts , <EOL> sort = True , <EOL> multiple = True <EOL> ) <EOL> def commit ( ) : <EOL> """<STR_LIT>""" <EOL> if not is_affiliated ( ) : <EOL> tablename = "<STR_LIT>" <EOL> table = s3db [ tablename ] <EOL> table . person_id . writable = False <EOL> s3db . configure ( tablename , <EOL> insertable = False , <EOL> ) <EOL> if "<STR_LIT>" in request . args : <EOL> def skill_default_filter ( selector , tablename = None ) : <EOL> commit_id = request . args [ <NUM_LIT:0> ] <EOL> ctable = s3db . req_commit <EOL> rstable = s3db . req_req_skill <EOL> query = ( ctable . id == commit_id ) & ( ctable . req_id == rstable . req_id ) <EOL> multi_skills = db ( query ) . select ( rstable . skill_id , <EOL> ) <EOL> skills = [ ] <EOL> for row in multi_skills : <EOL> m = row . skill_id <EOL> for s in m : <EOL> skills . append ( s ) <EOL> return skills <EOL> s3base . s3_set_default_filter ( "<STR_LIT>" , <EOL> skill_default_filter , <EOL> tablename = "<STR_LIT>" ) <EOL> def prep ( r ) : <EOL> if r . interactive and r . record : <EOL> if r . component : <EOL> if r . component_name == "<STR_LIT>" : <EOL> s3db . req_commit_item . req_item_id . widget = None <EOL> s3db . req_commit_item . req_item_id . requires = IS_ONE_OF ( db , "<STR_LIT>" , <EOL> s3db . req_item_represent , <EOL> filterby = "<STR_LIT>" , <EOL> filter_opts = [ r . record . req_id ] , <EOL> orderby = "<STR_LIT>" , <EOL> sort = True , <EOL> ) <EOL> elif r . component_name == "<STR_LIT>" : <EOL> skills_filter ( r . record . req_id ) <EOL> else : <EOL> table = r . table <EOL> s3 . crud . submit_button = T ( "<STR_LIT>" ) <EOL> if r . record . type == <NUM_LIT:1> : <EOL> auth . permitted_facilities ( table = table , <EOL> error_msg = T ( "<STR_LIT>" ) ) <EOL> table . site_id . comment = A ( T ( "<STR_LIT>" ) , <EOL> _id = "<STR_LIT>" , <EOL> _target = "<STR_LIT>" , <EOL> _href = URL ( c = "<STR_LIT:default>" , <EOL> f = "<STR_LIT:user>" , <EOL> args = [ "<STR_LIT>" ] ) ) <EOL> jappend = s3 . jquery_ready . append <EOL> jappend ( '''<STR_LIT>''' ) <EOL> s3db . req_commit_item . req_item_id . widget = None <EOL> jappend ( '''<STR_LIT>''' ) <EOL> s3forms = s3base . s3forms <EOL> crud_form = s3forms . S3SQLCustomForm ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:date>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> s3forms . S3SQLInlineComponent ( <EOL> "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> fields = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> ) , <EOL> "<STR_LIT>" , <EOL> ) <EOL> s3db . configure ( "<STR_LIT>" , <EOL> crud_form = crud_form , <EOL> ) <EOL> elif r . record . type == <NUM_LIT:3> : <EOL> auth . permitted_facilities ( table = r . table , <EOL> error_msg = T ( "<STR_LIT>" ) ) <EOL> table . site_id . comment = A ( T ( "<STR_LIT>" ) , <EOL> _id = "<STR_LIT>" , <EOL> _target = "<STR_LIT>" , <EOL> _href = URL ( c = "<STR_LIT:default>" , <EOL> f = "<STR_LIT:user>" , <EOL> args = [ "<STR_LIT>" ] ) ) <EOL> skills_filter ( r . record . req_id ) <EOL> s3forms = s3base . s3forms <EOL> crud_form = s3forms . S3SQLCustomForm ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:date>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> s3forms . S3SQLInlineComponent ( <EOL> "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> fields = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> ) , <EOL> "<STR_LIT>" , <EOL> ) <EOL> s3db . configure ( "<STR_LIT>" , <EOL> crud_form = crud_form , <EOL> ) <EOL> else : <EOL> auth . permitted_organisations ( table = r . table , redirect_on_error = False ) <EOL> table . organisation_id . readable = True <EOL> table . organisation_id . writable = True <EOL> table . site_id . readable = False <EOL> table . site_id . writable = False <EOL> return True <EOL> s3 . prep = prep <EOL> def postp ( r , output ) : <EOL> if r . interactive and r . method != "<STR_LIT>" : <EOL> if not r . component : <EOL> req_types = settings . get_req_req_type ( ) <EOL> if "<STR_LIT>" in req_types : <EOL> s3_action_buttons ( r ) <EOL> if len ( req_types ) != <NUM_LIT:1> and ( get_vars . type != "<STR_LIT:1>" ) : <EOL> table = r . table <EOL> query = ( table . deleted == False ) & ( table . type == <NUM_LIT:1> ) <EOL> rows = db ( query ) . select ( table . id ) <EOL> restrict = [ str ( row . id ) for row in rows ] <EOL> else : <EOL> restrict = None <EOL> action = dict ( label = s3_unicode ( T ( "<STR_LIT>" ) ) . encode ( "<STR_LIT:utf8>" ) , <EOL> url = URL ( f = "<STR_LIT>" , <EOL> args = [ "<STR_LIT>" ] , <EOL> ) , <EOL> _class = "<STR_LIT>" , <EOL> ) <EOL> if restrict is not None : <EOL> action [ "<STR_LIT>" ] = restrict <EOL> s3 . actions . append ( action ) <EOL> confirm = T ( "<STR_LIT>" ) <EOL> s3 . jquery_ready . append ( '''<STR_LIT>''' % confirm ) <EOL> return output <EOL> s3 . postp = postp <EOL> return s3_rest_controller ( rheader = commit_rheader ) <EOL> def commit_rheader ( r ) : <EOL> """<STR_LIT>""" <EOL> if r . representation == "<STR_LIT:html>" : <EOL> record = r . record <EOL> if record and r . name == "<STR_LIT>" : <EOL> s3_date_represent = s3base . S3DateTime . date_represent <EOL> tabs = [ ( T ( "<STR_LIT>" ) , None ) ] <EOL> type = record . type and int ( record . type ) <EOL> table = r . table <EOL> if type == <NUM_LIT:1> : <EOL> tabs . append ( ( T ( "<STR_LIT>" ) , "<STR_LIT>" ) ) <EOL> rheader = DIV ( TABLE ( TR ( TH ( "<STR_LIT>" % table . req_id . label ) , <EOL> table . req_id . represent ( record . req_id ) , <EOL> ) , <EOL> TR ( TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , <EOL> s3db . org_site_represent ( record . site_id ) , <EOL> TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , <EOL> s3_date_represent ( record . date ) , <EOL> ) , <EOL> TR ( TH ( "<STR_LIT>" % table . comments . label ) , <EOL> TD ( record . comments or "<STR_LIT>" , _colspan = <NUM_LIT:3> ) <EOL> ) , <EOL> ) , <EOL> ) <EOL> prepare_btn = A ( T ( "<STR_LIT>" ) , <EOL> _href = URL ( f = "<STR_LIT>" , <EOL> args = [ record . id ] <EOL> ) , <EOL> _id = "<STR_LIT>" , <EOL> _class = "<STR_LIT>" <EOL> ) <EOL> s3 . rfooter = TAG [ "<STR_LIT>" ] ( prepare_btn ) <EOL> elif type == <NUM_LIT:3> : <EOL> if settings . get_req_commit_people ( ) : <EOL> tabs . append ( ( T ( "<STR_LIT>" ) , "<STR_LIT>" ) ) <EOL> if auth . s3_has_permission ( "<STR_LIT>" , "<STR_LIT>" ) and auth . s3_has_permission ( "<STR_LIT>" , "<STR_LIT>" , r . id ) : <EOL> tabs . append ( ( T ( "<STR_LIT>" ) , "<STR_LIT>" ) ) <EOL> else : <EOL> tabs . append ( ( T ( "<STR_LIT>" ) , "<STR_LIT>" ) ) <EOL> organisation_represent = s3db . org_organisation_represent <EOL> rheader = DIV ( TABLE ( TR ( TH ( "<STR_LIT>" % table . req_id . label ) , <EOL> table . req_id . represent ( record . req_id ) , <EOL> ) , <EOL> TR ( TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , <EOL> organisation_represent ( record . organisation_id ) , <EOL> TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , <EOL> s3_date_represent ( record . date ) , <EOL> ) , <EOL> TR ( TH ( "<STR_LIT>" % table . comments . label ) , <EOL> TD ( record . comments , _colspan = <NUM_LIT:3> ) <EOL> ) , <EOL> ) , <EOL> ) <EOL> else : <EOL> rheader = DIV ( TABLE ( TR ( TH ( "<STR_LIT>" % table . req_id . label ) , <EOL> table . req_id . represent ( record . req_id ) , <EOL> ) , <EOL> TR ( TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , <EOL> table . committer_id . represent ( record . committer_id ) , <EOL> TH ( "<STR_LIT>" % T ( "<STR_LIT>" ) ) , <EOL> s3_date_represent ( record . date ) , <EOL> ) , <EOL> TR ( TH ( "<STR_LIT>" % table . comments . label ) , <EOL> TD ( record . comments or "<STR_LIT>" , _colspan = <NUM_LIT:3> ) <EOL> ) , <EOL> ) , <EOL> ) <EOL> rheader_tabs = s3_rheader_tabs ( r , tabs ) <EOL> rheader . append ( rheader_tabs ) <EOL> return rheader <EOL> return None <EOL> def send ( ) : <EOL> """<STR_LIT>""" <EOL> s3db . configure ( "<STR_LIT>" , <EOL> listadd = False , <EOL> ) <EOL> return s3db . inv_send_controller ( ) <EOL> def send_commit ( ) : <EOL> """<STR_LIT>""" <EOL> return s3db . req_send_commit ( ) <EOL> def send_process ( ) : <EOL> """<STR_LIT>""" <EOL> return s3db . inv_send_process ( ) <EOL> def commit_item ( ) : <EOL> """<STR_LIT>""" <EOL> return s3_rest_controller ( ) <EOL> def commit_req ( ) : <EOL> """<STR_LIT>""" <EOL> req_id = request . args [ <NUM_LIT:0> ] <EOL> site_id = request . vars . get ( "<STR_LIT>" ) <EOL> table = s3db . req_req <EOL> r_req = db ( table . id == req_id ) . select ( table . type , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> ( prefix , resourcename , id ) = s3db . get_instance ( s3db . org_site , site_id ) <EOL> if not site_id or not auth . s3_has_permission ( "<STR_LIT>" , <EOL> "<STR_LIT>" % ( prefix , <EOL> resourcename ) , <EOL> record_id = id ) : <EOL> session . error = T ( "<STR_LIT>" ) <EOL> redirect ( URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ req_id ] ) ) <EOL> commit_id = s3db . req_commit . insert ( date = request . utcnow , <EOL> req_id = req_id , <EOL> site_id = site_id , <EOL> type = r_req . type <EOL> ) <EOL> ritable = s3db . req_req_item <EOL> iitable = s3db . inv_inv_item <EOL> query = ( ritable . req_id == req_id ) & ( ritable . quantity_fulfil < ritable . quantity ) & ( iitable . site_id == site_id ) & ( ritable . item_id == iitable . item_id ) & ( ritable . deleted == False ) & ( iitable . deleted == False ) <EOL> req_items = db ( query ) . select ( ritable . id , <EOL> ritable . quantity , <EOL> ritable . item_pack_id , <EOL> iitable . item_id , <EOL> iitable . quantity , <EOL> iitable . item_pack_id ) <EOL> citable = s3db . req_commit_item <EOL> for req_item in req_items : <EOL> req_pack_quantity = req_item . req_req_item . pack_quantity ( ) <EOL> req_item_quantity = req_item . req_req_item . quantity * req_pack_quantity <EOL> inv_item_quantity = req_item . inv_inv_item . quantity * req_item . inv_inv_item . pack_quantity ( ) <EOL> if inv_item_quantity > req_item_quantity : <EOL> commit_item_quantity = req_item_quantity <EOL> else : <EOL> commit_item_quantity = inv_item_quantity <EOL> commit_item_quantity = commit_item_quantity / req_pack_quantity <EOL> if commit_item_quantity : <EOL> req_item_id = req_item . req_req_item . id <EOL> commit_item_id = citable . insert ( commit_id = commit_id , <EOL> req_item_id = req_item_id , <EOL> item_pack_id = req_item . req_req_item . item_pack_id , <EOL> quantity = commit_item_quantity <EOL> ) <EOL> s3base . s3_store_last_record_id ( "<STR_LIT>" , commit_item_id ) <EOL> form = Storage ( ) <EOL> form . vars = Storage ( <EOL> req_item_id = req_item_id <EOL> ) <EOL> s3db . req_commit_item_onaccept ( form ) <EOL> redirect ( URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ commit_id , "<STR_LIT>" ] ) ) <EOL> def send_req ( ) : <EOL> """<STR_LIT>""" <EOL> req_id = request . args [ <NUM_LIT:0> ] <EOL> site_id = request . vars . get ( "<STR_LIT>" , None ) <EOL> table = s3db . req_req <EOL> r_req = db ( table . id == req_id ) . select ( table . req_ref , <EOL> table . requester_id , <EOL> table . site_id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> ( prefix , resourcename , id ) = s3db . get_instance ( db . org_site , site_id ) <EOL> if not site_id or not auth . s3_has_permission ( "<STR_LIT>" , <EOL> "<STR_LIT>" % ( prefix , <EOL> resourcename ) , <EOL> record_id = id ) : <EOL> session . error = T ( "<STR_LIT>" ) <EOL> redirect ( URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ req_id ] ) ) <EOL> ritable = s3db . req_req_item <EOL> iitable = s3db . inv_inv_item <EOL> sendtable = s3db . inv_send <EOL> tracktable = s3db . inv_track_item <EOL> siptable = s3db . supply_item_pack <EOL> sip_id_field = siptable . id <EOL> sip_quantity_field = siptable . quantity <EOL> query = ( ritable . req_id == req_id ) & ( ritable . quantity_transit < ritable . quantity ) & ( ritable . deleted == False ) & ( ritable . item_pack_id == sip_id_field ) <EOL> req_items = db ( query ) . select ( ritable . id , <EOL> ritable . quantity , <EOL> ritable . quantity_transit , <EOL> ritable . quantity_fulfil , <EOL> ritable . item_id , <EOL> sip_quantity_field <EOL> ) <EOL> if not req_items : <EOL> session . warning = T ( "<STR_LIT>" ) <EOL> redirect ( URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ req_id , "<STR_LIT>" ] ) <EOL> ) <EOL> code = s3db . supply_get_shipping_code ( "<STR_LIT>" , <EOL> site_id , <EOL> s3db . inv_send . send_ref <EOL> ) <EOL> send_id = sendtable . insert ( send_ref = code , <EOL> req_ref = r_req . req_ref , <EOL> sender_id = auth . s3_logged_in_person ( ) , <EOL> site_id = site_id , <EOL> date = request . utcnow , <EOL> recipient_id = r_req . requester_id , <EOL> to_site_id = r_req . site_id , <EOL> status = s3db . inv_ship_status [ "<STR_LIT>" ] , <EOL> ) <EOL> IN_PROCESS = s3db . inv_tracking_status [ "<STR_LIT>" ] <EOL> insert = tracktable . insert <EOL> inv_remove = s3db . inv_remove <EOL> ii_item_id_field = iitable . item_id <EOL> ii_quantity_field = iitable . quantity <EOL> ii_expiry_field = iitable . expiry_date <EOL> ii_purchase_field = iitable . purchase_date <EOL> iifields = [ iitable . id , <EOL> ii_item_id_field , <EOL> ii_quantity_field , <EOL> iitable . item_pack_id , <EOL> iitable . pack_value , <EOL> iitable . currency , <EOL> ii_expiry_field , <EOL> ii_purchase_field , <EOL> iitable . bin , <EOL> iitable . owner_org_id , <EOL> iitable . supply_org_id , <EOL> sip_quantity_field , <EOL> iitable . item_source_no , <EOL> ] <EOL> bquery = ( ii_quantity_field > <NUM_LIT:0> ) & ( iitable . site_id == site_id ) & ( iitable . deleted == False ) & ( iitable . item_pack_id == sip_id_field ) & ( ( iitable . expiry_date >= request . now ) | ( ( iitable . expiry_date == None ) ) ) & ( iitable . status == <NUM_LIT:0> ) <EOL> orderby = ii_expiry_field | ii_purchase_field <EOL> no_match = True <EOL> for ritem in req_items : <EOL> rim = ritem . req_req_item <EOL> rim_id = rim . id <EOL> query = bquery & ( ii_item_id_field == rim . item_id ) <EOL> inv_items = db ( query ) . select ( * iifields , <EOL> orderby = orderby ) <EOL> if len ( inv_items ) == <NUM_LIT:0> : <EOL> continue <EOL> no_match = False <EOL> one_match = len ( inv_items ) == <NUM_LIT:1> <EOL> quantity_shipped = max ( rim . quantity_transit , rim . quantity_fulfil ) <EOL> quantity_needed = ( rim . quantity - quantity_shipped ) * ritem . supply_item_pack . quantity <EOL> iids = [ ] <EOL> append = iids . append <EOL> for item in inv_items : <EOL> if not quantity_needed : <EOL> break <EOL> iitem = item . inv_inv_item <EOL> if one_match : <EOL> send_item_quantity = inv_remove ( iitem , quantity_needed ) <EOL> quantity_needed -= send_item_quantity <EOL> append ( iitem . id ) <EOL> else : <EOL> quantity_available = iitem . quantity * item . supply_item_pack . quantity <EOL> if iitem . expiry_date : <EOL> send_item_quantity = min ( quantity_needed , quantity_available ) <EOL> send_item_quantity = inv_remove ( iitem , send_item_quantity ) <EOL> quantity_needed -= send_item_quantity <EOL> append ( iitem . id ) <EOL> elif iitem . purchase_date : <EOL> send_item_quantity = min ( quantity_needed , quantity_available ) <EOL> send_item_quantity = inv_remove ( iitem , send_item_quantity ) <EOL> quantity_needed -= send_item_quantity <EOL> append ( iitem . id ) <EOL> elif quantity_needed <= quantity_available : <EOL> send_item_quantity = inv_remove ( iitem , quantity_needed ) <EOL> quantity_needed = <NUM_LIT:0> <EOL> append ( iitem . id ) <EOL> else : <EOL> continue <EOL> insert ( send_id = send_id , <EOL> send_inv_item_id = iitem . id , <EOL> item_id = iitem . item_id , <EOL> req_item_id = rim_id , <EOL> item_pack_id = iitem . item_pack_id , <EOL> quantity = send_item_quantity , <EOL> recv_quantity = send_item_quantity , <EOL> status = IN_PROCESS , <EOL> pack_value = iitem . pack_value , <EOL> currency = iitem . currency , <EOL> bin = iitem . bin , <EOL> expiry_date = iitem . expiry_date , <EOL> owner_org_id = iitem . owner_org_id , <EOL> supply_org_id = iitem . supply_org_id , <EOL> item_source_no = iitem . item_source_no , <EOL> ) <EOL> for item in inv_items : <EOL> if not quantity_needed : <EOL> break <EOL> iitem = item . inv_inv_item <EOL> if iitem . id in iids : <EOL> continue <EOL> send_item_quantity = <NUM_LIT:0> <EOL> insert ( send_id = send_id , <EOL> send_inv_item_id = iitem . id , <EOL> item_id = iitem . item_id , <EOL> req_item_id = rim_id , <EOL> item_pack_id = iitem . item_pack_id , <EOL> quantity = send_item_quantity , <EOL> status = IN_PROCESS , <EOL> pack_value = iitem . pack_value , <EOL> currency = iitem . currency , <EOL> bin = iitem . bin , <EOL> expiry_date = iitem . expiry_date , <EOL> owner_org_id = iitem . owner_org_id , <EOL> supply_org_id = iitem . supply_org_id , <EOL> item_source_no = iitem . item_source_no , <EOL> ) <EOL> if no_match : <EOL> session . warning = T ( "<STR_LIT>" ) <EOL> redirect ( URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ send_id , "<STR_LIT>" ] ) <EOL> ) <EOL> def commit_item_json ( ) : <EOL> """<STR_LIT>""" <EOL> ctable = s3db . req_commit <EOL> itable = s3db . req_commit_item <EOL> stable = s3db . org_site <EOL> query = ( itable . req_item_id == request . args [ <NUM_LIT:0> ] ) & ( ctable . id == itable . commit_id ) & ( ctable . site_id == stable . id ) & ( itable . deleted == False ) <EOL> records = db ( query ) . select ( ctable . id , <EOL> ctable . date , <EOL> stable . name , <EOL> itable . quantity , <EOL> orderby = db . req_commit . date ) <EOL> json_str = '''<STR_LIT>''' % ( json . dumps ( dict ( id = str ( T ( "<STR_LIT>" ) ) , <EOL> quantity = "<STR_LIT:#>" ) ) , <EOL> records . json ( ) [ <NUM_LIT:1> : ] ) <EOL> response . headers [ "<STR_LIT:Content-Type>" ] = "<STR_LIT:application/json>" <EOL> return json_str <EOL> def fema ( ) : <EOL> """<STR_LIT>""" <EOL> ritable = s3db . req_req_item <EOL> rtable = db . req_req <EOL> itable = db . supply_item <EOL> ictable = db . supply_item_category <EOL> citable = db . supply_catalog_item <EOL> query = ( ictable . name == "<STR_LIT>" ) & ( citable . item_category_id == ictable . id ) & ( citable . item_id == itable . id ) & ( itable . deleted != True ) <EOL> fema_items = db ( query ) . select ( itable . id ) <EOL> fema_item_ids = [ item . id for item in fema_items ] <EOL> REQ_STATUS_COMPLETE = <NUM_LIT:2> <EOL> s3 . filter = ( rtable . deleted != True ) & ( rtable . is_template == False ) & ( rtable . commit_status != REQ_STATUS_COMPLETE ) & ( rtable . transit_status != REQ_STATUS_COMPLETE ) & ( rtable . fulfil_status != REQ_STATUS_COMPLETE ) & ( ritable . req_id == rtable . id ) & ( ritable . quantity > ritable . quantity_commit ) & ( ritable . quantity > ritable . quantity_transit ) & ( ritable . quantity > ritable . quantity_fulfil ) & ( ritable . deleted != True ) & ( ritable . item_id . belongs ( fema_item_ids ) ) <EOL> filter_widgets = [ <EOL> s3base . S3OptionsFilter ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> ] <EOL> s3db . configure ( "<STR_LIT>" , filter_widgets = filter_widgets ) <EOL> return req_item ( ) <EOL> def organisation_needs ( ) : <EOL> """<STR_LIT>""" <EOL> def prep ( r ) : <EOL> if r . interactive : <EOL> if r . method == "<STR_LIT>" : <EOL> organisation_id = get_vars . get ( "<STR_LIT>" , None ) <EOL> if organisation_id : <EOL> field = s3db . req_organisation_needs . organisation_id <EOL> field . default = organisation_id <EOL> field . readable = False <EOL> field . writable = False <EOL> elif r . method == "<STR_LIT>" : <EOL> field = s3db . req_organisation_needs . organisation_id <EOL> field . writable = False <EOL> field . comment = None <EOL> return True <EOL> s3 . prep = prep <EOL> return s3_rest_controller ( ) <EOL> def organisation_needs_skill ( ) : <EOL> """<STR_LIT>""" <EOL> s3 . prep = lambda r : r . method == "<STR_LIT>" and r . representation == "<STR_LIT>" <EOL> return s3_rest_controller ( ) <EOL> def organisation_needs_item ( ) : <EOL> """<STR_LIT>""" <EOL> s3 . prep = lambda r : r . method == "<STR_LIT>" and r . representation == "<STR_LIT>" <EOL> return s3_rest_controller ( ) <EOL> def site_needs ( ) : <EOL> """<STR_LIT>""" <EOL> def prep ( r ) : <EOL> if r . interactive and r . method == "<STR_LIT>" : <EOL> site_id = get_vars . get ( "<STR_LIT>" , None ) <EOL> if site_id : <EOL> field = s3db . req_site_needs . site_id <EOL> field . default = site_id <EOL> field . readable = False <EOL> field . writable = False <EOL> return True <EOL> s3 . prep = prep <EOL> return s3_rest_controller ( ) <EOL> def facility ( ) : <EOL> s3db . configure ( "<STR_LIT>" , <EOL> create_next = URL ( c = "<STR_LIT>" , f = "<STR_LIT>" , <EOL> args = [ "<STR_LIT>" , "<STR_LIT>" ] ) , <EOL> ) <EOL> return s3db . org_facility_controller ( ) </s>
