def create_project(self): """ this method is used to create project for current bdo. """ try: print("choose gpm for project\n") gpm_list = self.get_gpm_list() menu = Menu() gpm_names = [x for x in gpm_list.keys()] gpm_names.extend([str(BackButton.EXIT.name)]) gpm_name = menu.draw_menu(gpm_names) input() gpm_id = gpm_list[gpm_name] print("choose project type:\n") menu2 = Menu() project_types = [x.name for x in ProjectType] project_types.extend([str(BackButton.EXIT.name)]) project_type = menu2.draw_menu(project_types) input() project_id = str(uuid.uuid4()) project_name = input("enter project name: ") labours = input("enter expected labours: ") if not Validation.is_int(labours): print("labours count is not valid") input() sys.exit() cost = input("enter estimated project cost: ") if not Validation.is_int(cost): print("cost is not valid") input() sys.exit() area = input("enter estimated project area: ") if not Validation.is_int(area): print("area is not valid") input() sys.exit() start_date = input("enter estimated start date: ") if not Validation.is_date(start_date): print("start date is not valid") input() sys.exit() end_date = input("enter estimated end date: ") if not Validation.is_date(end_date): print("end date is not valid") input() sys.exit() is_deleted = 'False' created_by = self.bdo_id self.conn.create_project(project_id, project_name, labours, cost, area, start_date, end_date, gpm_id, created_by, project_type, is_deleted) self.conn.commit_data() print("\n" + Color.F_Green + "project created" + Base.END) except Exception as e: print(e) self.conn.rollback_data()
def update_project(self): """ this method is used to update project for current bdo. """ print("choose project") project_list = self.get_project_list() menu = Menu() project_names = [x for x in project_list.keys()] project_names.extend( [str(BackButton.EXIT.name), str(BackButton.BACK.name)]) project_name = menu.draw_menu(project_names) input() if str(BackButton.BACK.name) == project_name: return project_id = project_list[project_name] print("select the field to update: \n") menu2 = Menu() details = [x.name for x in ProjectsUpdateFields] details.extend([str(BackButton.EXIT.name)]) field = menu2.draw_menu(details) input() user_input = "" if ProjectsUpdateFields[ field].value == ProjectsUpdateFields.PROJECT_TYPE.value: print("choose project type: \n") menu3 = Menu() project_types = [x.name for x in ProjectType] project_types.extend([str(BackButton.EXIT.name)]) user_input = menu3.draw_menu(project_types) input() else: user_input = input("enter new value for " + str(field) + " ") # validations if field == str(ProjectsUpdateFields.AREA_OF_PROJECT.name): if not Validation.is_int(user_input): print("area is not valid") input() sys.exit() if field == str(ProjectsUpdateFields.TOTAL_LABOUR_REQUIRED.name): if not Validation.is_int(user_input): print("labour required is not valid") input() sys.exit() if field == str(ProjectsUpdateFields.ESTIMATED_START_DATE.name): if not Validation.is_date(user_input): print("start date is not valid") input() sys.exit() if field == str(ProjectsUpdateFields.ESTIMATED_END_DATE.name): if not Validation.is_date(user_input): print("end date is not valid") input() sys.exit() if field == str(ProjectsUpdateFields.ESTIMATED_COST.name): if not Validation.is_int(user_input): print("cost is not valid") input() sys.exit() self.conn.update_project(field, user_input, project_id) self.conn.commit_data() print("\n" + Color.F_Green + "record updated" + Base.END)