def check_lock_status(): return_data = {"error":1,"message":"please Try again" ,"locked_count":0} data = request.data post_data = json.loads(data) selected_year = "" selected_type = 0 if post_data.get("year" ,-1) != -1 : selected_year = post_data['year'] if post_data.get("job_type" ,-1) != -1 : selected_type = post_data['job_type'] try: result = helper.check_islocked(mongo,selected_year,selected_type) return_data['locked_count'] =result except Exception as e: return_data['message'] =str(e) return jsonify(return_data)
def remove_document(): return_data = {"error":1,"message":"please Try again"} data = request.data post_data = json.loads(data) selected_year = "" selected_type = 0 if post_data.get("id" ,-1) != -1 : id = str(post_data['id']) wher_query ={} wher_query["_id"] =ObjectId(id) result = helper.find_project(mongo ,wher_query) #print(result) #return_data["search_result"] = result['documents'] result_count = result['total_records'] if result_count > 0: document =list(result['documents'])[0] oh_year_not_locked =True; ug_year_not_locked =True; if document['job_type'] ==1: date_time_str = str(document['oh_estimated_completion_date']) date_time_obj = datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S') oh_estimated_completion_year = date_time_obj.year oh_lock_year = helper.check_islocked(mongo,oh_estimated_completion_year ,1) if oh_lock_year >0: return_data["oh_error"] = "Overhead Project is Locked in this ("+ str(oh_lock_year) +") Year" oh_year_not_locked =False; elif document['job_type'] ==2: date_time_str = str(document['ug_estimated_completion_date']) date_time_obj = datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S') ug_estimated_completion_year = date_time_obj.year ug_lock_year = helper.check_islocked(mongo,ug_estimated_completion_year ,2) if ug_lock_year >0: return_data["ug_error"] = "Underground Project is Locked in this ("+ str(ug_lock_year) +") Year" ug_year_not_locked =False; elif document['job_type'] ==3: date_time_str = str(document['oh_estimated_completion_date']) date_time_obj = datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S') oh_estimated_completion_year = date_time_obj.year oh_lock_year = helper.check_islocked(mongo,oh_estimated_completion_year ,1) if oh_lock_year >0: return_data["oh_error"] = "Overhead Project is Locked in this ("+ str(oh_lock_year) +") Year" oh_year_not_locked =False; date_time_str = str(document['ug_estimated_completion_date']) date_time_obj = datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S') ug_estimated_completion_year = date_time_obj.year ug_lock_year = helper.check_islocked(mongo,ug_estimated_completion_year ,2) if ug_lock_year >0: return_data["ug_error"] = "UnderGround Project is Locked in this ("+ str(ug_lock_year) +") Year" ug_year_not_locked =False; if oh_year_not_locked and ug_year_not_locked: del_res = helper.remove_document(mongo ,ObjectId(id)) if del_res.deleted_count >0: return_data["error"] =0 return_data['message'] = "Deleted Successfully" else: return_data["error"] =1 return_data['message'] = "Somthing went Wrong. Please Try Again" else: return_data["error"] =1 return_data['message'] = "Year Is locked , You can`t delete this Project" else: return_data['error'] =1 return_data['message'] ="Selecte Project is Not Found..!" else: return_data['error'] =1 return_data['message'] ="Project id Is Required" return jsonify(return_data)
def project_initiation_update(): return_data = {"error": 1, "message": "Please Try Again"} data = request.data dataDict = json.loads(data) id = '' if dataDict.get("id", -1) != -1: id = str(dataDict.get("id")) else: return_data["id_error"] = "Document id Is Required" job_number = '' if dataDict.get("job_number", -1) != -1: job_number = str(dataDict.get("job_number")) else: return_data["job_number_error"] = "job_number Is Required" job_owner = '' if dataDict.get("job_owner", -1) != -1: job_owner = str(dataDict.get("job_owner")) else: return_data["job_owner_error"] = "job_owner Is Required" transmission_line_name = '' if dataDict.get("transmission_line_name", -1) != -1: transmission_line_name = str(dataDict["transmission_line_name"]) else: return_data["transmission_line_name_error"] = "transmission_line_name Is Required" job_type = -1 if dataDict.get("job_type", -1) != -1: job_type = int(dataDict.get("job_type")) else: return_data["job_type_error"] = "job_type Is Required" oh_estimated_completion_date = '' oh_locked_count =0 oh_year ='' ug_year ='' ug_estimated_completion_date = '' ug_locked_count =0 if ( job_type ==1) and dataDict.get("oh_estimated_completion_date", -1) != -1: oh_estimated_completion_date = dataDict.get("oh_estimated_completion_date") oh_estimated_completion_date = datetime.datetime.strptime(oh_estimated_completion_date, "%m/%d/%Y") oh_year = oh_estimated_completion_date.year oh_locked_count = helper.check_islocked(mongo ,oh_year ,1) elif ( job_type ==2 ) and dataDict.get("og_estimated_completion_date", -1) != -1: ug_estimated_completion_date = dataDict.get("og_estimated_completion_date") ug_estimated_completion_date = datetime.datetime.strptime(ug_estimated_completion_date, "%m/%d/%Y") ug_year = ug_estimated_completion_date.year ug_locked_count = helper.check_islocked(mongo ,ug_year ,2) elif job_type ==3 and dataDict.get("oh_estimated_completion_date", -1) != -1 and dataDict.get("og_estimated_completion_date", -1) != -1 : #job_type 1 oh_estimated_completion_date = dataDict.get("oh_estimated_completion_date") oh_estimated_completion_date = datetime.datetime.strptime(oh_estimated_completion_date, "%m/%d/%Y") oh_year = oh_estimated_completion_date.year oh_locked_count = helper.check_islocked(mongo ,oh_year ,1) #job type =2 ug_estimated_completion_date = dataDict.get("og_estimated_completion_date") ug_estimated_completion_date = datetime.datetime.strptime(ug_estimated_completion_date, "%m/%d/%Y") ug_year = ug_estimated_completion_date.year ug_locked_count = helper.check_islocked(mongo ,ug_year ,2) else: job_type =-1 if oh_locked_count >0 or ug_locked_count > 0 : if ( job_type ==1 ) and oh_locked_count >0: return_data["oh_error"] = "Overhead Project is Locked in this ("+ str(oh_year) +") Year" elif ( job_type ==2 ) and ug_locked_count >0: return_data["ug_error"] = "Under Ground Project is Locked in this ("+ str(ug_year) +") Year" elif job_type == 3 and (oh_locked_count >0 or ug_locked_count > 0 ): if oh_locked_count >0: return_data["oh_error"] = "Overhead Project is Locked in this ("+ str(oh_year) +") Year" if ug_locked_count >0: return_data["ug_error"] = "Under Ground Project is Locked in this ("+ str(ug_year) +") Year" return_data['error'] =1 return_data['message'] ="Selected Project Year is locked" return jsonify(return_data) pass is_itlocked = 0; # Default Value =0 not locked if(id !='' and job_number != '' and job_owner != '' and job_owner != '' and transmission_line_name != '' and job_type > 0 ): try: result = helper.find_project(mongo ,{"_id":ObjectId(id)}) if result['total_records'] >0: #check post job number is already exists other than this Selected Document job_number_result = helper.find_project(mongo ,{"_id":{"$ne":ObjectId(id)} ,"job_number":job_number }) if job_number_result['total_records'] >0: return_data['error']= 1 return_data['message'] ="Selected Job Number Already Exists" else: result['documents'] = list(result['documents'])[0] document_job_type = result['documents']['job_type'] if document_job_type != job_type: #Job type change from 2 to job type one (underground TO overhead ) if job_type == 1 and document_job_type ==2: up_res1 =helper.project_update_rename(mongo ,{"_id":ObjectId(id)} ,{"underground":"overhead"}, upsert_value =False ,multi_value =False) up_res2 =helper.project_update(mongo ,{"_id":ObjectId(id)} ,{"job_type":1 ,"overhead.type":1}, upsert_value =False ,multi_value =False) #unsetting underground if document_job_type ==3 : up_res1 =helper.project_update_unset(mongo ,{"_id":ObjectId(id),"underground":{"$exists":1}} ,{"underground":1}, upsert_value =False ,multi_value =False) #Job type change from 1 to job type 2 ( overhead TO underground ) elif job_type == 2 and document_job_type == 1: up_res1 =helper.project_update_rename(mongo ,{"_id":ObjectId(id)} ,{"overhead":"underground"}, upsert_value =False ,multi_value =False) up_res2 =helper.project_update(mongo ,{"_id":ObjectId(id)} ,{"job_type":2 ,"underground.type":2 }, upsert_value =False ,multi_value =False) if document_job_type ==3: up_res1 =helper.project_update_unset(mongo ,{"_id":ObjectId(id),"overhead":{"$exists":1}} ,{"overhead":1}, upsert_value =False ,multi_value =False) update_data ={} update_data['job_number'] =job_number update_data['job_owner'] =job_owner update_data['transmission_line_name'] =transmission_line_name update_data['job_type'] =job_type update_data['oh_estimated_completion_date'] = oh_estimated_completion_date update_data['ug_estimated_completion_date'] = ug_estimated_completion_date update_data["overhead.estimated_completion_date"] = oh_estimated_completion_date update_data["underground.estimated_completion_date"] = ug_estimated_completion_date update_res =helper.project_update(mongo ,{"_id":ObjectId(id)} ,update_data, upsert_value =False ,multi_value =False) if update_res["n"] >0 : return_data["error"] =0 return_data["message"] = "Update Successfully..!" else: return_data["error"] =1 return_data["message"] ="Not Updated Anything..!" else: return_data['error']= 1 return_data['message'] ="Selected Record not Found..!" except Exception as e: return_data['error'] = 1 return_data['message'] = str(e) else: return_data["error"] = 1 return_data['message'] ="Invalid Inputs!" return jsonify(return_data)
def project_update(): #1 = Overhead (OH) , 2 = Underground(UG) ,3= Both return_data = {"error":1,"message":"please Try again"} update_data = {} where_condation = {} data = request.data post_data = json.loads(data) document_id ='' if post_data.get("id", -1) != -1: id = str(post_data.get("id")) where_condation["_id"] = ObjectId(id) try: res = helper.find_project(mongo ,where_condation) if res['total_records'] >0: document = list(res['documents'])[0] date_time_str = str(document['oh_estimated_completion_date']) date_time_obj = datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S') oh_estimated_completion_year = date_time_obj.year this_oh_year_locked = helper.check_islocked(mongo,oh_estimated_completion_year,1) if this_oh_year_locked >0: return_data["ug_error"] = "Overhead Project is Locked in this ("+ str(oh_estimated_completion_year) +") Year" #overhead DATA PREPARATION 1 = overhead if post_data.get("overhead", -1) != -1 and (document["job_type"] == 1 or document["job_type"] == 3 ) and this_oh_year_locked <=0 : update_data["overhead.type"] = 1 update_data["overhead.estimated_completion_date"] = document['oh_estimated_completion_date'] update_data["overhead.is_itlocked"] = 0 overhead_data =post_data['overhead'] if overhead_data.get("addition", -1) != -1: overhead_addition_data = overhead_data['addition'] if overhead_addition_data.get("proj_completion", -1) != -1: overhead_addition_proj_completion_data = overhead_addition_data['proj_completion'] for key in overhead_addition_proj_completion_data: update_data["overhead.addition.proj_completion."+key] =overhead_addition_proj_completion_data[key] if overhead_addition_data.get("business_finance", -1) != -1: overhead_addition_business_finance_data = overhead_addition_data['business_finance'] for key in overhead_addition_business_finance_data: update_data["overhead.addition.business_finance."+key] =overhead_addition_business_finance_data[key] if overhead_data.get("reconductor", -1) != -1: overhead_reconductor_data = overhead_data['reconductor'] if overhead_reconductor_data.get("proj_completion", -1) != -1: overhead_reconductor_proj_completion_data = overhead_reconductor_data['proj_completion'] for key in overhead_reconductor_proj_completion_data: update_data["overhead.reconductor.proj_completion."+key] =overhead_reconductor_proj_completion_data[key] if overhead_reconductor_data.get("business_finance", -1) != -1: overhead_reconductor_business_finance_data = overhead_reconductor_data['business_finance'] for key in overhead_reconductor_business_finance_data: update_data["overhead.reconductor.business_finance."+key] =overhead_reconductor_business_finance_data[key] if overhead_data.get("removal", -1) != -1: overhead_removal_data = overhead_data['removal'] if overhead_removal_data.get("proj_completion", -1) != -1: overhead_removal_proj_completion_data = overhead_removal_data['proj_completion'] for key in overhead_removal_proj_completion_data: update_data["overhead.removal.proj_completion."+key] =overhead_removal_proj_completion_data[key] if overhead_removal_data.get("business_finance", -1) != -1: overhead_removal_business_finance_data = overhead_removal_data['business_finance'] for key in overhead_removal_business_finance_data: update_data["overhead.removal.business_finance."+key] =overhead_removal_business_finance_data[key] #UNDERGROUND DATA PRAPARATION 2 == underground date_time_str = str(document['ug_estimated_completion_date']) date_time_obj = datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S') ug_estimated_completion_year = date_time_obj.year this_ug_year_locked = helper.check_islocked(mongo,ug_estimated_completion_year,2) if this_ug_year_locked >0: return_data["ug_error"] = "Ungerground Project is Locked in this ("+ str(ug_estimated_completion_year) +") Year" if post_data.get("underground", -1) != -1 and (document["job_type"] == 2 or document["job_type"] == 3 ) and this_ug_year_locked <= 0: update_data["underground.type"] = 2 update_data["underground.estimated_completion_date"] = document['ug_estimated_completion_date'] update_data["underground.is_itlocked"] = 0 underground_data =post_data['underground'] if underground_data.get("addition", -1) != -1: underground_addition_data = underground_data['addition'] if underground_addition_data.get("proj_completion", -1) != -1: underground_addition_proj_completion_data = underground_addition_data['proj_completion'] for key in underground_addition_proj_completion_data: update_data["underground.addition.proj_completion."+key] =underground_addition_proj_completion_data[key] if underground_addition_data.get("business_finance", -1) != -1: underground_addition_business_finance_data = underground_addition_data['business_finance'] for key in underground_addition_business_finance_data: update_data["underground.addition.business_finance."+key] =underground_addition_business_finance_data[key] if underground_data.get("reconductor", -1) != -1: underground_reconductor_data = underground_data['reconductor'] if underground_reconductor_data.get("proj_completion", -1) != -1: underground_reconductor_proj_completion_data = underground_reconductor_data['proj_completion'] for key in underground_reconductor_proj_completion_data: update_data["underground.reconductor.proj_completion."+key] =underground_reconductor_proj_completion_data[key] if underground_reconductor_data.get("business_finance", -1) != -1: underground_reconductor_business_finance_data = underground_reconductor_data['business_finance'] for key in underground_reconductor_business_finance_data: update_data["underground.reconductor.business_finance."+key] =underground_reconductor_business_finance_data[key] if underground_data.get("removal", -1) != -1: underground_removal_data = underground_data['removal'] if underground_removal_data.get("proj_completion", -1) != -1: underground_removal_proj_completion_data = underground_removal_data['proj_completion'] for key in underground_removal_proj_completion_data: update_data["underground.removal.proj_completion."+key] =underground_removal_proj_completion_data[key] if underground_removal_data.get("business_finance", -1) != -1: underground_removal_business_finance_data = underground_removal_data['business_finance'] for key in underground_removal_business_finance_data: update_data["underground.removal.business_finance."+key] =underground_removal_business_finance_data[key] if len(update_data) >0: result = helper.project_update(mongo, where_condation ,update_data, upsert_value =False ,multi_value =True) if result["n"] >0 : return_data["error"] =0 return_data["message"] = "Update Successfully..!" else: return_data["error"] =1 return_data["message"] ="Not Updated Anything..!" else: return_data["error"] =1 return_data["message"] ="In Valid Project Seleted" except Exception as e: return_data["error"] =1 return_data["message"] =str(e) return jsonify(return_data)
def project_initiation(): return_data = {"error": 1, "message": "Please Try Again"} data = request.data dataDict = json.loads(data) job_number = '' if dataDict.get("job_number", -1) != -1: job_number = str(dataDict.get("job_number")) else: return_data["job_number_error"] = "job_number Is Required" job_owner = '' if dataDict.get("job_owner", -1) != -1: job_owner = str(dataDict.get("job_owner")) else: return_data["job_owner_error"] = "job_owner Is Required" transmission_line_name = '' if dataDict.get("transmission_line_name", -1) != -1: transmission_line_name = str(dataDict["transmission_line_name"]) else: return_data["transmission_line_name_error"] = "transmission_line_name Is Required" job_type = -1 if dataDict.get("job_type", -1) != -1: job_type = int(dataDict.get("job_type")) else: return_data["job_type_error"] = "job_type Is Required" oh_estimated_completion_date = '' oh_locked_count =0 oh_year ='' ug_year ='' ug_estimated_completion_date = '' ug_locked_count =0 if ( job_type ==1) and dataDict.get("oh_estimated_completion_date", -1) != -1: oh_estimated_completion_date = dataDict.get("oh_estimated_completion_date") oh_estimated_completion_date = datetime.datetime.strptime(oh_estimated_completion_date, "%m/%d/%Y") oh_year = oh_estimated_completion_date.year oh_locked_count = helper.check_islocked(mongo ,oh_year ,1) elif ( job_type ==2 ) and dataDict.get("og_estimated_completion_date", -1) != -1: ug_estimated_completion_date = dataDict.get("og_estimated_completion_date") ug_estimated_completion_date = datetime.datetime.strptime(ug_estimated_completion_date, "%m/%d/%Y") ug_year = ug_estimated_completion_date.year ug_locked_count = helper.check_islocked(mongo ,ug_year ,2) elif job_type ==3 and dataDict.get("oh_estimated_completion_date", -1) != -1 and dataDict.get("og_estimated_completion_date", -1) != -1 : #job_type 1 oh_estimated_completion_date = dataDict.get("oh_estimated_completion_date") oh_estimated_completion_date = datetime.datetime.strptime(oh_estimated_completion_date, "%m/%d/%Y") oh_year = oh_estimated_completion_date.year oh_locked_count = helper.check_islocked(mongo ,oh_year ,1) #job type =2 ug_estimated_completion_date = dataDict.get("og_estimated_completion_date") ug_estimated_completion_date = datetime.datetime.strptime(ug_estimated_completion_date, "%m/%d/%Y") ug_year = ug_estimated_completion_date.year ug_locked_count = helper.check_islocked(mongo ,ug_year ,2) else: job_type =-1 if oh_locked_count >0 or ug_locked_count > 0 : if ( job_type ==1 or job_type ==3 ) and oh_locked_count >0: return_data["oh_error"] = "Overhead Project is Locked in this ("+ str(oh_year) +") Year" if ( job_type ==2 or job_type ==3 ) and ug_locked_count >0: return_data["ug_error"] = "Under Ground Project is Locked in this ("+ str(ug_year) +") Year" return_data['error'] =1 return_data['message'] ="Selected Project Year is locked" return jsonify(return_data) pass is_itlocked = 0; # Default Value =0 not locked if( job_number != '' and job_owner != '' and job_owner != '' and transmission_line_name != '' and job_type > 0 ): try: result = helper.find_project(mongo ,{"job_number":job_number}) if result['total_records'] <=0: insert_data ={} insert_data['job_number'] =job_number insert_data['job_owner'] =job_owner insert_data['transmission_line_name'] =transmission_line_name insert_data['job_type'] =job_type insert_data['oh_estimated_completion_date'] =oh_estimated_completion_date insert_data['ug_estimated_completion_date'] =ug_estimated_completion_date result = helper.insert_data(mongo ,insert_data) if result !='': return_data['error'] = 0 return_data['message'] ="Successfully Insereted!" else: return_data['error'] =0 return_data['message'] ="Please Try Again..!" else: return_data['error']= 1 return_data['message'] ="Given Job Number Already Exists" except Exception as e: return_data['error'] = 1 return_data['message'] = str(e) else: return_data["error"] = 1 return_data['message'] ="Invalid Inputs!" return jsonify(return_data)