from ppms import project_rights, ppms_cu, ppms, constants from ppms.calculations.budget.budget_helper import get_main_pr_in_structure, \ get_pr_tree from ppms.calculations.budget.budget_calc_project import BudgetCalcProject from ppms.ctg_aggregation import CtgAggregation from ppms.constants import * from ppms.calculations.risks_and_chances.calc_project_totals import aggregate_risk_chance_totals import scheduling def get_plan_objects_in_mod(mod_obj, exclude_obj_types=[], get_by_state=[], dt_list=['461','823']): ''' Returns a list of all planning object ids in a module. - exclude_obj_types: Skips object types in list, -> e.g. [30] will skip programs - get_by_state: List of object states which shall be fetched, -> e.g. [1] gets only active objects - dt_list: check only records from these tables ''' obj_list = [] for da_obj in mod_obj.get_das(): if ppms_cu.Access.get_dt_id_of_ddi(da_obj) not in dt_list: continue for mts_rec_obj in da_obj.get_records(): if not hasattr(mts_rec_obj.get_dtp_record(), 'pr_id'): continue obj_id = mts_rec_obj.get_dtp_record().pr_id.get_value() obj_rec = ppms.search_record(461, [obj_id], [1042, 23220], True) obj_type = obj_rec.pr_type.get_value() obj_state = obj_rec.project_state.get_value() if get_by_state and obj_state not in get_by_state: # skip if not needed states continue if obj_type in exclude_obj_types: # exclude object by type continue if obj_id not in obj_list: obj_list.append(obj_id) return obj_list def start_tcalc(mod_obj): """ Start tcalc on given module object """ if ppms_cu.get_mod_obj_type(mod_obj) == MODULE_CLASS_MACRO: mod_obj = mod_obj.get_invoker_module() if not mod_obj: ppms.ui_message_box('Invoker of the tcalc macro could not be ' \ 'found. Please check your tcalc implementation.') return else: mod_obj = mod_obj.get_invoker_module() mod_id = mod_obj.get_id() panel_obj = mod_obj.get_panel() if not panel_obj: # if we start this outside the project work-flow, going back # in the invoker chain could end up on the user menu, therefore assuming # this here in case panel can't be found main_mod_id = ppms_cu.Helper.get_global_setting("user_menu").alpha120.get_value() else: main_mod_id = panel_obj.get_main_module().get_id() new_planing_module_id = ppms_cu.Helper.get_global_setting("new_planing_module").alpha120.get_value() program_startmodule = ppms_cu.Helper.get_global_setting("programm_startmodule").alpha120.get_value() if project_rights.check_for_active_planing() == False: mod_obj.menu(34) cost_aggregation = None pr_list_no_prg=[] if main_mod_id == program_startmodule: # there are no resources in programs, but projects shall still # be calculated, so need to skip program id here pr_list_no_prg = get_plan_objects_in_mod(mod_obj, exclude_obj_types=[30], get_by_state=[1]) pr_list = get_plan_objects_in_mod(mod_obj) if not pr_list_no_prg: pr_list_no_prg = pr_list if pr_list: cost_aggregation = CtgAggregation(projects=pr_list_no_prg, portfolios=None, mod_obj=mod_obj) if project_rights.check_cost_details_toggle() == False: # case for automatic cost registration scheduling.schedule_capacity(pr_list) if mod_id != new_planing_module_id: if cost_aggregation: # start dt472->dt281->dt282 aggregation for all projects in schedule cost_aggregation.start_full_aggregation() aggregate_risk_chance_totals(pr_list) else: # case for manual cost registration if not mod_obj.menu(193): return if cost_aggregation: # start dt281->dt282 aggregation for all projects in schedule cost_aggregation.start_aggregation_282() cost_aggregation.start_benefit_aggregation() aggregate_risk_chance_totals(pr_list) mod_obj.refresh_dts((461,)) # refresh program costs if main_mod_id == program_startmodule: l_var = mod_obj.get_current_L_var() program_id = l_var.get(30, None) if program_id: # import here to prevent circular import from ppms.calculations.budget.budget_calc_program import BudgetCalcProgram BudgetCalcProgram(program_id[0]).start_budget_calc_program() # refresh records in current project workflow if mod_id == new_planing_module_id: # recalc budget for pr_id in pr_list: BudgetCalcProject(pr_id).start_budget_calc() # start dt472->dt281->dt282 aggregation for all projects ctg_aggregation_full = CtgAggregation(mod_obj=mod_obj) ctg_aggregation_full.start_full_aggregation() aggregate_risk_chance_totals() else: mod_obj.refresh_dts((472,)) if hasattr(mod_obj, 'actualize_child_modules'): # invoke menu 19 on child modules mod_obj.actualize_child_modules() panel = mod_obj.get_panel() if not panel: return for panel_mod_obj in panel.get_modules(): if panel_mod_obj.is_stub(): # don't need to refresh if the mod hasn't been loaded yet continue if hasattr(panel_mod_obj, 'changes_in_panel'): panel_mod_obj.changes_in_panel = True else: ppms.ui_message_id("0200")