<s> """<STR_LIT>""" <EOL> from reportlab . lib . validators import Percentage <EOL> __all__ = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> from gluon import * <EOL> from gluon . storage import Storage <EOL> from . . s3 import * <EOL> from s3dal import Row <EOL> from s3layouts import S3PopupLink <EOL> class S3BudgetModel ( S3Model ) : <EOL> names = ( "<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> def model ( self ) : <EOL> T = current . T <EOL> db = current . db <EOL> configure = self . configure <EOL> define_table = self . define_table <EOL> super_link = self . super_link <EOL> messages = current . messages <EOL> UNKNOWN_OPT = messages . UNKNOWN_OPT <EOL> s3 = current . response . s3 <EOL> crud_strings = s3 . crud_strings <EOL> entity_types = Storage ( <EOL> project_project = T ( "<STR_LIT>" ) , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> self . super_entity ( tablename , "<STR_LIT>" , entity_types ) <EOL> self . add_components ( tablename , <EOL> budget_budget = "<STR_LIT>" , <EOL> budget_allocation = "<STR_LIT>" , <EOL> budget_monitoring = "<STR_LIT>" , <EOL> budget_staff = { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:key>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } , <EOL> budget_bundle = { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:key>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } , <EOL> ) <EOL> status_opts = { <NUM_LIT:1> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT:2> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT:3> : T ( "<STR_LIT>" ) , <EOL> } <EOL> monitoring_opts = { <NUM_LIT:1> : messages [ "<STR_LIT>" ] , <EOL> <NUM_LIT:3> : T ( "<STR_LIT>" ) , <EOL> } <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> Field ( "<STR_LIT:name>" , length = <NUM_LIT> , notnull = True , unique = True , <EOL> label = T ( "<STR_LIT:Name>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT:description>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:0.0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> writable = False , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:0.0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> writable = False , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:0.0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> s3_currency ( required = True ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:1> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = lambda opt : monitoring_opts . get ( opt , UNKNOWN_OPT ) , <EOL> requires = IS_IN_SET ( monitoring_opts ) , <EOL> ) , <EOL> Field ( "<STR_LIT:status>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:1> , <EOL> represent = lambda opt : status_opts . get ( opt , UNKNOWN_OPT ) , <EOL> requires = IS_IN_SET ( status_opts ) , <EOL> ) , <EOL> s3_comments ( ) , <EOL> * s3_meta_fields ( ) <EOL> ) <EOL> crud_strings [ tablename ] = 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> ) <EOL> configure ( tablename , <EOL> onaccept = self . budget_budget_onaccept , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_FLOAT_IN_RANGE ( <NUM_LIT:0> , <NUM_LIT:100> ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT:0.0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_FLOAT_IN_RANGE ( <NUM_LIT:0> , <NUM_LIT:100> ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT:0.0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_FLOAT_IN_RANGE ( <NUM_LIT:0> , <NUM_LIT:100> ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_FLOAT_IN_RANGE ( <NUM_LIT:0> , <NUM_LIT:100> ) , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> crud_strings [ tablename ] = Storage ( <EOL> title_update = T ( "<STR_LIT>" ) , <EOL> title_display = T ( "<STR_LIT>" ) <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> Field ( "<STR_LIT:code>" , length = <NUM_LIT:3> , notnull = True , unique = True , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT:description>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:0.0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:0.0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> s3_comments ( ) , <EOL> * s3_meta_fields ( ) ) <EOL> ADD_LOCATION = T ( "<STR_LIT>" ) <EOL> crud_strings [ tablename ] = Storage ( <EOL> label_create = ADD_LOCATION , <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> ) <EOL> budget_location_represent = S3Represent ( lookup = tablename , <EOL> fields = [ "<STR_LIT:code>" ] ) <EOL> budget_location_id = S3ReusableField ( "<STR_LIT>" , "<STR_LIT>" % tablename , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ondelete = "<STR_LIT>" , <EOL> represent = budget_location_represent , <EOL> requires = IS_ONE_OF ( db , "<STR_LIT>" , <EOL> budget_location_represent , <EOL> ) , <EOL> comment = S3PopupLink ( <EOL> c = "<STR_LIT>" , <EOL> f = "<STR_LIT:location>" , <EOL> label = ADD_LOCATION , <EOL> title = T ( "<STR_LIT>" ) , <EOL> tooltip = T ( "<STR_LIT>" ) % ADD_LOCATION <EOL> ) , <EOL> ) <EOL> configure ( tablename , <EOL> update_onaccept = self . budget_location_onaccept , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> Field ( "<STR_LIT:name>" , length = <NUM_LIT> , notnull = True , unique = True , <EOL> label = T ( "<STR_LIT:Name>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , notnull = True , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> s3_currency ( ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> s3_comments ( ) , <EOL> * s3_meta_fields ( ) ) <EOL> ADD_STAFF_TYPE = T ( "<STR_LIT>" ) <EOL> crud_strings [ tablename ] = Storage ( <EOL> label_create = ADD_STAFF_TYPE , <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> ) <EOL> budget_staff_represent = S3Represent ( lookup = tablename , <EOL> fields = [ "<STR_LIT:name>" ] ) <EOL> budget_staff_id = S3ReusableField ( "<STR_LIT>" , "<STR_LIT>" % tablename , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ondelete = "<STR_LIT>" , <EOL> represent = budget_staff_represent , <EOL> requires = IS_ONE_OF ( db , "<STR_LIT>" , <EOL> budget_staff_represent , <EOL> ) , <EOL> comment = S3PopupLink ( <EOL> c = "<STR_LIT>" , <EOL> f = "<STR_LIT>" , <EOL> label = ADD_STAFF_TYPE , <EOL> title = T ( "<STR_LIT>" ) , <EOL> tooltip = T ( "<STR_LIT>" ) % ADD_STAFF_TYPE <EOL> ) , <EOL> ) <EOL> configure ( tablename , <EOL> update_onaccept = self . budget_staff_onaccept , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> budget_location_id ( ) , <EOL> budget_staff_id ( ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT:1> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT:3> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> configure ( tablename , <EOL> onaccept = self . budget_budget_staff_onaccept , <EOL> ondelete = self . budget_budget_staff_ondelete , <EOL> ) <EOL> return dict ( <EOL> budget_location_id = budget_location_id , <EOL> budget_staff_id = budget_staff_id , <EOL> ) <EOL> def defaults ( self ) : <EOL> """<STR_LIT>""" <EOL> dummy = S3ReusableField ( "<STR_LIT>" , "<STR_LIT>" , <EOL> readable = False , <EOL> writable = False ) <EOL> return dict ( budget_budget_id = lambda ** attr : dummy ( "<STR_LIT>" ) , <EOL> budget_location_id = lambda ** attr : dummy ( "<STR_LIT>" ) , <EOL> budget_staff_id = lambda ** attr : dummy ( "<STR_LIT>" ) , <EOL> ) <EOL> @ staticmethod <EOL> def budget_budget_onaccept ( form ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> budget_entity_id = form . vars . budget_entity_id <EOL> except : <EOL> return <EOL> budget_budget_totals ( budget_entity_id ) <EOL> return <EOL> @ staticmethod <EOL> def budget_staff_onaccept ( form ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> record_id = form . vars . id <EOL> except : <EOL> return <EOL> linktable = current . s3db . budget_budget_staff <EOL> budget_entity_id = linktable . budget_entity_id <EOL> query = ( linktable . staff_id == record_id ) <EOL> rows = current . db ( query ) . select ( budget_entity_id , <EOL> groupby = budget_entity_id ) <EOL> for row in rows : <EOL> budget_budget_totals ( row . budget_entity_id ) <EOL> return <EOL> @ staticmethod <EOL> def budget_location_onaccept ( form ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> record_id = form . vars . id <EOL> except : <EOL> return <EOL> linktable = current . s3db . budget_budget_staff <EOL> budget_entity_id = linktable . budget_entity_id <EOL> query = ( linktable . location_id == record_id ) <EOL> rows = current . db ( query ) . select ( budget_entity_id , <EOL> groupby = budget_entity_id ) <EOL> for row in rows : <EOL> budget_budget_totals ( row . budget_entity_id ) <EOL> return <EOL> @ staticmethod <EOL> def budget_budget_staff_onaccept ( form ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> record_id = form . vars . id <EOL> except : <EOL> return <EOL> table = current . s3db . budget_budget_staff <EOL> row = current . db ( table . id == record_id ) . select ( table . budget_entity_id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if row : <EOL> budget_budget_totals ( row . budget_entity_id ) <EOL> return <EOL> @ staticmethod <EOL> def budget_budget_staff_ondelete ( row ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> linktable = current . s3db . budget_budget_staff <EOL> try : <EOL> record_id = row . id <EOL> except : <EOL> return <EOL> link = db ( linktable . id == record_id ) . select ( linktable . deleted_fk , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if link : <EOL> deleted_fk = json . loads ( link . deleted_fk ) <EOL> budget_entity_id = deleted_fk . get ( "<STR_LIT>" ) <EOL> if budget_entity_id : <EOL> budget_budget_totals ( budget_entity_id ) <EOL> return <EOL> class S3BudgetKitModel ( S3Model ) : <EOL> names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> T = current . T <EOL> configure = self . configure <EOL> define_table = self . define_table <EOL> add_components = self . add_components <EOL> s3 = current . response . s3 <EOL> crud_strings = s3 . crud_strings <EOL> UNKNOWN_OPT = current . messages . UNKNOWN_OPT <EOL> db = current . db <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> Field ( "<STR_LIT:code>" , length = <NUM_LIT> , notnull = True , unique = True , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT:description>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:0.0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> writable = False , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:0.0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> writable = False , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:0.0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> writable = False , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:0.0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> writable = False , <EOL> ) , <EOL> s3_comments ( ) , <EOL> * s3_meta_fields ( ) ) <EOL> ADD_KIT = T ( "<STR_LIT>" ) <EOL> crud_strings [ tablename ] = Storage ( <EOL> label_create = ADD_KIT , <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> ) <EOL> budget_kit_represent = S3Represent ( lookup = tablename , fields = [ "<STR_LIT:code>" ] ) <EOL> budget_kit_id = S3ReusableField ( "<STR_LIT>" , "<STR_LIT>" % tablename , <EOL> ondelete = "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = budget_kit_represent , <EOL> requires = IS_ONE_OF ( db , "<STR_LIT>" , <EOL> budget_kit_represent , <EOL> ) , <EOL> comment = S3PopupLink ( <EOL> c = "<STR_LIT>" , <EOL> f = "<STR_LIT>" , <EOL> label = ADD_KIT , <EOL> title = T ( "<STR_LIT>" ) , <EOL> tooltip = T ( "<STR_LIT>" ) % ADD_KIT <EOL> ) , <EOL> ) <EOL> configure ( tablename , <EOL> onaccept = self . budget_kit_onaccept , <EOL> ) <EOL> add_components ( tablename , <EOL> budget_item = { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:key>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } , <EOL> ) <EOL> budget_cost_type_opts = { <NUM_LIT:1> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT:2> : T ( "<STR_LIT>" ) , <EOL> } <EOL> budget_category_type_opts = { <NUM_LIT:1> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT:2> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT:3> : "<STR_LIT>" , <EOL> <NUM_LIT:4> : "<STR_LIT>" , <EOL> <NUM_LIT:5> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT:6> : "<STR_LIT>" , <EOL> <NUM_LIT:7> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT:8> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT:9> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT:10> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT:11> : "<STR_LIT>" , <EOL> <NUM_LIT:12> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT:15> : "<STR_LIT>" , <EOL> <NUM_LIT:16> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT> : T ( "<STR_LIT>" ) , <EOL> <NUM_LIT> : T ( "<STR_LIT>" ) , <EOL> } <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = lambda opt : budget_category_type_opts . get ( opt , UNKNOWN_OPT ) , <EOL> requires = IS_IN_SET ( budget_category_type_opts , zero = None ) , <EOL> ) , <EOL> Field ( "<STR_LIT:code>" , length = <NUM_LIT> , notnull = True , unique = True , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT:description>" , notnull = True , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = lambda opt : budget_cost_type_opts . get ( opt , UNKNOWN_OPT ) , <EOL> requires = IS_IN_SET ( budget_cost_type_opts , <EOL> zero = None ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> s3_comments ( ) , <EOL> * s3_meta_fields ( ) ) <EOL> ADD_ITEM = T ( "<STR_LIT>" ) <EOL> crud_strings [ tablename ] = Storage ( <EOL> label_create = ADD_ITEM , <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> label_search_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> ) <EOL> budget_item_represent = S3Represent ( lookup = tablename , <EOL> fields = [ "<STR_LIT:description>" ] ) <EOL> budget_item_id = S3ReusableField ( "<STR_LIT>" , "<STR_LIT>" % tablename , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ondelete = "<STR_LIT>" , <EOL> represent = budget_item_represent , <EOL> requires = IS_ONE_OF ( db , "<STR_LIT>" , <EOL> budget_item_represent , <EOL> ) , <EOL> comment = S3PopupLink ( <EOL> c = "<STR_LIT>" , <EOL> f = "<STR_LIT>" , <EOL> label = ADD_ITEM , <EOL> title = T ( "<STR_LIT>" ) , <EOL> tooltip = T ( "<STR_LIT>" ) % ADD_ITEM <EOL> ) , <EOL> ) <EOL> configure ( tablename , <EOL> main = "<STR_LIT:code>" , <EOL> extra = "<STR_LIT:description>" , <EOL> onaccept = self . budget_item_onaccept , <EOL> orderby = "<STR_LIT>" , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> budget_kit_id ( ) , <EOL> budget_item_id ( ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT:1> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> configure ( tablename , <EOL> onaccept = self . budget_kit_item_onaccept , <EOL> ondelete = self . budget_kit_item_ondelete , <EOL> ) <EOL> return dict ( budget_kit_id = budget_kit_id , <EOL> budget_item_id = budget_item_id , <EOL> ) <EOL> def defaults ( self ) : <EOL> """<STR_LIT>""" <EOL> dummy = S3ReusableField ( "<STR_LIT>" , "<STR_LIT>" , <EOL> readable = False , <EOL> writable = False ) <EOL> return dict ( budget_kit_id = lambda ** attr : dummy ( "<STR_LIT>" ) , <EOL> budget_item_id = lambda ** attr : dummy ( "<STR_LIT>" ) , <EOL> ) <EOL> @ staticmethod <EOL> def budget_kit_onaccept ( form ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> kit_id = form . vars . id <EOL> except : <EOL> return <EOL> budget_kit_totals ( kit_id ) <EOL> return <EOL> @ staticmethod <EOL> def budget_item_onaccept ( form ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> s3db = current . s3db <EOL> try : <EOL> item_id = form . vars . id <EOL> except : <EOL> return <EOL> linktable = s3db . budget_kit_item <EOL> kit_id = linktable . kit_id <EOL> rows = db ( linktable . item_id == item_id ) . select ( kit_id , <EOL> groupby = kit_id ) <EOL> kit_ids = set ( ) <EOL> for row in rows : <EOL> kit_id = row . kit_id <EOL> budget_kit_totals ( kit_id ) <EOL> kit_ids . add ( kit_id ) <EOL> if kit_ids : <EOL> linktable = s3db . budget_bundle_kit <EOL> bundle_id = linktable . bundle_id <EOL> rows = db ( linktable . kit_id . belongs ( kit_ids ) ) . select ( bundle_id , <EOL> groupby = bundle_id ) <EOL> already_updated = [ row . bundle_id for row in rows ] <EOL> else : <EOL> already_updated = None <EOL> linktable = s3db . budget_bundle_item <EOL> bundle_id = linktable . bundle_id <EOL> query = ( linktable . item_id == item_id ) <EOL> if already_updated : <EOL> query &= ~ ( linktable . bundle_id . belongs ( already_updated ) ) <EOL> rows = db ( query ) . select ( bundle_id , groupby = bundle_id ) <EOL> for row in rows : <EOL> budget_bundle_totals ( kit_id ) <EOL> return <EOL> @ staticmethod <EOL> def budget_kit_item_onaccept ( form ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> record_id = form . vars . id <EOL> except : <EOL> return <EOL> table = current . s3db . budget_kit_item <EOL> row = current . db ( table . id == record_id ) . select ( table . kit_id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if row : <EOL> budget_kit_totals ( row . kit_id ) <EOL> return <EOL> @ staticmethod <EOL> def budget_kit_item_ondelete ( row ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> linktable = current . s3db . budget_kit_item <EOL> try : <EOL> record_id = row . id <EOL> except : <EOL> return <EOL> link = db ( linktable . id == record_id ) . select ( linktable . deleted_fk , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if link : <EOL> deleted_fk = json . loads ( link . deleted_fk ) <EOL> kit_id = deleted_fk . get ( "<STR_LIT>" ) <EOL> if kit_id : <EOL> budget_kit_totals ( kit_id ) <EOL> return <EOL> class S3BudgetBundleModel ( S3Model ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> T = current . T <EOL> configure = self . configure <EOL> define_table = self . define_table <EOL> add_components = self . add_components <EOL> s3 = current . response . s3 <EOL> crud_strings = s3 . crud_strings <EOL> db = current . db <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> Field ( "<STR_LIT:name>" , length = <NUM_LIT> , notnull = True , unique = True , <EOL> label = T ( "<STR_LIT:Name>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT:description>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:0.0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> writable = False , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT:0.0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> writable = False , <EOL> ) , <EOL> s3_comments ( ) , <EOL> * s3_meta_fields ( ) ) <EOL> ADD_BUNDLE = T ( "<STR_LIT>" ) <EOL> crud_strings [ tablename ] = Storage ( <EOL> label_create = ADD_BUNDLE , <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> ) <EOL> configure ( tablename , <EOL> onaccept = self . budget_bundle_onaccept , <EOL> ) <EOL> add_components ( tablename , <EOL> budget_item = { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:key>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } , <EOL> budget_kit = { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:key>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } , <EOL> ) <EOL> budget_bundle_represent = S3Represent ( lookup = tablename , <EOL> fields = [ "<STR_LIT:name>" ] ) <EOL> budget_bundle_id = S3ReusableField ( "<STR_LIT>" , "<STR_LIT>" % tablename , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ondelete = "<STR_LIT>" , <EOL> represent = budget_bundle_represent , <EOL> requires = IS_ONE_OF ( db , "<STR_LIT>" , <EOL> budget_bundle_represent , <EOL> ) , <EOL> comment = S3PopupLink ( <EOL> c = "<STR_LIT>" , <EOL> f = "<STR_LIT>" , <EOL> label = ADD_BUNDLE , <EOL> title = T ( "<STR_LIT>" ) , <EOL> tooltip = T ( "<STR_LIT>" ) % ADD_BUNDLE <EOL> ) , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> budget_bundle_id ( ) , <EOL> self . budget_kit_id ( ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT:1> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT:0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT:0> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> crud_strings [ tablename ] = 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> ) <EOL> configure ( tablename , <EOL> onaccept = self . budget_bundle_kit_onaccept , <EOL> ondelete = self . budget_bundle_kit_ondelete , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> budget_bundle_id ( ) , <EOL> self . budget_item_id ( ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT:1> , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT:0> , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT:0> , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> crud_strings [ tablename ] = 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> ) <EOL> configure ( tablename , <EOL> onaccept = self . budget_bundle_item_onaccept , <EOL> ondelete = self . budget_bundle_item_ondelete , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> define_table ( tablename , <EOL> self . super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> self . budget_location_id ( ) , <EOL> budget_bundle_id ( ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT:1> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT:3> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> requires = IS_NOT_EMPTY ( ) , <EOL> ) , <EOL> * s3_meta_fields ( ) ) <EOL> crud_strings [ tablename ] = 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> ) <EOL> configure ( tablename , <EOL> onaccept = self . budget_budget_bundle_onaccept , <EOL> ondelete = self . budget_budget_bundle_ondelete , <EOL> ) <EOL> return dict ( budget_bundle_id = budget_bundle_id , <EOL> ) <EOL> def defaults ( self ) : <EOL> """<STR_LIT>""" <EOL> dummy = S3ReusableField ( "<STR_LIT>" , "<STR_LIT>" , <EOL> readable = False , <EOL> writable = False ) <EOL> return dict ( budget_bundle_id = lambda ** attr : dummy ( "<STR_LIT>" ) , <EOL> ) <EOL> @ staticmethod <EOL> def budget_bundle_onaccept ( form ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> bundle_id = form . vars . id <EOL> except : <EOL> return <EOL> budget_bundle_totals ( bundle_id ) <EOL> return <EOL> @ staticmethod <EOL> def budget_bundle_item_onaccept ( form ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> record_id = form . vars . id <EOL> except : <EOL> return <EOL> table = current . s3db . budget_bundle_item <EOL> row = current . db ( table . id == record_id ) . select ( table . bundle_id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if row : <EOL> budget_bundle_totals ( row . bundle_id ) <EOL> return <EOL> @ staticmethod <EOL> def budget_bundle_item_ondelete ( row ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> linktable = current . s3db . budget_bundle_item <EOL> try : <EOL> record_id = row . id <EOL> except : <EOL> return <EOL> link = db ( linktable . id == record_id ) . select ( linktable . deleted_fk , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if link : <EOL> deleted_fk = json . loads ( link . deleted_fk ) <EOL> bundle_id = deleted_fk . get ( "<STR_LIT>" ) <EOL> if bundle_id : <EOL> budget_bundle_totals ( bundle_id ) <EOL> return <EOL> @ staticmethod <EOL> def budget_bundle_kit_onaccept ( form ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> record_id = form . vars . id <EOL> except : <EOL> return <EOL> table = current . s3db . budget_bundle_kit <EOL> row = current . db ( table . id == record_id ) . select ( table . bundle_id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if row : <EOL> budget_bundle_totals ( row . bundle_id ) <EOL> return <EOL> @ staticmethod <EOL> def budget_bundle_kit_ondelete ( row ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> linktable = current . s3db . budget_bundle_kit <EOL> try : <EOL> record_id = row . id <EOL> except : <EOL> return <EOL> link = db ( linktable . id == record_id ) . select ( linktable . deleted_fk , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if link : <EOL> deleted_fk = json . loads ( link . deleted_fk ) <EOL> bundle_id = deleted_fk . get ( "<STR_LIT>" ) <EOL> if bundle_id : <EOL> budget_bundle_totals ( bundle_id ) <EOL> return <EOL> @ staticmethod <EOL> def budget_budget_bundle_onaccept ( form ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> record_id = form . vars . id <EOL> except : <EOL> return <EOL> table = current . s3db . budget_budget_bundle <EOL> row = current . db ( table . id == record_id ) . select ( table . budget_entity_id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if row : <EOL> budget_budget_totals ( row . budget_entity_id ) <EOL> return <EOL> @ staticmethod <EOL> def budget_budget_bundle_ondelete ( row ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> linktable = current . s3db . budget_budget_bundle <EOL> try : <EOL> record_id = row . id <EOL> except : <EOL> return <EOL> link = db ( linktable . id == record_id ) . select ( linktable . deleted_fk , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if link : <EOL> deleted_fk = json . loads ( link . deleted_fk ) <EOL> budget_entity_id = deleted_fk . get ( "<STR_LIT>" ) <EOL> if budget_entity_id : <EOL> budget_budget_totals ( budget_entity_id ) <EOL> return <EOL> class S3BudgetAllocationModel ( S3Model ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def model ( self ) : <EOL> T = current . T <EOL> super_link = self . super_link <EOL> entity_types = Storage ( event_asset = T ( "<STR_LIT>" ) , <EOL> event_human_resource = T ( "<STR_LIT>" ) , <EOL> event_site = T ( "<STR_LIT>" ) , <EOL> project_human_resource_project = T ( "<STR_LIT>" ) , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> self . super_entity ( tablename , "<STR_LIT>" , entity_types ) <EOL> self . add_components ( tablename , <EOL> budget_allocation = "<STR_LIT>" , <EOL> ) <EOL> tablename = "<STR_LIT>" <EOL> self . define_table ( tablename , <EOL> super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> super_link ( "<STR_LIT>" , "<STR_LIT>" , <EOL> readable = True , <EOL> writable = True , <EOL> represent = self . budget_CostItemRepresent ( ) , <EOL> ) , <EOL> s3_date ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) <EOL> ) , <EOL> s3_date ( "<STR_LIT>" , <EOL> label = T ( "<STR_LIT>" ) , <EOL> start_field = "<STR_LIT>" , <EOL> default_interval = <NUM_LIT:12> , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , <EOL> default = <NUM_LIT> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> s3_comments ( ) , <EOL> * s3_meta_fields ( ) ) <EOL> self . configure ( tablename , <EOL> deduplicate = self . budget_allocation_duplicate , <EOL> timeplot_options = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:start>" : "<STR_LIT>" , <EOL> "<STR_LIT:end>" : "<STR_LIT>" , <EOL> } , <EOL> } , <EOL> ) <EOL> return { } <EOL> def defaults ( self ) : <EOL> """<STR_LIT>""" <EOL> return { } <EOL> @ staticmethod <EOL> def budget_allocation_duplicate ( item ) : <EOL> """<STR_LIT>""" <EOL> data = item . data <EOL> budget_entity_id = data . get ( "<STR_LIT>" ) <EOL> cost_item_id = data . get ( "<STR_LIT>" ) <EOL> if budget_entity_id and cost_item_id : <EOL> table = item . table <EOL> start_date = data . get ( "<STR_LIT>" ) <EOL> end_date = data . get ( "<STR_LIT>" ) <EOL> query = ( table . budget_entity_id == budget_entity_id ) & ( table . cost_item_id == cost_item_id ) & ( ( table . start_date == None ) | ( table . start_date == start_date ) ) <EOL> duplicate = current . db ( query ) . select ( table . id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) ) . first ( ) <EOL> if duplicate : <EOL> item . id = duplicate . id <EOL> item . method = item . METHOD . UPDATE <EOL> return <EOL> class S3BudgetMonitoringModel ( S3Model ) : <EOL> """<STR_LIT>""" <EOL> names = ( "<STR_LIT>" , ) <EOL> def model ( self ) : <EOL> T = current . T <EOL> tablename = "<STR_LIT>" <EOL> self . define_table ( tablename , <EOL> self . super_link ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> s3_date ( "<STR_LIT>" , <EOL> readable = False , <EOL> writable = False , <EOL> ) , <EOL> s3_date ( "<STR_LIT>" , <EOL> empty = False , <EOL> label = T ( "<STR_LIT>" ) , <EOL> ) , <EOL> Field ( "<STR_LIT>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = lambda v : IS_FLOAT_AMOUNT . represent ( v , precision = <NUM_LIT:2> ) , <EOL> requires = IS_FLOAT_AMOUNT ( ) , <EOL> ) , <EOL> Field ( "<STR_LIT:value>" , "<STR_LIT>" , notnull = True , <EOL> default = <NUM_LIT> , <EOL> label = T ( "<STR_LIT>" ) , <EOL> represent = lambda v : IS_FLOAT_AMOUNT . represent ( v , precision = <NUM_LIT:2> ) , <EOL> requires = IS_FLOAT_AMOUNT ( ) , <EOL> ) , <EOL> s3_currency ( required = True , <EOL> writable = False , <EOL> ) , <EOL> Field . Method ( "<STR_LIT>" , self . budget_monitoring_percentage ) , <EOL> s3_comments ( ) , <EOL> * s3_meta_fields ( ) ) <EOL> self . configure ( tablename , <EOL> list_fields = [ "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:value>" , <EOL> ( T ( "<STR_LIT>" ) , "<STR_LIT>" ) , <EOL> "<STR_LIT>" , <EOL> ] , <EOL> onaccept = self . budget_monitoring_onaccept , <EOL> onvalidation = self . budget_monitoring_onvalidation , <EOL> ) <EOL> return { } <EOL> @ staticmethod <EOL> def budget_monitoring_onaccept ( form ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> table = current . s3db . budget_monitoring <EOL> record_id = form . vars . id <EOL> record = db ( table . id == record_id ) . select ( table . budget_entity_id , <EOL> table . start_date , <EOL> table . end_date , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> ) . first ( ) <EOL> if not record : <EOL> s3_debug ( "<STR_LIT>" ) <EOL> return <EOL> budget_entity_id = record . budget_entity_id <EOL> start_date = record . start_date <EOL> end_date = record . end_date <EOL> query = ( table . budget_entity_id == budget_entity_id ) & ( table . deleted == False ) & ( table . end_date < end_date ) <EOL> record = db ( query ) . select ( table . end_date , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> orderby = ~ ( table . end_date ) , <EOL> ) . first ( ) <EOL> if record and record . end_date != start_date : <EOL> db ( table . id == record_id ) . update ( start_date = record . end_date ) <EOL> query = ( table . budget_entity_id == budget_entity_id ) & ( table . deleted == False ) & ( table . end_date > end_date ) <EOL> record = db ( query ) . select ( table . id , <EOL> table . start_date , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) , <EOL> orderby = table . end_date , <EOL> ) . first ( ) <EOL> if record and record . start_date != end_date : <EOL> record . update_record ( start_date = end_date ) <EOL> @ staticmethod <EOL> def budget_monitoring_onvalidation ( form ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> s3db = current . s3db <EOL> mtable = s3db . budget_monitoring <EOL> record_id = form . record_id <EOL> record = db ( mtable . id == record_id ) . select ( mtable . budget_entity_id , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> ) . first ( ) <EOL> if not record : <EOL> s3_debug ( "<STR_LIT>" ) <EOL> return <EOL> budget_entity_id = record . budget_entity_id <EOL> btable = s3db . budget_budget <EOL> query = ( btable . budget_entity_id == budget_entity_id ) <EOL> budget = db ( query ) . select ( btable . total_budget , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> ) . first ( ) <EOL> if not budget : <EOL> s3_debug ( "<STR_LIT>" ) <EOL> return <EOL> query = ( mtable . budget_entity_id == budget_entity_id ) & ( mtable . deleted == False ) & ( mtable . id != record_id ) <EOL> records = db ( query ) . select ( mtable . planned ) <EOL> planned = <NUM_LIT:0> <EOL> for r in records : <EOL> planned += r . planned <EOL> planned += form . vars . planned <EOL> if planned > budget . total_budget : <EOL> form . errors . planned = current . T ( "<STR_LIT>" ) % budget . total_budget <EOL> @ staticmethod <EOL> def budget_monitoring_percentage ( row ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( row , "<STR_LIT>" ) : <EOL> row = row . budget_monitoring <EOL> if hasattr ( row , "<STR_LIT>" ) : <EOL> planned = row . planned <EOL> if planned == <NUM_LIT:0.0> : <EOL> return current . messages [ "<STR_LIT>" ] <EOL> else : <EOL> planned = None <EOL> if hasattr ( row , "<STR_LIT:value>" ) : <EOL> actual = row . value <EOL> else : <EOL> actual = None <EOL> if planned is not None and actual is not None : <EOL> percentage = actual / planned * <NUM_LIT:100> <EOL> return "<STR_LIT>" % "<STR_LIT>" . format ( percentage ) <EOL> if hasattr ( row , "<STR_LIT:id>" ) : <EOL> table = current . s3db . budget_monitoring <EOL> r = current . db ( table . id == row . id ) . select ( table . planned , <EOL> table . value , <EOL> limitby = ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> ) . first ( ) <EOL> if r : <EOL> planned = r . planned <EOL> if planned == <NUM_LIT:0.0> : <EOL> return current . messages [ "<STR_LIT>" ] <EOL> percentage = r . value / planned * <NUM_LIT:100> <EOL> return "<STR_LIT>" % percentage <EOL> return current . messages [ "<STR_LIT>" ] <EOL> class budget_CostItemRepresent ( S3Represent ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , show_link = False ) : <EOL> """<STR_LIT>""" <EOL> super ( budget_CostItemRepresent , self ) . __init__ ( lookup = "<STR_LIT>" , <EOL> key = "<STR_LIT>" , <EOL> show_link = show_link , <EOL> ) <EOL> s3db = current . s3db <EOL> self . represent = { <EOL> "<STR_LIT>" : s3db . asset_AssetRepresent ( show_link = False ) , <EOL> "<STR_LIT>" : s3db . org_SiteRepresent ( show_link = False ) , <EOL> "<STR_LIT>" : s3db . hrm_HumanResourceRepresent ( show_link = False ) , <EOL> } <EOL> def lookup_rows ( self , key , values , fields = [ ] ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> s3db = current . s3db <EOL> instance_fields = { <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> } <EOL> etable = s3db . budget_cost_item <EOL> rows = db ( key . belongs ( values ) ) . select ( key , <EOL> etable . instance_type ) <EOL> self . queries += <NUM_LIT:1> <EOL> keyname = key . name <EOL> types = { } <EOL> for row in rows : <EOL> instance_type = row . instance_type <EOL> cost_item_id = row [ keyname ] <EOL> if instance_type not in types : <EOL> types [ instance_type ] = { cost_item_id : row } <EOL> else : <EOL> types [ instance_type ] [ cost_item_id ] = row <EOL> results = [ ] <EOL> append = results . append <EOL> for instance_type in types : <EOL> table = s3db . table ( instance_type ) <EOL> if not table : <EOL> continue <EOL> fields = [ ] <EOL> bulk_repr = { } <EOL> if instance_type in instance_fields : <EOL> for fname in instance_fields [ instance_type ] : <EOL> field = table [ fname ] <EOL> if fname in self . represent : <EOL> represent = self . represent [ fname ] <EOL> else : <EOL> represent = field . represent <EOL> if represent and hasattr ( represent , "<STR_LIT>" ) : <EOL> bulk_repr [ fname ] = { "<STR_LIT>" : represent , "<STR_LIT>" : [ ] } <EOL> fields . append ( field ) <EOL> else : <EOL> continue <EOL> fields . insert ( <NUM_LIT:0> , table [ keyname ] ) <EOL> query = ( table [ keyname ] . belongs ( types [ instance_type ] . keys ( ) ) ) <EOL> rows = db ( query ) . select ( * fields ) <EOL> self . queries += <NUM_LIT:1> <EOL> sdata = types [ instance_type ] <EOL> for row in rows : <EOL> for fname , frepr in bulk_repr . items ( ) : <EOL> frepr [ "<STR_LIT>" ] . append ( row [ fname ] ) <EOL> append ( Row ( budget_cost_item = sdata [ row [ keyname ] ] , <EOL> ** { instance_type : row } ) ) <EOL> for fname , frepr in bulk_repr . items ( ) : <EOL> frepr [ "<STR_LIT>" ] . bulk ( frepr [ "<STR_LIT>" ] ) <EOL> return results <EOL> def represent_row ( self , row ) : <EOL> """<STR_LIT>""" <EOL> s3db = current . s3db <EOL> cost_item = row . budget_cost_item <EOL> instance_type = cost_item . instance_type <EOL> item = object . __getattribute__ ( row , instance_type ) <EOL> if instance_type == "<STR_LIT>" : <EOL> table = s3db . event_asset <EOL> repr_str = "<STR_LIT>" % ( table . incident_id . represent ( item . incident_id ) , <EOL> self . represent [ "<STR_LIT>" ] ( item . asset_id ) , <EOL> ) <EOL> elif instance_type == "<STR_LIT>" : <EOL> table = s3db . event_site <EOL> repr_str = "<STR_LIT>" % ( table . incident_id . represent ( item . incident_id ) , <EOL> self . represent [ "<STR_LIT>" ] ( item . site_id ) , <EOL> ) <EOL> elif instance_type == "<STR_LIT>" : <EOL> table = s3db . event_human_resource <EOL> repr_str = "<STR_LIT>" % ( table . incident_id . represent ( item . incident_id ) , <EOL> self . represent [ "<STR_LIT>" ] ( item . human_resource_id ) , <EOL> ) <EOL> else : <EOL> etable = s3db . budget_cost_item <EOL> instance_type_nice = etable . instance_type . represent ( instance_type ) <EOL> repr_str = "<STR_LIT>" % ( instance_type_nice , <EOL> cost_item . cost_item_id , <EOL> ) <EOL> return repr_str <EOL> def budget_kit_totals ( kit_id ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> s3db = current . s3db <EOL> ltable = s3db . budget_kit_item <EOL> query = ( ltable . kit_id == kit_id ) & ( ltable . deleted == False ) <EOL> items = db ( query ) . select ( ltable . item_id , ltable . quantity ) <EOL> item_ids = set ( item . item_id for item in items ) <EOL> itable = s3db . budget_item <EOL> query = ( itable . id . belongs ( item_ids ) ) <EOL> costs = db ( query ) . select ( itable . id , <EOL> itable . unit_cost , <EOL> itable . monthly_cost , <EOL> itable . minute_cost , <EOL> itable . megabyte_cost ) . as_dict ( ) <EOL> total_unit_cost = <NUM_LIT:0> <EOL> total_monthly_cost = <NUM_LIT:0> <EOL> total_minute_cost = <NUM_LIT:0> <EOL> total_megabyte_cost = <NUM_LIT:0> <EOL> for item in items : <EOL> quantity = item . quantity <EOL> item_costs = costs [ item . item_id ] <EOL> total_unit_cost += item_costs [ "<STR_LIT>" ] * quantity <EOL> total_monthly_cost += item_costs [ "<STR_LIT>" ] * quantity <EOL> total_minute_cost += item_costs [ "<STR_LIT>" ] * quantity <EOL> total_megabyte_cost += item_costs [ "<STR_LIT>" ] * quantity <EOL> ktable = s3db . budget_kit <EOL> db ( ktable . id == kit_id ) . update ( total_unit_cost = total_unit_cost , <EOL> total_monthly_cost = total_monthly_cost , <EOL> total_minute_cost = total_minute_cost , <EOL> total_megabyte_cost = total_megabyte_cost ) <EOL> linktable = s3db . budget_bundle_kit <EOL> bundle_id = linktable . bundle_id <EOL> rows = db ( linktable . kit_id == kit_id ) . select ( bundle_id , <EOL> groupby = bundle_id ) <EOL> for row in rows : <EOL> budget_bundle_totals ( row . bundle_id ) <EOL> return <EOL> def budget_bundle_totals ( bundle_id ) : <EOL> """<STR_LIT>""" <EOL> s3db = current . s3db <EOL> db = current . db <EOL> total_unit_cost = <NUM_LIT:0> <EOL> total_monthly_cost = <NUM_LIT:0> <EOL> ktable = s3db . budget_kit <EOL> linktable = s3db . budget_bundle_kit <EOL> left = [ ktable . on ( linktable . kit_id == ktable . id ) ] <EOL> query = ( linktable . bundle_id == bundle_id ) <EOL> rows = db ( query ) . select ( linktable . quantity , <EOL> linktable . minutes , <EOL> linktable . megabytes , <EOL> ktable . total_unit_cost , <EOL> ktable . total_monthly_cost , <EOL> ktable . total_minute_cost , <EOL> ktable . total_megabyte_cost , <EOL> left = left ) <EOL> for row in rows : <EOL> kit = row [ ktable ] <EOL> link = row [ linktable ] <EOL> quantity = link . quantity <EOL> total_unit_cost += kit . total_unit_cost * quantity <EOL> monthly_cost = kit . total_monthly_cost + kit . total_minute_cost * link . minutes + kit . total_megabyte_cost * link . megabytes <EOL> total_monthly_cost += monthly_cost * quantity <EOL> itable = s3db . budget_item <EOL> linktable = s3db . budget_bundle_item <EOL> left = [ itable . on ( linktable . item_id == itable . id ) ] <EOL> query = ( linktable . bundle_id == bundle_id ) <EOL> rows = db ( query ) . select ( linktable . quantity , <EOL> linktable . minutes , <EOL> linktable . megabytes , <EOL> itable . unit_cost , <EOL> itable . monthly_cost , <EOL> itable . minute_cost , <EOL> itable . megabyte_cost , <EOL> left = left ) <EOL> for row in rows : <EOL> item = row [ itable ] <EOL> link = row [ linktable ] <EOL> quantity = link . quantity <EOL> total_unit_cost += item . unit_cost * quantity <EOL> monthly_cost = item . monthly_cost + item . minute_cost * link . minutes + item . megabyte_cost * link . megabytes <EOL> total_monthly_cost += monthly_cost * quantity <EOL> btable = s3db . budget_bundle <EOL> db ( btable . id == bundle_id ) . update ( total_unit_cost = total_unit_cost , <EOL> total_monthly_cost = total_monthly_cost ) <EOL> linktable = s3db . budget_budget_bundle <EOL> budget_entity_id = linktable . budget_entity_id <EOL> rows = db ( linktable . bundle_id == bundle_id ) . select ( budget_entity_id , <EOL> groupby = budget_entity_id ) <EOL> for row in rows : <EOL> budget_budget_totals ( row . budget_entity_id ) <EOL> return <EOL> def budget_budget_totals ( budget_entity_id ) : <EOL> """<STR_LIT>""" <EOL> db = current . db <EOL> s3db = current . s3db <EOL> total_onetime_cost = <NUM_LIT:0> <EOL> total_recurring_cost = <NUM_LIT:0> <EOL> stable = s3db . budget_staff <EOL> ltable = s3db . budget_location <EOL> linktable = s3db . budget_budget_staff <EOL> left = [ stable . on ( linktable . staff_id == stable . id ) , <EOL> ltable . on ( linktable . location_id == ltable . id ) , <EOL> ] <EOL> query = ( linktable . budget_entity_id == budget_entity_id ) <EOL> rows = db ( query ) . select ( linktable . quantity , <EOL> linktable . months , <EOL> stable . salary , <EOL> stable . travel , <EOL> ltable . subsistence , <EOL> ltable . hazard_pay , <EOL> left = left ) <EOL> for row in rows : <EOL> quantity = row [ linktable . quantity ] <EOL> total_onetime_cost += row [ stable . travel ] * quantity <EOL> recurring_costs = row [ stable . salary ] + row [ ltable . subsistence ] + row [ ltable . hazard_pay ] <EOL> total_recurring_cost += recurring_costs * quantity * row [ linktable . months ] <EOL> btable = s3db . budget_bundle <EOL> linktable = s3db . budget_budget_bundle <EOL> left = [ btable . on ( linktable . bundle_id == btable . id ) ] <EOL> query = ( linktable . budget_entity_id == budget_entity_id ) <EOL> rows = db ( query ) . select ( linktable . quantity , <EOL> linktable . months , <EOL> btable . total_unit_cost , <EOL> btable . total_monthly_cost , <EOL> left = left ) <EOL> for row in rows : <EOL> quantity = row [ linktable . quantity ] <EOL> total_onetime_cost += row [ btable . total_unit_cost ] * quantity <EOL> total_recurring_cost += row [ btable . total_monthly_cost ] * quantity * row [ linktable . months ] <EOL> table = s3db . budget_budget <EOL> db ( table . id == budget_entity_id ) . update ( total_onetime_costs = total_onetime_cost , <EOL> total_recurring_costs = total_recurring_cost ) <EOL> def budget_rheader ( r ) : <EOL> T = current . T <EOL> if r . representation != "<STR_LIT:html>" : <EOL> return None <EOL> resourcename = r . name <EOL> if resourcename == "<STR_LIT>" : <EOL> tpvars = dict ( r . get_vars ) <EOL> tpvars [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> tabs = [ ( T ( "<STR_LIT>" ) , None ) , <EOL> ( T ( "<STR_LIT>" ) , "<STR_LIT>" ) , <EOL> ( T ( "<STR_LIT>" ) , "<STR_LIT>" ) , <EOL> ( T ( "<STR_LIT>" ) , "<STR_LIT>" ) , <EOL> ( T ( "<STR_LIT>" ) , "<STR_LIT>" , tpvars ) , <EOL> ] <EOL> rheader_fields = [ [ "<STR_LIT:name>" ] , <EOL> [ "<STR_LIT:description>" ] , <EOL> [ "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] , <EOL> ] <EOL> rheader = S3ResourceHeader ( rheader_fields , tabs ) ( r ) <EOL> elif resourcename == "<STR_LIT>" : <EOL> tabs = [ ( T ( "<STR_LIT>" ) , None ) , <EOL> ( T ( "<STR_LIT>" ) , "<STR_LIT>" ) , <EOL> ( T ( "<STR_LIT>" ) , "<STR_LIT>" ) , <EOL> ] <EOL> rheader_fields = [ [ "<STR_LIT:name>" ] , <EOL> [ "<STR_LIT:description>" ] , <EOL> [ "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] , <EOL> ] <EOL> rheader = S3ResourceHeader ( rheader_fields , tabs ) ( r ) <EOL> elif resourcename == "<STR_LIT>" : <EOL> tabs = [ ( T ( "<STR_LIT>" ) , None ) , <EOL> ( T ( "<STR_LIT>" ) , "<STR_LIT>" ) , <EOL> ] <EOL> rheader_fields = [ [ "<STR_LIT:code>" ] , <EOL> [ "<STR_LIT:description>" ] , <EOL> [ "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" ] , <EOL> ] <EOL> rheader = S3ResourceHeader ( rheader_fields , tabs ) ( r ) <EOL> return rheader </s>
