Esempio n. 1
0
 def get_success_url(self):
     slug = self.kwargs['slug']
     slug_proj = self.kwargs['slug_proj']
     pk = self.kwargs['pk']
     delete_complete_work(pk, slug)
     from object.views import refresh_data_object
     refresh_data_object(slug)
     from object.views import refresh_peform_proc_project
     refresh_peform_proc_project(slug_proj)
     return reverse('work:complete_work', kwargs={'slug': slug, 'slug_proj': slug_proj})
Esempio n. 2
0
def plan_work_update(request, slug_proj, slug, pk):
    work = PlanWorks.objects.get(pk=pk)
    work_form = PlanWorksForm(slug, instance=work)
    # --------------------------------------Проверка на доступ
    if not request.user.has_perm('work.change_planworks'):
        return render(request, "work/update_plan_work.html",
                      {'slug_proj': slug_proj, 'slug': slug, 'error_perm': 'У вас недостаточно прав'})
    if request.method == "POST":
        work_form = PlanWorksForm(slug, request.POST or None)
        if work_form.is_valid():
            data = work_form.cleaned_data

            type_works = data['type_works']
            quantity_plan = data['quantity_plan']
            NCH_unit_of_time = TypeOfWork.objects.get(name=type_works.name).NCH_unit_of_time
            comment = data['comment']
            NCH_general = quantity_plan * NCH_unit_of_time
            if quantity_plan != work.quantity_plan:
                if comment:
                    comment += '. План.кол-во изменилось с ' + str(work.quantity_plan) + ' на ' + str(quantity_plan)
                else:
                    comment += 'План.кол-во изменилось с ' + str(work.quantity_plan) + ' на ' + str(quantity_plan)

            if quantity_plan > work.quantity_plan:
                raznost = quantity_plan - work.quantity_plan
                quantity_plan = work.quantity_plan + raznost
                NCH_general = quantity_plan * NCH_unit_of_time

            if quantity_plan < work.quantity_plan:
                raznost = work.quantity_plan - quantity_plan
                quantity_plan = work.quantity_plan - raznost
                NCH_general = quantity_plan * NCH_unit_of_time

            NCH_left = NCH_general - work.NCH_spent
            perform_proc = int((work.NCH_spent / NCH_general) * 100)
            color = color_proc(perform_proc)
            work.quantity_plan = quantity_plan
            work.NCH_general = NCH_general
            work.type_works = type_works
            work.comment = comment
            work.NCH_left = NCH_left
            work.color = color
            work.perform_proc = perform_proc
            work.save()

            from object.views import refresh_data_object
            refresh_data_object(slug)
            from object.views import refresh_peform_proc_project
            refresh_peform_proc_project(slug_proj)
            return redirect('work:plan_work', slug_proj=slug_proj, slug=slug)
    name_object = Object.objects.get(slug__iexact=slug)
    return render(request, 'work/update_plan_work.html',
                  {'form': work_form, 'slug': slug, 'slug_proj': slug_proj, 'object_list': name_object, 'pk': pk})
Esempio n. 3
0
def delete_plan_work(request, slug, slug_proj, pk):
    name_object = Object.objects.get(slug__iexact=slug)
    plan_work = PlanWorks.objects.get(pk=pk)
    if not request.user.has_perm('work.delete_planworks'):
        return render(request, "work/delete_plan_work.html",
                      {'slug': slug, 'slug_proj': slug_proj,
                       'error_perm': 'У вас недостаточно прав', 'object_list': name_object})

    if request.method == "POST":
        plan_work.delete()

        from object.views import refresh_data_object
        refresh_data_object(slug)
        from object.views import refresh_peform_proc_project
        refresh_peform_proc_project(slug_proj)
        return redirect("work:plan_work", slug_proj=slug_proj, slug=slug)

    return render(request, 'work/delete_plan_work.html',
                  {'slug_proj': slug_proj, 'slug': slug, 'pk': pk, 'work': plan_work, 'object_list': name_object})
Esempio n. 4
0
def plan_work_create(request, slug_proj, slug):
    work_form = PlanWorksForm(slug)
    name_object = Object.objects.get(slug__iexact=slug)
    # ---------------проверка прав
    if not request.user.has_perm('work.add_planworks'):
        return render(request, "work/create_plan_work.html",
                      {'slug': slug, 'slug_proj': slug_proj, 'name_object': name_object,
                       'error_perm': 'У вас недостаточно прав'})

    if request.method == "POST":
        work_form = PlanWorksForm(slug, request.POST or None)
        if work_form.is_valid():
            data = work_form.cleaned_data
            name_object = Object.objects.get(slug__iexact=slug)
            type_works = data['type_works']
            find_works = PlanWorks.objects.filter(type_works__name__iexact=type_works.name,
                                                  name_object__slug__exact=slug)
            if find_works:
                return render(request, "work/create_plan_work.html",
                              {"form": work_form, 'slug': slug, 'slug_proj': slug_proj,
                               'name_object': name_object, 'error': 'Данная работа уже существует в списке'})
            quantity_plan = data['quantity_plan']
            NCH_unit_of_time = TypeOfWork.objects.get(name=type_works.name).NCH_unit_of_time
            NCH_general = quantity_plan * NCH_unit_of_time
            comment = data['comment']

            NCH_left = NCH_general

            color = (255, 0, 0)
            add = PlanWorks(name_object=name_object, type_works=type_works, quantity_plan=quantity_plan,
                            NCH_general=NCH_general, NCH_left=NCH_left, comment=comment, color=color)
            add.save()

            from object.views import refresh_data_object
            refresh_data_object(slug)
            from object.views import refresh_peform_proc_project
            refresh_peform_proc_project(slug_proj)
            return redirect('work:plan_work', slug_proj=slug_proj, slug=slug)
    name_object = Object.objects.get(slug__iexact=slug)
    return render(request, 'work/create_plan_work.html',
                  {'form': work_form, 'slug': slug, 'slug_proj': slug_proj, 'object_list': name_object})
Esempio n. 5
0
def complete_work_update(request, slug_proj, slug, pk):
    work = CompleteWorks.objects.get(pk=pk)
    work_form = CompleteWorksForm(slug, instance=work)
    if request.method == "POST":
        work_form = CompleteWorksForm(slug, request.POST or None)
        if work_form.is_valid():
            data = work_form.cleaned_data
            name_object = Object.objects.get(slug__iexact=slug)

            plan_work = PlanWorks.objects.get(pk=work.plan.pk)
            type_works = data['type_works']
            quantity_complete = data['quantity_complete']
            NCH_unit_of_time = TypeOfWork.objects.get(name=type_works.name).NCH_unit_of_time
            comment = data['comment']
            date = data['date']
            NCH_general = work.plan.NCH_general
            NCH_spent = quantity_complete * NCH_unit_of_time
            NCH_left = NCH_general - NCH_spent
            if date != work.date or type_works != work.type_works:
                find_works = CompleteWorks.objects.filter(date=date, type_works__name__iexact=type_works.name,
                                                          name_object__slug__exact=slug)
                if find_works:
                    return render(request, "work/update_complete_work.html",
                                  {"form": work_form, 'slug': slug, 'slug_proj': slug_proj, 'pk': pk,
                                   'name_object': name_object, 'error': 'Данная работа уже существует в этот день'})

            if quantity_complete != work.quantity_complete:
                complete_works = [p.NCH_spent for p in
                                  CompleteWorks.objects.filter(type_works=type_works, name_object=name_object)]
                max = 0
                sum = 0
                if len(complete_works) > 1:
                    for i in complete_works:
                        if i > max:
                            max = i
                    sum += max

                    raznost = (quantity_complete - work.quantity_complete) * NCH_unit_of_time
                    NCH_spent = raznost + sum
                else:
                    NCH_spent = quantity_complete * NCH_unit_of_time

                perform_proc = int((NCH_spent / NCH_general) * 100)
                color = color_proc(perform_proc)
                work.quantity_complete = quantity_complete
                work.NCH_left = NCH_left
                work.NCH_spent = NCH_spent
                work.color = color
                work.perform_proc = perform_proc

                plan_work.quantity_complete = quantity_complete
                plan_work.NCH_left = NCH_left
                plan_work.NCH_spent = NCH_spent
                plan_work.color = color
                plan_work.perform_proc = perform_proc
            if date != work.date:
                work.date = date
            if comment != work.comment:
                work.comment = comment

            work.type_works = type_works

            work.save()
            plan_work.save()

            from object.views import refresh_data_object
            refresh_data_object(slug)

            from object.views import refresh_peform_proc_project
            refresh_peform_proc_project(slug_proj)
            return redirect('work:complete_work', slug_proj=slug_proj, slug=slug)

    name_object = Object.objects.get(slug__iexact=slug)
    return render(request, 'work/update_complete_work.html',
                  {'form': work_form, 'slug': slug, 'slug_proj': slug_proj, 'object_list': name_object, 'pk': pk})
Esempio n. 6
0
def complete_work_create(request, slug_proj, slug):
    work_form = CompleteWorksForm(slug)
    check_form = CheckCompleteWorksForm(slug)
    name_object = Object.objects.get(slug__iexact=slug)
    if request.method == "POST":
        work_form = CompleteWorksForm(slug, request.POST or None)
        check_form = CheckCompleteWorksForm(slug, request.POST or None)
        if work_form.is_valid():
            data = work_form.cleaned_data
            type_works = work_form.cleaned_data['type_works']
            date = data['date']
            find_works = CompleteWorks.objects.filter(date=date, type_works__name__iexact=type_works.name,
                                                      name_object__slug__exact=slug)
            if not find_works:
                name_object = Object.objects.get(slug__iexact=slug)
                comment = data['comment']
                type_work = TypeOfWork.objects.get(name=type_works.name)
                quantity_complete = data['quantity_complete']
                NCH_unit_of_time = TypeOfWork.objects.get(name=type_works.name).NCH_unit_of_time
                general_spent = [p.NCH_spent for p in
                                 CompleteWorks.objects.filter(name_object=name_object)]
                # ------------------------выдает ошибку при нахождении одинаковых строк
                NCH_general = PlanWorks.objects.get(type_works=type_work, name_object__slug__iexact=slug).NCH_general
                # --------------------------считает затраченные часы для выполненной работы
                complete_works = [p.NCH_spent for p in
                                  CompleteWorks.objects.filter(type_works=type_work, name_object__slug__iexact=slug)]
                max = 0
                sum = 0
                if complete_works:
                    for i in complete_works:
                        if i > max:
                            max = i
                    sum += max
                    NCH_spent = (quantity_complete * NCH_unit_of_time) + sum

                else:
                    NCH_spent = quantity_complete * NCH_unit_of_time

                perform_proc = int((NCH_spent / NCH_general) * 100)
                NCH_left = NCH_general - NCH_spent

                user = request.user
                user_get = CustomUser.objects.get(id=user.id)
                first_name = '{:.1}.'.format(user_get.first_name)
                patronymic_name = '{:.1}.'.format(user_get.patronymic_name)
                last_name = '{} '.format(user_get.last_name)
                senior = '{} {} {}'.format(last_name, first_name, patronymic_name)
                plan_work = PlanWorks.objects.get(type_works=type_work.pk, name_object=name_object)
                color = color_proc(perform_proc)

                add = CompleteWorks(name_object=name_object, type_works=type_work, quantity_complete=quantity_complete,
                                    NCH_spent=NCH_spent, comment=comment, NCH_left=NCH_left, senior=senior,
                                    perform_proc=perform_proc, date=date, plan=plan_work, color=color)
                add.save()
                plan_work.quantity_complete += quantity_complete
                plan_work.NCH_spent = NCH_spent
                plan_work.NCH_left = NCH_left
                plan_work.perform_proc = perform_proc
                plan_work.color = color
                plan_work.save()

                from object.views import refresh_data_object
                refresh_data_object(slug)

                from object.views import refresh_peform_proc_project
                refresh_peform_proc_project(slug_proj)
                return redirect('work:complete_work', slug_proj=slug_proj, slug=slug)
            else:
                return render(request, "work/create_complete_work.html",
                              {"form": work_form, 'slug': slug, 'slug_proj': slug_proj, 'name_object': name_object,
                               'error': 'Данная работа уже существует в этот день', 'check_form': check_form,
                               'object_list': name_object})

    return render(request, 'work/create_complete_work.html',
                  {'form': work_form, 'slug': slug, 'slug_proj': slug_proj, 'name_object': name_object,
                   'check_form': check_form, 'object_list': name_object})