Exemplo n.º 1
0
    def handle(self, *args, **options):

        # check fuel
        from dailyreport.fuel.models import FuelConsumption
        from dailyreport.utils.date_utils import get_today
        from dailyreport.deviation.models import ParameterDeviationProblem
        from dailyreport.deviation.utils import create_problem

        cons = FuelConsumption.objects.filter(
            date__lte=get_today() - datetime.timedelta(3)
        ).extra(where=[
            '1-(plan_day/real_plan_day) >=0.05', 'real_plan_day > 0',
            'plan_day > 0',
            "id NOT IN (SELECT fuel_id FROM deviation WHERE fuel_id IS NOT NULL ORDER BY deviation.start_date ASC)"
        ])

        for item in cons:
            #print item
            create_problem(item)
Exemplo n.º 2
0
    def test_closing_problem(self):
        """
        Закрытие проблемы.
        """
        # TEST UTILITY METHOD
        info = FuelInfo.objects.create(boiler=self.boiler_obj,
                                       creator=self.test_user,
                                       type=settings.FUEL_TYPE_NAMES[0])
        consumption = FuelConsumption.objects.create(boiler=self.boiler_obj,
                                                     date=get_today(),
                                                     creator=self.test_user,
                                                     fuel_info=info)

        problem = create_problem(consumption)
        close_problem(self.test_user, problem)
        problem = ParameterDeviationProblem.objects.get(id=problem.id)
        self.assertEqual(problem.state, self.state_closed)
Exemplo n.º 3
0
    def test_commenting_problem(self):
        """
        Комментирование проблемы.
        """
        # TEST UTILITY METHOD
        info = FuelInfo.objects.create(boiler=self.boiler_obj,
                                       creator=self.test_user,
                                       type=settings.FUEL_TYPE_NAMES[0])
        consumption = FuelConsumption.objects.create(boiler=self.boiler_obj,
                                                     date=get_today(),
                                                     creator=self.test_user,
                                                     fuel_info=info)

        problem = create_problem(consumption)

        # Add comment
        comment1 = ParameterDeviationProblemComment.objects.create(
            author=self.responsible1,
            date=get_today(),
            text=u"Test comment!",
            deviation=problem)
        problem = ParameterDeviationProblem.objects.get(id=problem.id)

        # Два комментария с учетом комментария созданного при создании записи
        self.assertEqual(problem.comments.all().count(), 2)

        # Add another one comment
        comment2 = ParameterDeviationProblemComment.objects.create(
            author=self.concerned1,
            date=get_today(),
            text=u"Accept test comment!",
            deviation=problem)

        #problem = ParameterDeviationProblem.objects.get(id = problem.id)
        self.assertEqual(problem.comments.all().count(), 3)

        from django.core import serializers
        query_set = ParameterDeviationProblem.objects.all()
        result = serializers.serialize('json',
                                       query_set,
                                       indent=2,
                                       relations=('boiler', 'resource',
                                                  'state', 'cause',
                                                  'responsible'))
        print result
Exemplo n.º 4
0
    def test_creation(self):
        """
        Создание проблемы при возникновении отклонения.
        При заведении новой проблемы:
         - запись находится в статусе "Новая".
         - не указывается тип проблемы
         - указан список ответственных
         - указан список заинтересованных
         - указана дата возникновения проблемы
         - указан ресурс, параметр по которому отклоение превысило ожидаемый порог  
        """

        # TEST UTILITY METHOD
        info = FuelInfo.objects.create(boiler=self.boiler_obj,
                                       creator=self.test_user,
                                       type=settings.FUEL_TYPE_NAMES[0])
        consumption = FuelConsumption.objects.create(boiler=self.boiler_obj,
                                                     date=get_today(),
                                                     creator=self.test_user,
                                                     fuel_info=info)

        problem1 = create_problem(consumption)

        self.assertNotEqual(problem1, None)
Exemplo n.º 5
0
    def test_look_for_problem(self):
        """"""
        problems = look_for_problems_query(self.test_user, [], [], None, None,
                                           None, None)

        self.assertEqual(list(problems), [])

        # create a problem
        info = FuelInfo.objects.create(boiler=self.boiler_obj,
                                       creator=self.test_user,
                                       type=settings.FUEL_TYPE_NAMES[0])
        consumption = FuelConsumption.objects.create(boiler=self.boiler_obj,
                                                     date=get_today(),
                                                     creator=self.test_user,
                                                     fuel_info=info)

        problem = create_problem(consumption)

        self.assertNotEqual(problem, None)

        problems = look_for_problems_query(self.test_user, [], [], None, None,
                                           None, None)

        self.assertEqual(problems[0], problem)