def pin_to_task(executor: Executor, task: IntraserviceTask): add_journal_record(executor) update_statistic( executor, ready_min=round( (timezone.now() - executor.last_status_change).seconds / 60)) executor.intraservice_task_active = task executor.status = 'Занят' executor.last_status_change = timezone.now() executor.save() task.long_execution_notification = timezone.now() task.executor_notification_count = 0 task.admin_notification = timezone.now() task.admin_notification_count = 0 task.save() api.update_executor_and_status(task.id, executor.intraservice_user.id, TASK_STATUSES['В процессе']) task_url = api.new_api.get_task_url(task.id) bot.send_message(executor.telegram_user.user_id, text=r.EXECUTOR_PIN.format( task_id=task.id, task_url=task_url, priority=PRIORITY_STATUSES_R[task.priority], open_tasks=len(get_opened_tasks()), mass_tasks=len(get_mass_tasks())), parse_mode='Markdown')
def clear_executor_active_task(executor: Executor): add_journal_record(executor) update_statistic( executor, work_min=round( (timezone.now() - executor.last_status_change).seconds / 60)) executor.intraservice_task_active = None executor.status = 'Готов' executor.last_status_change = timezone.now() executor.save() bot.send_message(executor.telegram_user.user_id, text=r.EXECUTOR_FREE)
def task_delay(executor): task = executor.intraservice_task_active task.postponed_type = POSTPONED_TYPE['Отложена сотрудником'] task.postponed_executor = executor task.save() update_statistic( executor, postponed_task=1, work_min=round( (timezone.now() - executor.last_status_change).seconds / 60)) executor.status = 'Готов' executor.last_status_change = timezone.now() executor.intraservice_task_active = None executor.save() bot.send_message(executor.telegram_user.user_id, text=r.EXECUTOR_FREE)
def check_parent_task(cls, task, db_task): # Проверка прикрепления заявки к родительской if task['ParentId']: parent_task = None try: parent_task = IntraserviceTask.objects.get(id=task['ParentId']) except ObjectDoesNotExist: try: parent_task_json = api.new_api.get_task(task['ParentId']) parent_task = IntraserviceTask.objects.create( id=parent_task_json['Id'], status=parent_task_json['StatusId'], priority=parent_task_json['PriorityId']) except APIError as e: print(e) # ToDo if parent_task: db_task.parent = parent_task db_task.save() try: active_executor = Executor.objects.get( intraservice_task_active=db_task) except ObjectDoesNotExist: pass else: if active_executor.status == 'Занят': update_statistic( active_executor, work_min=round( (timezone.now() - active_executor.last_status_change).seconds / 60), cancel_task=1) active_executor.status = 'Готов' active_executor.last_status_change = timezone.now() active_executor.intraservice_task_active = None active_executor.save() bot.send_message( active_executor.telegram_user.user_id, text=r.PIN_OTHER_TASK.format( task_id=db_task.id, task_url=api.new_api.get_task_url(db_task.id), parent_task_id=parent_task.id, parent_task_url=api.new_api.get_task_url( parent_task.id))) elif active_executor.status == 'Не готов': update_statistic(active_executor, cancel_task=1) active_executor.intraservice_active_task = None active_executor.save()
def close_task_after_mass(executor: Executor): if executor.status == 'Занят': add_journal_record(executor) update_statistic( executor, work_min=round( (timezone.now() - executor.last_status_change).seconds / 60), cancel_task=1) task = executor.intraservice_task_active task_url = api.new_api.get_task_url(task.id) executor.intraservice_task_active = None executor.status = 'Готов' executor.last_status_change = timezone.now() executor.save() bot.send_message(executor.telegram_user.user_id, text=r.CHANGE_FROM_MASS_TASK.format( task_id=task.id, task_url=task_url)) elif executor.status == 'Не готов': update_statistic(executor, cancel_task=1) executor.intraservice_task_active = None executor.save()
def re_pin_to_task(executor: Executor): add_journal_record(executor) update_statistic( executor, ready_min=round( (timezone.now() - executor.last_status_change).seconds / 60)) executor.status = 'Занят' executor.last_status_change = timezone.now() executor.save() executor.intraservice_task_active.long_execution_notification = timezone.now( ) executor.intraservice_task_active.executor_notification_count = 0 executor.intraservice_task_active.admin_notification = timezone.now() executor.intraservice_task_active.admin_notification_count = 0 executor.intraservice_task_active.save() task_url = api.new_api.get_task_url(executor.intraservice_task_active.id) bot.send_message(executor.telegram_user.user_id, text=r.EXECUTOR_HAVE_TASK.format( task_id=executor.intraservice_task_active.id, task_url=task_url, open_tasks=len(get_opened_tasks())), parse_mode='Markdown')
def executor_stop(message): try: executor = Executor.objects.get(telegram_user__user_id=message.from_user.id) except ObjectDoesNotExist: bot.send_message(message.from_user.id, 'Вы не являетесь сотрудником ТП.') return if executor.status == 'Готов': add_journal_record(executor) update_statistic(executor, ready_min=round((timezone.now() - executor.last_status_change).seconds / 60)) executor.status = 'Не готов' executor.last_status_change = timezone.now() executor.save() bot.send_message(message.from_user.id, text=r.EXECUTOR_STOP) elif executor.status == 'Занят': add_journal_record(executor) update_statistic(executor, work_min=round((timezone.now() - executor.last_status_change).seconds / 60)) executor.status = 'Не готов' executor.last_status_change = timezone.now() executor.save() bot.send_message(message.from_user.id, text=r.EXECUTOR_STOP_WITH_TASK) elif executor.status == 'Не готов': bot.send_message(message.from_user.id, 'Вы не начинали работу.')
def pin_to_other_executor(cls, task, db_task): if task['ExecutorIds']: # and not task['ParentId']: # ToDO: Try to remove "not task['ParentId]" try: int(task['ExecutorIds']) except ValueError: pass # Good else: if db_task.status == TASK_STATUSES['Открыта']: try: executor = Executor.objects.get( intraservice_user__id=task['ExecutorIds']) except ObjectDoesNotExist: pass else: db_task.postponed_type = POSTPONED_TYPE[ 'Критическая завка'] db_task.postponed_executor = executor db_task.save() elif db_task.status == TASK_STATUSES['В работе']: try: # Исполнитель назначенный на задачу executor = Executor.objects.get( intraservice_user__id=int(task['ExecutorIds'])) except ObjectDoesNotExist: pass else: try: # Исполнитель у которого в исполнении находиться задача active_executor = Executor.objects.get( intraservice_task_active=db_task) except ObjectDoesNotExist: pass else: if executor != active_executor: # Если исполнитель сменился if active_executor.status == 'Готов': pass elif active_executor.status == 'Занят': update_statistic( active_executor, work_min=round( (timezone.now() - active_executor.last_status_change ).seconds / 60), cancel_task=1) active_executor.status = 'Готов' active_executor.last_status_change = timezone.now( ) active_executor.intraservice_task_active = None active_executor.save() bot.send_message( executor.telegram_user.user_id, text=r.PIN_OTHER_EXECUTOR.format( task_id=db_task.id, task_url=api.new_api.get_task_url( db_task.id), executor_name=executor. intraservice_user.name, executor_url= f"tg://user?id={executor.telegram_user.user_id}" )) else: active_executor.intraservice_task_active = None active_executor.save() else: if executor.intraservice_task_active: if executor.intraservice_task_active != db_task: old_task = executor.intraservice_task_active executor.intraservice_task_active = db_task executor.save() db_task.long_execution_notification = timezone.now( ) db_task.executor_notification_count = 0 db_task.admin_notification = timezone.now( ) db_task.admin_notification_count = 0 db_task.save() old_task.postponed_type = POSTPONED_TYPE[ 'Критическая завка'] old_task.postponed_executor = executor old_task.save() api.new_api.change_task( old_task.id, status_id=TASK_STATUSES[ 'Отложена'], comment= 'Сотрудник взял другую заявку') api.new_api.change_task(db_task.id) old_url = api.new_api.get_task_url( old_task.id) new_url = api.new_api.get_task_url( db_task.id) bot.send_message( executor.telegram_user.user_id, text=r.CHANGE_ACTIVE_TASK.format( old_task_id=old_task.id, new_task_id=db_task.id, old_url=old_url, new_url=new_url), parse_mode='Markdown') else: pin_to_task(executor, db_task)