def worker_submit(request, *args, **kwargs): command_type = request.GET.get('CommandType') start = request.GET.get('start') end = request.GET.get('end') worker_id = request.GET.get('resourceId') start = UDatetime.datetime_str_init(start) end = UDatetime.datetime_str_init(end, start, timedelta(hours=2)) start_date = UDatetime.pick_date_by_one_date(start) end_date = UDatetime.pick_date_by_one_date(end) worker = Workers.objects.get(id=worker_id) response = [] if command_type == 'ClearTasks': WorkScheduleReviseDAO.remove_schedule_by_date_range_and_worker( start_date, end_date, worker) elif command_type == 'ClearAll': WorkScheduleReviseDAO.remove_available_by_date_range_and_worker( start_date, end_date, worker) WorkScheduleReviseDAO.remove_schedule_by_date_range_and_worker( start_date, end_date, worker) return JsonResponse(response, safe=False)
def bulk_price_change_task(start, end, product, DOW, price, centers, user, tracking_id): start = UDatetime.datetime_str_init(start) start_report = start if not end: end = max(UDatetime.now_local() + datetime.timedelta(days=13), start + datetime.timedelta(days=13)) end_report = None else: end = UDatetime.datetime_str_init(end) end_report = end start = start.date() end = end.date() user = User.objects.get(username=user) tracking_id = Tracking.objects.get(tracking_id=tracking_id) DataReviseDAO.pricing_new3(start, end, product, DOW, price, centers, user, start_report, end_report, tracking_id=tracking_id) return
def resources(request, *args, **kwargs): start = request.GET.get('start') end = request.GET.get('end') start = UDatetime.datetime_str_init(start) end = UDatetime.datetime_str_init(end, start, timedelta(days=1)) start_date = UDatetime.pick_date_by_one_date(start) end_date = UDatetime.pick_date_by_one_date(end) workers_df = WorkScheduleDataDAO.get_all_include_workers_by_date_range( start_date, end_date) response = [] if not workers_df.empty: workers_df.rename_axis( { 'name': 'title', 'balance': 'Avail' }, axis=1, inplace=True) response = workers_df.to_dict(orient='records') return JsonResponse(response, safe=False) else: return JsonResponse(response, safe=False)
def edit(request, *args, **kwargs): current_user = request.user product_id = request.GET.get('product_id') menu_id = request.GET.get('menu_id') category = request.GET.get('category') field = request.GET.get('field') new_value = request.GET.get(field) old_value = request.GET.get('old_value') start = request.GET.get('start') end = request.GET.get('end') center_id = field start = UDatetime.datetime_str_init( start).date() if start else UDatetime.now_local().date() end = UDatetime.datetime_str_init(end).date() if end else None price = { 'price_symbol': 'equal', 'price': float(new_value), 'unit': 'dollar' } category_products = [(category, product_id)] centers = [center_id] # Get Menu menu = Menu.objects.filter( menu_id=menu_id ) #get (as opposed to filter) throws an error if multiple records are returned if menu.exists(): menu_name = menu[0].menu_name else: menu_name = None # Tracking tracking_type = TrackingType.objects.get( type='retail food tier price change') content_type = ContentType.objects.get_for_model(FoodPrice) input_params = \ { 'start': str(start), 'end': str(end), 'menu_id': menu_id, 'menu_name': menu_name, 'category_products': category_products, 'price': price, 'centers': centers } tracking_id = Tracking.objects.create(username=request.user, tracking_type=tracking_type, content_type=content_type, input_params=input_params) # FoodDataDao.updateFoodPrice(menu_id, category_products, centers, start, end, price, [category], request.user, tracking_id.tracking_id) return JsonResponse({'status': 1, 'msg': ''})
def submit(request, *args, **kwargs): start = request.GET.get('Start') end = request.GET.get('End') start = UDatetime.datetime_str_init(start) end = UDatetime.datetime_str_init(end, start, timedelta(days=1)) SmartScheduler(request, start, end).run() return JsonResponse({})
def update_food_price(menu_id, category_products, centers, start, end, price, category, user, tracking_id): user = User.objects.get(username=user) start = UDatetime.datetime_str_init( start).date() if start else UDatetime.now_local().date() end = UDatetime.datetime_str_init(start).date() if end else None FoodDataDao.updateFoodPrice(menu_id, category_products, centers, start, end, price, category, user, tracking_id) return
def submit(request, *args, **kwargs): action = request.GET.get('action') date = request.GET.get('date') price_type = request.GET.get('price_type') categories = request.GET.get('categories') categories = categories.split(',') categories = [int(category) for category in categories if category] # data init if not date: date = UDatetime.now_local().date() if not price_type: price_type = 'regular' if action == 'bulk pricing': if not categories: return JsonResponse({'status': 1, 'msg': ''}) price_symbol = request.GET.get('price-symbol') price = request.GET.get('price') price_unit = request.GET.get('price-unit') start = request.GET.get('start') end = request.GET.get('end') tiers = request.GET.getlist('tiers') if not tiers: tiers = get_tiers(date, price_type) if start: start = UDatetime.datetime_str_init(start).date() else: start = None if end: end = UDatetime.datetime_str_init(end).date() else: end = None price = [{ 'price_symbol': price_symbol, 'price_delta': UString.str2float(price), 'price_unit': price_unit, }] AlcoholReviseDAO.bulk_pricing(start, end, price, date, price_type, categories, tiers, request.user, tracking_id=None) return JsonResponse({'status': 1, 'msg': ''})
def add_worker_workers(request, *args, **kwargs): start = request.GET.get('start') end = request.GET.get('end') start = UDatetime.datetime_str_init(start) end = UDatetime.datetime_str_init(end, start, timedelta(days=1)) start_date = UDatetime.pick_date_by_one_date(start) end_date = UDatetime.pick_date_by_one_date(end) workers_df = WorkScheduleDataDAO.get_all_exclude_workers_by_date_range( start_date, end_date) workers_df_contractor = pd.DataFrame(columns=['id', 'text']) workers_df_contractor['id'] = workers_df[workers_df['type'] == 'contractor']['id'] workers_df_contractor['text'] = workers_df[ workers_df['type'] == 'contractor']['name'] if not workers_df_contractor.empty: workers_dict_contractor = workers_df_contractor.to_dict( orient='records') else: workers_dict_contractor = [] workers_df_employee = pd.DataFrame(columns=['id', 'text']) workers_df_employee['id'] = workers_df[workers_df['type'] == 'employee']['id'] workers_df_employee['text'] = workers_df[workers_df['type'] == 'employee']['name'] if not workers_df_employee.empty: workers_dict_employee = workers_df_employee.to_dict( orient='records') else: workers_dict_employee = [] response = [ { 'text': 'Contractor', 'children': workers_dict_contractor }, { 'text': 'Employee', 'children': workers_dict_employee }, ] return JsonResponse(response, safe=False)
def create(request, *args, **kwargs): page_size = request.GET.get('limit') offset = request.GET.get('offset') filters = request.GET.get('filter') sort = request.GET.get('sort') order = request.GET.get('order') product = request.GET.get('product') as_of_date = request.GET.get('as_of_date') try: as_of_date = UDatetime.datetime_str_init(as_of_date).date() except Exception as e: as_of_date = UDatetime.now_local().date() pagination = True if page_size: page_size = int(page_size) if offset: offset = int(offset) if product == 'event bowling': product_ids = ProductChoice.event_bowling_product_ids elif product == 'event shoe': product_ids = ProductChoice.event_shoe_product_ids elif product == 'event basic packages': product_ids = ProductChoice.event_basic_packages_product_ids else: product_ids = ProductChoice.event_bowling_product_ids response = DataDAO.get_centers(pagination=pagination, page_size=page_size, offset=offset, filters=filters, sort=sort, order=order, last_price=True, last_price_product_ids=product_ids, last_price_from_change=True, as_of_date=as_of_date, opt=False) # print(response) data = response[0] num = response[1] if pagination: if not data.empty: data = data.where((pd.notnull(data)), '-') data_response = data.to_dict(orient='records') response = {'total': num, 'rows': data_response} else: response = {'total': 0, 'rows': []} else: if not data.empty: data = data.where((pd.notnull(data)), '-') response = data.to_dict(orient='records') else: response = {'total': 0, 'rows': []} return JsonResponse(response, safe=False)
def create(request, *args, **kwargs): page_size = int(request.GET.get('limit')) offset = int(request.GET.get('offset')) filters = request.GET.get('filter') sort = request.GET.get('sort') order = request.GET.get('order') start = request.GET.get('start') end = request.GET.get('end') menu_id = request.GET.get('menu_id') # Get all selection values (used specifically in Center selection) category = request.GET.getlist('category') district = request.GET.getlist('district') region = request.GET.getlist('region') center_id = request.GET.getlist('center_id') # Find if all in the selections if category and 'all' in category: category = [] if district and 'all' in district: district = [] if region and 'all' in region: region = [] if center_id and 'all' in center_id: center_id = [] # Remove empty string category = [item for item in category if item] district = [item for item in district if item] region = [item for item in region if item] center_id = [item for item in center_id if item] start = UDatetime.datetime_str_init( start).date() if start else UDatetime.now_local().date() data, num = FoodDataDao.getFoodByCenter( menu_id, start, category, district, region, center_id, pagination=True, page_size=page_size, offset=offset, filters=filters, sort=sort, order=order, ) if not data.empty: data = data.where((pd.notnull(data)), "-") data_response = data.to_dict(orient='records') response = {'total': num, 'rows': data_response} else: response = {'total': 0, 'rows': []} return JsonResponse(response, safe=False)
def bulk_price_change_task_from_price_change(start, end, product, DOW, price, centers, user, tracking_id): start = UDatetime.datetime_str_init(start).date() if not end: end = None else: end = UDatetime.datetime_str_init(end).date() user = User.objects.get(username=user) tracking_id = Tracking.objects.get(tracking_id=tracking_id) DataReviseDAO.pricing_new4(start, end, product, DOW, price, centers, user, tracking_id=tracking_id) return
def event_update(request, *args, **kwargs): start = request.GET.get('start') end = request.GET.get('end') resourceId = request.GET.get('resourceId') taskId = request.GET.get('taskId') workerscheduledId = request.GET.get('workerscheduledId') start = UDatetime.datetime_str_init(start) end = UDatetime.datetime_str_init(end, start, timedelta(hours=2)) date = UDatetime.pick_date_by_two_date(start, end) duration = end - start worker = Workers.objects.get(id__exact=resourceId) task = Tasks.objects.get(work_order__exact=taskId) available_id = WorkerAvailable.objects.filter( time_start__lte=start, time_end__gte=end, name__exact=worker) if available_id.count() > 0: available_id = available_id[0] WorkScheduleReviseDAO.update_or_create_schedule( request.user, start, end, date, duration, available_id, worker, task, schedule_id=workerscheduledId) response = [] return JsonResponse(response, safe=False)
def submit(request, *args, **kwargs): # Tracking current_user = request.user start = request.GET.get('start') end = request.GET.get('end') product = request.GET.get('product') DOW = request.GET.getlist('DOW') centers = request.GET.get('centers') centers = centers.split(',') centers = [center.replace('*', '') for center in centers] last_price_from_change = True # Non task date init # start = UDatetime.datetime_str_init(start) # start_report = start # # if not end: # end = max(UDatetime.now_local() + datetime.timedelta(days=13), # start + datetime.timedelta(days=13)) # end_report = None # else: # end = UDatetime.datetime_str_init(end) # end_report = end # # start = start.date() # end = end.date() start = UDatetime.datetime_str_init(start).date() if not end: end = None else: end = UDatetime.datetime_str_init(end).date() if product == 'retail bowling': np_price_symbol = request.GET.get('np-price-symbol') np_price = request.GET.get('np-price') np_price_unit = request.GET.get('np-price-unit') np_price_base = request.GET.get('np-price-base') primewk_price_symbol = request.GET.get('primewk-price-symbol') primewk_price = request.GET.get('primewk-price') primewk_price_unit = request.GET.get('primewk-price-unit') primewk_price_base = request.GET.get('primewk-price-base') primewkd_price_symbol = request.GET.get( 'primewkd-price-symbol') primewkd_price = request.GET.get('primewkd-price') primewkd_price_unit = request.GET.get('primewkd-price-unit') primewkd_price_base = request.GET.get('primewkd-price-base') premium_price_symbol = request.GET.get('premium-price-symbol') premium_price = request.GET.get('premium-price') premium_price_unit = request.GET.get('premium-price-unit') premium_price_base = request.GET.get('premium-price-base') price = [ { 'product_id': '108', 'price_symbol': np_price_symbol, 'price_delta': UString.str2float(np_price), 'price_unit': np_price_unit, 'product_id_base': np_price_base }, { 'product_id': '110', 'price_symbol': primewk_price_symbol, 'price_delta': UString.str2float(primewk_price), 'price_unit': primewk_price_unit, 'product_id_base': primewk_price_base }, { 'product_id': '111', 'price_symbol': primewkd_price_symbol, 'price_delta': UString.str2float(primewkd_price), 'price_unit': primewkd_price_unit, 'product_id_base': primewkd_price_base }, { 'product_id': '113', 'price_symbol': premium_price_symbol, 'price_delta': UString.str2float(premium_price), 'price_unit': premium_price_unit, 'product_id_base': premium_price_base }, ] # Tracking tracking_type = TrackingType.objects.get( type='bulk retail bowling price change') content_type = ContentType.objects.get_for_model( RetailBowlingPrice) elif product == 'retail shoe': wk_price_symbol = request.GET.get('wk-price-symbol') wk_price = request.GET.get('wk-price') wk_price_unit = request.GET.get('wk-price-unit') wk_price_base = request.GET.get('wk-price-base') wknd_price_symbol = request.GET.get('wknd-price-symbol') wknd_price = request.GET.get('wknd-price') wknd_price_unit = request.GET.get('wknd-price-unit') wknd_price_base = request.GET.get('wknd-price-base') price = [ { 'product_id': '114', 'price_symbol': wk_price_symbol, 'price_delta': UString.str2float(wk_price), 'price_unit': wk_price_unit, 'product_id_base': wk_price_base }, { 'product_id': '115', 'price_symbol': wknd_price_symbol, 'price_delta': UString.str2float(wknd_price), 'price_unit': wknd_price_unit, 'product_id_base': wknd_price_base }, ] # Tracking tracking_type = TrackingType.objects.get( type='bulk retail shoes price change') content_type = ContentType.objects.get_for_model( RetailShoePrice) elif product == 'after party friday': friday8PM_price_symbol = request.GET.get('8pm-price-symbol') friday8PM_price = request.GET.get('8pm-price') friday8PM_price_unit = request.GET.get('8pm-price-unit') friday8PM_price_base = request.GET.get('8pm-price-base') friday9PM_price_symbol = request.GET.get('9pm-price-symbol') friday9PM_price = request.GET.get('9pm-price') friday9PM_price_unit = request.GET.get('9pm-price-unit') friday9PM_price_base = request.GET.get('9pm-price-base') friday10PM_price_symbol = request.GET.get('10pm-price-symbol') friday10PM_price = request.GET.get('10pm-price') friday10PM_price_unit = request.GET.get('10pm-price-unit') friday10PM_price_base = request.GET.get('10pm-price-base') friday11PM_price_symbol = request.GET.get('11pm-price-symbol') friday11PM_price = request.GET.get('11pm-price') friday11PM_price_unit = request.GET.get('11pm-price-unit') friday11PM_price_base = request.GET.get('11pm-price-base') price = [ { 'product_id': '2146481686', 'price_symbol': friday8PM_price_symbol, 'price_delta': UString.str2float(friday8PM_price), 'price_unit': friday8PM_price_unit, 'product_id_base': friday8PM_price_base }, { 'product_id': '2146532909', 'price_symbol': friday9PM_price_symbol, 'price_delta': UString.str2float(friday9PM_price), 'price_unit': friday9PM_price_unit, 'product_id_base': friday9PM_price_base }, { 'product_id': '2146507303', 'price_symbol': friday10PM_price_symbol, 'price_delta': UString.str2float(friday10PM_price), 'price_unit': friday10PM_price_unit, 'product_id_base': friday10PM_price_base }, { 'product_id': '2146481687', 'price_symbol': friday11PM_price_symbol, 'price_delta': UString.str2float(friday11PM_price), 'price_unit': friday11PM_price_unit, 'product_id_base': friday11PM_price_base }, ] # Tracking tracking_type = TrackingType.objects.get( type='bulk retail promos price change') content_type = ContentType.objects.get_for_model(ProductPrice) else: price_symbol = request.GET.get('price-symbol') price = request.GET.get('price') price_unit = request.GET.get('price-unit') price = [{ 'product_id': product, 'price_symbol': price_symbol, 'price_delta': UString.str2float(price), 'price_unit': price_unit, 'product_id_base': product }] # Tracking tracking_type = TrackingType.objects.get( type='bulk retail promos price change') content_type = ContentType.objects.get_for_model(ProductPrice) if not last_price_from_change: if not DOW: DOW = [dow[0] for dow in DOW_choice] # Tracking input_params = \ { 'start': str(start), 'end': str(end), 'product': product, 'DOW': DOW, 'price': price, 'centers': centers } tracking_id = Tracking.objects.create(username=current_user, tracking_type=tracking_type, content_type=content_type, input_params=input_params) # msg = '' if price: if last_price_from_change: bulk_price_change_task_from_price_change.delay( start, end, product, DOW, price, centers, request.user.username, tracking_id=tracking_id.tracking_id) # DataReviseDAO.pricing_new4(start, end, product, DOW, price, centers, request.user, # tracking_id=tracking_id) else: #currently not being used bulk_price_change_task.delay( start, end, product, DOW, price, centers, request.user.username, tracking_id=tracking_id.tracking_id) # DataReviseDAO.pricing_new3(start, end, product, DOW, price, centers, request.user, # start_report, end_report, tracking_id=tracking_id) msg = "RMS is updating your price changes. Price changes for all centers may take up to 15 mins. " \ "Subsequently the changes will be displayed in the 'Change Report'." return JsonResponse({'status': 1, 'msg': msg})
def bulk_product_opt(data, current_user, start, end): data = pd.DataFrame.from_dict(data) current_user = User.objects.get(username=current_user) # Format Date start = UDatetime.datetime_str_init(start).date() if not end: end = None else: end = UDatetime.datetime_str_init(end).date() def update_opt(current_user, center_id, product_num, opt, start, end): center_obj = Centers.objects.get(center_id=center_id) product_obj = Product.objects.get(product_num=str(product_num)) # Tracking tracking_type = TrackingType.objects.get( type='product opt in/out change') content_type = ContentType.objects.get_for_model(ProductOpt) input_params = { 'opt': opt, 'center_id': center_id, 'start': str(start), 'end': str(end), 'product_num': product_num } tracking_id = Tracking.objects.create(username=current_user, tracking_type=tracking_type, content_type=content_type, input_params=input_params) # Tracking Change Report BSChangeReport.objects.create(tracking_id=tracking_id, username=current_user, center_id=center_obj, product_id=product_obj, effective_start=start, effective_end=end, price_old=None, price_new=None, is_bulk_change=True, opt=opt) # ProductOpt.objects \ .update_or_create( product_id=product_obj, center_id=center_obj, start=start, end=end, defaults={ 'opt': opt, 'action_user': current_user, 'tracking_id': tracking_id, 'action_time': UDatetime.now_local() } ) for index, row in data.iterrows(): center_id = row['center_id'] product_num = row['product_num'] opt = row['opt'] update_opt(current_user, center_id, product_num, opt, start, end) # retail bowling opt in/out if product_num in ProductChoice.products_opt_oppo_pixel: if opt == 'In': opt_oppo = 'Out' elif opt == 'Out': opt_oppo = 'In' else: continue product_num_oppo = ProductChoice.products_opt_oppo_dict_pixel[ product_num] update_opt(current_user, center_id, product_num_oppo, opt_oppo, start, end) return
def create(request, *args, **kwargs): page_size = request.GET.get('limit') offset = request.GET.get('offset') filters = request.GET.get('filter') sort = request.GET.get('sort') order = request.GET.get('order') product = request.GET.get('product') as_of_date = request.GET.get('as_of_date') as_of_date = UDatetime.datetime_str_init(as_of_date).date() pagination = True if page_size: page_size = int(page_size) if offset: offset = int(offset) if product == 'retail bowling': product_ids = ProductChoice.retail_bowling_ids_new_short last_price_from_change = True elif product == 'retail shoe': product_ids = ProductChoice.retail_shoe_product_ids_new last_price_from_change = True elif product == 'after party friday': product_ids = [ '2146481686', '2146532909', '2146507303', '2146481687' ] last_price_from_change = True elif product: product_ids = [product] last_price_from_change = True else: product_ids = ProductChoice.retail_bowling_ids_new_short last_price_from_change = True response = DataDAO.get_centers( pagination=pagination, page_size=page_size, offset=offset, filters=filters, sort=sort, order=order, last_price=True, last_price_product_ids=product_ids, last_price_from_change=last_price_from_change, as_of_date=as_of_date) # print(response) data = response[0] num = response[1] if pagination: if not data.empty: data = data.where((pd.notnull(data)), '-') data_response = data.to_dict(orient='records') response = {'total': num, 'rows': data_response} else: response = {'total': 0, 'rows': []} else: if not data.empty: data = data.where((pd.notnull(data)), '-') response = data.to_dict(orient='records') else: response = {'total': 0, 'rows': []} return JsonResponse(response, safe=False)
def export(request, *args, **kwargs): page_size = request.GET.get('limit') offset = request.GET.get('offset') filters = request.GET.get('filter') sort = request.GET.get('sort') order = request.GET.get('order') product = request.GET.get('product') as_of_date = request.GET.get('as_of_date') file_type = request.GET.get('type') as_of_date = UDatetime.datetime_str_init(as_of_date).date() pagination = True if page_size: page_size = int(page_size) if offset: offset = int(offset) if product == 'retail bowling': product_ids = ProductChoice.retail_bowling_ids_new_short elif product == 'retail shoe': product_ids = ProductChoice.retail_shoe_product_ids_new elif product == 'after party friday': product_ids = [ '2146481686', '2146532909', '2146507303', '2146481687' ] elif product: product_ids = [product] else: product_ids = ProductChoice.retail_bowling_ids_new_short data, num = DataDAO.get_centers(pagination=pagination, page_size=page_size, offset=offset, filters=filters, sort=sort, order=order, last_price=True, last_price_product_ids=product_ids, last_price_from_change=True, lastPriceSplit=True, columns=[ 'center_name', 'region', 'district', 'brand', 'time_zone', 'center_type' ], as_of_date=as_of_date) # data = data.where((pd.notnull(data)), "") data.columns = map(str.capitalize, data.columns) if file_type == 'json': response = json.dumps(data.to_dict(orient='records'), ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response[ 'Content-Disposition'] = 'attachment; filename=export.json' elif file_type == 'csv': response = data.to_csv(index=False) response = HttpResponse(response, content_type='application/csv') response[ 'Content-Disposition'] = 'attachment; filename=export.csv' elif file_type == 'xlsx': response = io() xlwriter = pd.ExcelWriter(response) data.to_excel(xlwriter, index=False) xlwriter.save() xlwriter.close() response.seek(0) response = HttpResponse( response.read(), content_type= 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) response[ 'Content-Disposition'] = 'attachment; filename=export.xlsx' # elif type == 'excel': # writer = pd.ExcelWriter('export.xlsx') # response = data.to_excel(writer) # writer.save() # response = HttpResponse(response, content_type='application/vnd.ms-excel') # response['Content-Disposition'] = 'attachment; filename=export.xlsx' else: response = json.dumps([], ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response[ 'Content-Disposition'] = 'attachment; filename=export.json' return response
def update(request, *args, **kwargs): start = request.GET.get('start') end = request.GET.get('end') start = UDatetime.datetime_str_init(start) end = UDatetime.datetime_str_init(end, start, timedelta(days=1)) start_date = UDatetime.pick_date_by_one_date(start) end_date = UDatetime.pick_date_by_one_date(end) print(start_date, end_date) worker_avail = WorkerAvailable.objects.filter( date__range=[start_date, end_date]) worker_scheduled = WorkerScheduled.objects.filter(date__range=[start_date, end_date])\ .exclude(task_id__priority__in=['0', 'T']) worker_scheduled_others = WorkerScheduled.objects.filter( date__range=[start_date, end_date], task_id__priority__in=['0', 'T']) tasks = WorkScheduleDataDAO.get_all_tasks_open()[0] if worker_avail.exists(): worker_avail_df = pd.DataFrame.from_records( worker_avail.values('duration', 'deduction')) avail = (worker_avail_df['duration'] ).sum().total_seconds() / 3600 else: avail = 0 if worker_scheduled.exists(): worker_scheduled_df = pd.DataFrame.from_records( worker_scheduled.values('duration')) scheduled = worker_scheduled_df['duration'].sum( ).total_seconds() / 3600 else: scheduled = 0 if worker_scheduled_others.exists(): worker_scheduled_others_df = pd.DataFrame.from_records( worker_scheduled_others.values('duration')) scheduled_others = worker_scheduled_others_df[ 'duration'].sum().total_seconds() / 3600 else: scheduled_others = 0 if not tasks.empty: tasks_df = tasks[['estimate_hour', 'schedule_hour']] tasks_est = tasks_df['estimate_hour'].sum() tasks_count = len(tasks_df) tasks_scheduled_count = len( tasks_df[tasks_df['schedule_hour'] > 0]) else: tasks_est = 0 tasks_count = 0 tasks_scheduled_count = 0 avail_orig = avail - scheduled_others avail_remain = avail - scheduled - scheduled_others task_est_remain = tasks_est - scheduled response = { 'scheduled': scheduled, 'avail': avail_orig, 'avail_remain': avail_remain, 'tasks_est': tasks_est, 'task_est_remain': task_est_remain, 'tasks_count': tasks_count, 'tasks_scheduled_count': tasks_scheduled_count } return JsonResponse(response)
def submit(request, *args, **kwargs): # Tracking current_user = request.user start = request.GET.get('start') end = request.GET.get('end') product = request.GET.get('product') DOW = request.GET.getlist('DOW') centers = request.GET.get('centers') centers = centers.split(',') centers = [center.replace('*', '') for center in centers] start = UDatetime.datetime_str_init(start).date() if not end: end = None else: end = UDatetime.datetime_str_init(end).date() price = [] if product == 'event bowling': for bowling_product_id in ProductChoice.event_bowling_product_ids: x_price_symbol = request.GET.get( '{product_id}-price-symbol'.format( product_id=bowling_product_id)) x_price = request.GET.get('{product_id}-price'.format( product_id=bowling_product_id)) x_price_unit = request.GET.get( '{product_id}-price-unit'.format( product_id=bowling_product_id)) x_price_base = request.GET.get( '{product_id}-price-base'.format( product_id=bowling_product_id)) price += [ { 'product_id': bowling_product_id, 'price_symbol': x_price_symbol, 'price_delta': UString.str2float(x_price), 'price_unit': x_price_unit, 'product_id_base': x_price_base }, ] elif product == 'event shoe': product_id = '3101' price_symbol = request.GET.get('price-symbol') price = request.GET.get('price') price_unit = request.GET.get('price-unit') price = [{ 'product_id': product_id, 'price_symbol': price_symbol, 'price_delta': UString.str2float(price), 'price_unit': price_unit, 'product_id_base': product_id }] elif product == 'event basic packages': for product_id in ProductChoice.event_basic_packages_product_ids: x_price_symbol = request.GET.get( '{product_id}-price-symbol'.format( product_id=product_id)) x_price = request.GET.get( '{product_id}-price'.format(product_id=product_id)) x_price_unit = request.GET.get( '{product_id}-price-unit'.format( product_id=product_id)) x_price_base = request.GET.get( '{product_id}-price-base'.format( product_id=product_id)) price += [ { 'product_id': product_id, 'price_symbol': x_price_symbol, 'price_delta': UString.str2float(x_price), 'price_unit': x_price_unit, 'product_id_base': x_price_base }, ] # Tracking tracking_type = TrackingType.objects.get( type='bulk retail bowling price change') content_type = ContentType.objects.get_for_model(ProductPrice) # if not DOW: # DOW = [dow[0] for dow in DOW_choice] # Tracking input_params = \ { 'start': str(start), 'end': str(end), 'product': product, 'DOW': DOW, 'price': price, 'centers': centers } tracking_id = Tracking.objects.create(username=current_user, tracking_type=tracking_type, content_type=content_type, input_params=input_params) msg = '' if price: # DataReviseDAO.pricing_new4(start, end, product, DOW, price, centers, request.user, # tracking_id=tracking_id) bulk_price_change_task_from_price_change.delay( start, end, product, DOW, price, centers, request.user.username, tracking_id=tracking_id.tracking_id) msg = "RMS is updating your price changes. Price changes for all centers may take up to 15 mins. " \ "Subsequently the changes will be displayed in the 'Change Report'." return JsonResponse({'status': 1, 'msg': msg})
def events(request, *args, **kwargs): start = request.GET.get('start') end = request.GET.get('end') start = UDatetime.datetime_str_init(start) end = UDatetime.datetime_str_init(end, start, timedelta(days=1)) start_date = UDatetime.pick_date_by_one_date(start) end_date = UDatetime.pick_date_by_one_date(end) # avail events avail_records = WorkerAvailable.objects.filter( date__range=[start_date, end_date]) if avail_records.exists(): avail_events = pd.DataFrame.from_records( avail_records.values('name__id', 'time_start', 'time_end', 'date')) avail_events['id'] = 'WorkerAvail' avail_events['rendering'] = 'background' avail_events['color'] = 'lightgreen' avail_events.rename_axis( { 'name__id': 'resourceId', 'time_start': 'start', 'time_end': 'end' }, axis=1, inplace=True) avail_events['resourceId'] = avail_events[ 'resourceId'].astype('str') # avail_events['start'] = avail_events['start'].apply(lambda x: x.astimezone(EST)) # avail_events['end'] = avail_events['end'].apply(lambda x: x.astimezone(EST)) avail_response = avail_events.to_dict(orient='records') else: avail_response = [] # task events event_records = WorkerScheduled.objects.filter( date__range=[start_date, end_date]) if event_records.exists(): event_records = pd.DataFrame.from_records( event_records.values( 'id', 'name__id', 'task_id__work_order', 'task_id__description', 'task_id__AOR__equip_code', 'task_id__priority', 'task_id__estimate_hour', 'duration', 'time_start', 'time_end').annotate(total_duration=Sum( 'task_id__workerscheduled__duration'))) event_records.rename_axis( { 'id': 'workerscheduledId', 'name__id': 'resourceId', 'task_id__work_order': 'taskId', 'task_id__description': 'description', 'task_id__AOR__equip_code': 'equip_code', 'task_id__priority': 'priority', 'task_id__estimate_hour': 'est', 'duration': 'duration', 'time_start': 'start', 'time_end': 'end' }, axis=1, inplace=True) event_records['resourceId'] = event_records[ 'resourceId'].astype('str') event_records['title'] = event_records['taskId'] event_records['constraint'] = 'WorkerAvail' event_records['percent'] = event_records[ 'total_duration'] / event_records['est'] event_records['percent'] = event_records['percent'].apply( lambda x: np.round(x, 2)) event_records['remaining_hours'] = event_records[ 'est'] - event_records['duration'] event_records['remaining_hours'] = event_records[ 'remaining_hours'].apply( lambda x: round(x.total_seconds() / 3600)) # event_records['start'] = event_records['start'].apply(lambda x: x.astimezone(EST)) # event_records['end'] = event_records['end'].apply(lambda x: x.astimezone(EST)) event_records['duration'] = event_records[ 'duration'].apply( lambda x: np.round(x.total_seconds() / 3600, 2)) # revise time off event percent event_records[event_records['priority'] == 'T']['percent'] = 1 event_records = event_records.to_dict(orient='records') else: event_records = [] response = [] response += avail_response response += event_records return JsonResponse(response, safe=False)
def export(request, *args, **kwargs): page_size = int(request.GET.get('limit')) offset = int(request.GET.get('offset')) filters = request.GET.get('filter') sort = request.GET.get('sort') order = request.GET.get('order') start = request.GET.get('start') end = request.GET.get('end') menu_id = request.GET.get('menu_id') file_type = request.GET.get('type') # Get all selection values category = request.GET.getlist('category') district = request.GET.getlist('district') region = request.GET.getlist('region') center_id = request.GET.getlist('center_id') # Find if all in the selections if category and 'all' in category: category = [] if district and 'all' in district: district = [] if region and 'all' in region: region = [] if center_id and 'all' in center_id: center_id = [] # Remove empty string category = [item for item in category if item] district = [item for item in district if item] region = [item for item in region if item] center_id = [item for item in center_id if item] start = UDatetime.datetime_str_init( start).date() if start else UDatetime.now_local().date() data, num = FoodDataDao.getFoodByCenter(menu_id, start, category, district, region, center_id, pagination=True, page_size=page_size, offset=offset, filters=filters, sort=sort, order=order, download=True) if file_type == 'json': response = json.dumps(data.to_dict(orient='records'), ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response[ 'Content-Disposition'] = 'attachment; filename=export.json' elif file_type == 'csv': response = data.to_csv(index=False) response = HttpResponse(response, content_type='application/csv') response[ 'Content-Disposition'] = 'attachment; filename=export.csv' elif file_type == 'xlsx': response = io() xlwriter = pd.ExcelWriter(response) data.to_excel(xlwriter, index=False) xlwriter.save() xlwriter.close() response.seek(0) response = HttpResponse( response.read(), content_type= 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) response[ 'Content-Disposition'] = 'attachment; filename=export.xlsx' else: response = json.dumps([], ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response[ 'Content-Disposition'] = 'attachment; filename=export.json' return response
def submit(cls, request, *args, **kwargs): price = request.GET.get('price') category_products = request.GET.getlist('category_products') if price and category_products and category_products != [ 'undefined---undefined' ]: menu_id = request.GET.get('menu_id') category = request.GET.get('category') start = request.GET.get('start') end = request.GET.get('end') priceSymbol = request.GET.get('price-symbol') priceUnit = request.GET.get('price-unit') price_ = request.GET.get('price') start = UDatetime.datetime_str_init( start).date() if start else UDatetime.now_local().date() end = UDatetime.datetime_str_init(end).date() if end else None category_products = [ category_product.split('---') for category_product in category_products ] category_products = [ (category, product_id) for category, product_id in category_products ] centers = Panel2.Table1.get_columns(request, centersOnly=True, *args, **kwargs) price = { 'price_symbol': priceSymbol, 'price': float(price_), 'unit': priceUnit } # Get Menu menu = Menu.objects.filter(menu_id=menu_id) if menu.exists(): menu_name = menu[0].menu_name else: menu_name = None # Tracking tracking_type = TrackingType.objects.get( type='retail food tier price change') content_type = ContentType.objects.get_for_model(FoodPrice) input_params = \ { 'start': str(start), 'end': str(end), 'menu_id': menu_id, 'menu_name': menu_name, 'category_products': category_products, 'price': price, 'centers': centers } tracking_id = Tracking.objects.create( username=request.user, tracking_type=tracking_type, content_type=content_type, input_params=input_params) # update_food_price.delay(menu_id, category_products, centers, start, end, price, category, request.user.username, tracking_id.tracking_id) # FoodDataDao.updateFoodPrice(menu_id, category_products, centers, start, end, price, category, request.user, tracking_id.tracking_id) response = Panel2.Table1.get_columns(request, *args, **kwargs) return response
def submit(cls, request, *args, **kwargs): start_date = request.GET.get('StartDate') end_date = request.GET.get('EndDate') start_shift = request.GET.get('StartShift') end_shift = request.GET.get('EndShift') line = request.GET.get('Line') groupby = request.GET.get('GroupBy') product_name = request.GET.get('product_name') cause_name = request.GET.get('cause_name') div_id = request.GET.get('div_id') StartDate = UDatetime.datetime_str_init(start_date) EndDate = UDatetime.datetime_str_init(end_date, StartDate, timedelta(days=0)) response = [] if EndDate > StartDate + timedelta(days=1): start_shift_range = UDatetime.pick_shift_by_start_shift( start_shift) end_shift_range = UDatetime.pick_shift_by_end_shift( end_shift) records = ReportLostTimeDetail.objects\ .filter(Q(SalesDate__range=[StartDate + timedelta(days=1), EndDate - timedelta(days=1)], Line__exact=line) | Q(SalesDate__exact=StartDate, Line__exact=line, Shift__in=start_shift_range) | Q(SalesDate__exact=EndDate, Line__exact=line, Shift__in=end_shift_range) ) elif EndDate == StartDate + timedelta(days=1): start_shift_range = UDatetime.pick_shift_by_start_shift( start_shift) end_shift_range = UDatetime.pick_shift_by_end_shift( end_shift) records = ReportLostTimeDetail.objects\ .filter(Q(SalesDate__exact=StartDate, Line__exact=line, Shift__in=start_shift_range) | Q(SalesDate__exact=EndDate, Line__exact=line, Shift__in=end_shift_range) ) elif EndDate == StartDate: shift_range = UDatetime.pick_shift_by_two_shift( start_shift, end_shift) records = ReportLostTimeDetail.objects.filter( SalesDate__range=[StartDate, EndDate], Line__exact=line, Shift__in=shift_range) else: records = ReportLostTimeDetail.objects.none() if records.exists(): data = pd.DataFrame.from_records( records.values('SalesDate', 'Line', 'Shift', 'MIPS_Description', 'Cause', 'Comments', 'LostTimeMinutes', 'Occ')) data = data[data['LostTimeMinutes'] != 0] # get the for lower leven when click on the bar if groupby == 'Product': if div_id == 'ReportLostTimeDetailPanel2Chart1' and product_name and product_name != 'Total': groupby = 'Cause' data = data[data['MIPS_Description'] == product_name] elif div_id == 'ReportLostTimeDetailPanel2Chart2' and cause_name and cause_name != 'Total': groupby = 'Comments' data = data[ (data['MIPS_Description'] == product_name) & (data['Cause'] == cause_name)] elif groupby == 'Cause': if div_id == 'ReportLostTimeDetailPanel2Chart2' and cause_name and cause_name != 'Total': groupby = 'Comments' data = data[data['Cause'] == cause_name] # group data by different groupby field if groupby == 'Product': data_gp = data[['MIPS_Description', 'LostTimeMinutes', 'Occ']]\ .groupby(['MIPS_Description'], as_index=False)['LostTimeMinutes', 'Occ']\ .agg('sum') data_gp.rename_axis( { 'MIPS_Description': 'name', 'LostTimeMinutes': 'y', 'Occ': 'count' }, axis=1, inplace=True) elif groupby == 'Cause': data_gp = data[['Cause', 'LostTimeMinutes', 'Occ']]\ .groupby(['Cause'], as_index=False)['LostTimeMinutes', 'Occ']\ .agg('sum') data_gp.rename_axis( { 'Cause': 'name', 'LostTimeMinutes': 'y', 'Occ': 'count' }, axis=1, inplace=True) elif groupby == 'Comments': data_gp = data[['Comments', 'LostTimeMinutes', 'Occ']]\ .groupby(['Comments'], as_index=False)['LostTimeMinutes', 'Occ']\ .agg('sum') data_gp.rename_axis( { 'Comments': 'name', 'LostTimeMinutes': 'y', 'Occ': 'count' }, axis=1, inplace=True) else: response = [] return JsonResponse(response, safe=False) data_gp.reset_index(inplace=True, drop=True) data_gp['colorIndex'] = 8 data_gp.sort_values(['y'], ascending=[False], inplace=True) total_sum = data_gp['y'].sum() total_count = data_gp['count'].sum() total = pd.DataFrame( { 'name': 'Total', 'colorIndex': 9, 'y': total_sum, 'count': total_count }, index=[0]) data_gp['y'] = -data_gp['y'] data_gp = total.append(data_gp, ignore_index=True) response = data_gp.to_dict(orient='records') return JsonResponse(response, safe=False)
def get_columns(cls, request, centersOnly=False, *args, **kwargs): menuId = request.GET.get('menu_id') category = request.GET.get('category') start = request.GET.get('start') # Get all selection values district = request.GET.getlist('district') region = request.GET.getlist('region') center_id = request.GET.getlist('center_id') # Find if all in the selections if district and 'all' in district: district = [] if region and 'all' in region: region = [] if center_id and 'all' in center_id: center_id = [] # Remove empty string district = [item for item in district if item] region = [item for item in region if item] center_id = [item for item in center_id if item] # Filter centers centers = Centers.objects \ .filter(status='open') if district: centers = centers.filter(district__in=district) if region: centers = centers.filter(region__in=region) if center_id: centers = centers.filter(center_id__in=center_id) center_list = centers.values_list('center_id', flat=True) start = UDatetime.datetime_str_init( start).date() if start else UDatetime.now_local().date() centers = FoodPrice.objects \ .filter(status='active', menu__menu_id=menuId, center_id__in=center_list ) \ .exclude(Q(start__gt=start) | Q(end__lt=start) ) \ .values_list('center_id', flat=True).distinct() centers = sorted([int(center) for center in centers]) if centersOnly: return centers columns = \ [ { 'field': 'state', 'title': 'State', 'checkbox': True }, { 'field': 'menu', 'title': 'Menu', 'sortable': True, 'editable': False, 'align': 'center', 'vlign': 'center' }, { 'field': 'category', 'title': 'Category', 'sortable': True, 'editable': False, 'align': 'center', 'vlign': 'center' }, { 'field': 'food', 'title': 'Food', 'sortable': True, 'editable': False, 'align': 'center', 'vlign': 'center', 'filter': {'type': 'input'} }, { 'field': 'product_num', 'title': 'Prod Num', 'sortable': True, 'editable': False, 'align': 'center', 'vlign': 'center', 'filter': {'type': 'input'} }, # { # 'field': 'start', 'title': 'Start', 'sortable': True, 'editable': True, # 'align': 'center', 'vlign': 'center', 'filter': {'type': 'input'} # }, # { # 'field': 'end', 'title': 'End', 'sortable': True, 'editable': True, # 'align': 'center', 'vlign': 'center', 'filter': {'type': 'input'} # }, { 'field': 'product_id', 'title': 'product_id', 'visible': False, 'align': 'center', 'vlign': 'center', 'filter': {'type': 'input'} }, { 'field': 'menu_id', 'title': 'menu_id', 'visible': False, 'align': 'center', 'vlign': 'center', 'filter': {'type': 'input'} }, ] columns += [{ 'field': centerId, 'title': centerId, 'editable': True, 'align': 'center', 'vlign': 'center', } for centerId in centers] return JsonResponse({'status': 1, 'msg': '', 'columns': columns})
def get_selections(cls, request, *args, **kwargs): selectType = request.GET.get('selectType') search = request.GET.get('search') menuId = request.GET.get('menu_id') start = request.GET.get('start') start = UDatetime.datetime_str_init( start).date() if start else UDatetime.now_local().date() if not search: result = [{ 'id': 'all', "text": 'All', }] else: result = [] if selectType == 'district': centers = Centers.objects.filter(status='open') \ .exclude(district=None) \ .exclude(district__contains='closed') if search: centers = centers.filter(district__contains=search) values = centers.values_list('district', flat=True).distinct() values = sorted(values) result += \ [ { 'id': value, "text": value, } for value in values ] elif selectType == 'region': centers = Centers.objects.filter(status='open') \ .exclude(region=None) \ .exclude(region__contains='closed') if search: centers = centers.filter(region__contains=search) values = centers.values_list('region', flat=True).distinct() values = sorted(values) result += \ [ { 'id': value, "text": value, } for value in values ] elif selectType == 'center_id': centers = Centers.objects.filter(status='open') if search: if search.isdigit(): centers = centers.filter(center_id__contains=search) else: centers = centers.filter(center_name__contains=search) centers = centers \ .order_by('center_id') \ .extra(select={'center_id': 'CAST(center_id AS INTEGER)'}) center_records = pd.DataFrame.from_records( centers.values( 'center_id', 'center_name', )) result += \ [ { 'id': row['center_id'], "text": str(row['center_id']) + '-' + str(row['center_name']), } for index, row in center_records.iterrows() ] elif selectType == 'menu_id': menus = Menu.objects.filter(status='active') if search: menus = menus.filter(menu_name__contains=search) menu_records = pd.DataFrame.from_records( menus.values( 'menu_id', 'menu_name', )) if not menu_records.empty: menu_records.sort_values(['menu_name'], inplace=True) result = [] result += \ [ { 'id': row['menu_id'], "text": row['menu_name'], } for index, row in menu_records.iterrows() ] elif selectType == 'category': if menuId: values = FoodPrice.objects \ .filter(menu_id=menuId) \ .exclude(Q(start__gt=start) | Q(end__lt=start) ) if search: values = values.filter(category__contains=search) values = values \ .values_list('category', flat=True) \ .distinct() else: values = [] result += \ [ { 'id': value, "text": value, } for value in values ] return JsonResponse({'status': 1, 'msg': '', 'results': result})
def select_submit(request, *args, **kwargs): command_type = request.GET.get('CommandType') worker_id = request.GET.get('resourceId') start = request.GET.get('start') end = request.GET.get('end') start = UDatetime.datetime_str_init(start) end = UDatetime.datetime_str_init(end, start, timedelta(hours=2)) date = UDatetime.pick_date_by_two_date(start, end) duration = end - start response = {} worker = Workers.objects.get(id=worker_id) if command_type == 'ExtendWorkerAvailable': avails = WorkerAvailable.objects.filter( Q(time_start__range=[start, end]) | Q(time_end__range=[start, end]) | Q(time_start__lte=start, time_end__gte=end), name__exact=worker) if avails.exists(): avails_df = pd.DataFrame.from_records(avails.values()) if avails.count() == 1: avail_id = avails_df['id'].tolist()[0] else: return start_list = avails_df['time_start'].tolist() start_list.append(start) end_list = avails_df['time_end'].tolist() end_list.append(end) # start_new = min(start_list).astimezone(EST) # end_new = max(end_list).astimezone(EST) start_new = min(start_list).replace(tzinfo=EST) end_new = max(end_list).replace(tzinfo=EST) date = UDatetime.pick_date_by_two_date( start_new, end_new) duration_new = end_new - start_new WorkScheduleReviseDAO.update_or_create_available( request.user, start_new, end_new, date, duration_new, WorkAvailSheet.DEDUCTION, worker, avail_id=avail_id, source='manual') # WorkerAvailable.objects.update_or_create(id=avail_id, # defaults={ # 'name': worker, # 'date': date, # 'duration': duration_new, # 'deduction': WorkAvailSheet.DEDUCTION, # 'time_start': start_new, # 'time_end': end_new # }) else: duration = end - start WorkScheduleReviseDAO.update_or_create_available( request.user, start, end, start.date(), duration, WorkAvailSheet.DEDUCTION, worker, source='manual') # WorkerAvailable.objects.update_or_create(name=worker, # date=start.date(), # duration=duration, # deduction=WorkAvailSheet.DEDUCTION, # time_start=start, # time_end=end, # source='manual') elif command_type == 'CutWorkerAvailable': avails = WorkerAvailable.objects.filter( Q(time_start__range=[start, end]) | Q(time_end__range=[start, end]) | Q(time_start__lte=start, time_end__gte=end), name__exact=worker) if avails.exists(): start = start.replace(tzinfo=pytz.UTC) end = end.replace(tzinfo=pytz.UTC) avails_df = pd.DataFrame.from_records(avails.values()) if avails.count() == 1: avail_id = avails_df['id'].tolist()[0] start_list = avails_df['time_start'].tolist() start_list.append(start) end_list = avails_df['time_end'].tolist() end_list.append(end) range_new = UDatetime.remove_overlap( start_list[0], end_list[0], start_list[1], end_list[1]) if len(range_new) == 1: start_new = range_new[0][0] end_new = range_new[0][1] if start_new == end_new: WorkScheduleReviseDAO.remove_available_by_id( avail_id) # WorkerAvailable.objects.filter(id__in=avail_id).delete() else: date = UDatetime.pick_date_by_two_date( start_new, end_new) duration_new = end_new - start_new WorkScheduleReviseDAO.update_or_create_available( request.user, start_new, end_new, date, duration_new, WorkAvailSheet.DEDUCTION, worker, avail_id=avail_id, source='manual') # WorkerAvailable.objects.update_or_create(id__in=ids, # defaults={ # 'name': worker, # 'date': date, # 'duration': duration_new, # 'deduction': WorkAvailSheet.DEDUCTION, # 'time_start': start_new, # 'time_end': end_new # }) else: response = {} elif command_type in ['Lunch', 'Breaks', 'UnionBus']: if command_type == 'Lunch': # task = WorkScheduleReviseDAO.create_or_update_timeoff_lunch_task(request.user, source='manual') task = Tasks.objects.get(work_order__exact='TLUNCH') elif command_type == 'Breaks': # task = WorkScheduleReviseDAO.create_or_update_timeoff_breaks_task(request.user, source='manual') task = Tasks.objects.get(work_order__exact='TBREAK') elif command_type == 'UnionBus': task = WorkScheduleReviseDAO.create_or_update_union_bus_task( request.user, duration, source='manual') else: return JsonResponse(response) available_ids = WorkerAvailable.objects.filter( time_start__lte=start, time_end__gte=end, name__exact=worker) if available_ids.count() > 0: available_id = available_ids[0] WorkScheduleReviseDAO.update_or_create_schedule( request.user, start, end, date, duration, available_id, worker, task, source='manual') # worker_scheduled = WorkerScheduled.objects.update_or_create(name=worker, # date=date, # time_start=start, # time_end=end, # task_id=task, # available_id=available_id, # defaults={'duration': duration}) return JsonResponse(response)