Ejemplo n.º 1
0
 def test_get_time_spents(self):
     person_id = self.person.id
     user_id = self.user["id"]
     task_id = self.task.id
     ts1 = TimeSpent.create(
         person_id=person_id,
         task_id=task_id,
         date=datetime.date(2017, 9, 23),
         duration=3600
     )
     ts2 = TimeSpent.create(
         person_id=user_id,
         task_id=task_id,
         date=datetime.date(2017, 9, 23),
         duration=7200
     )
     ts3 = TimeSpent.create(
         person_id=user_id,
         task_id=task_id,
         date=datetime.date(2017, 9, 24),
         duration=7200
     )
     time_spents = self.get(
         "/actions/tasks/%s/time-spents/" % task_id
     )
     self.assertEqual(
         time_spents["total"],
         sum([ts['duration'] for ts in [ts1, ts2, ts3]]))
     self.assertEqual(len(time_spents[str(user_id)]), 1)
     self.assertEqual(len(time_spents[str(person_id)]), 2)
Ejemplo n.º 2
0
 def test_remove_task_force(self):
     tasks_service.create_comment(self.task.id, self.task_status.id,
                                  self.person.id, "first comment")
     TimeSpent.create(person_id=self.person.id,
                      task_id=self.task.id,
                      date=datetime.date(2017, 9, 23),
                      duration=3600)
     deletion_service.remove_task(self.task_id, force=True)
     self.assertRaises(TaskNotFoundException, tasks_service.get_task,
                       self.task_id)
Ejemplo n.º 3
0
def create_or_update_time_spent(task_id, person_id, date, duration, add=False):
    """
    Create a new time spent if it doesn't exist. If it exists, it update it
    with the new duratin and returns it from the database.
    """
    try:
        time_spent = TimeSpent.get_by(
            task_id=task_id,
            person_id=person_id,
            date=date
        )
    except DataError:
        raise WrongDateFormatException

    if time_spent is not None:
        if add:
            time_spent.update({"duration": time_spent.duration + duration})
        else:
            time_spent.update({"duration": duration})
    else:
        time_spent = TimeSpent.create(
            task_id=task_id,
            person_id=person_id,
            date=date,
            duration=duration
        )
    return time_spent.serialize()
Ejemplo n.º 4
0
def create_or_update_time_spent(task_id, person_id, date, duration, add=False):
    """
    Create a new time spent if it doesn't exist. If it exists, it update it
    with the new duratin and returns it from the database.
    """
    try:
        time_spent = TimeSpent.get_by(task_id=task_id,
                                      person_id=person_id,
                                      date=date)
    except DataError:
        raise WrongDateFormatException

    if time_spent is not None:
        if duration == 0:
            time_spent.delete()
        elif add:
            time_spent.update({"duration": time_spent.duration + duration})
        else:
            time_spent.update({"duration": duration})
    else:
        time_spent = TimeSpent.create(task_id=task_id,
                                      person_id=person_id,
                                      date=date,
                                      duration=duration)

    task = Task.get(task_id)
    task.duration = 0
    time_spents = TimeSpent.get_all_by(task_id=task_id)
    for time_spent in time_spents:
        task.duration += time_spent.duration
    task.save()
    events.emit("task:update", {"task_id": task_id})

    return time_spent.serialize()
Ejemplo n.º 5
0
 def test_get_time_spents(self):
     person_id = self.person.id
     user_id = self.user.id
     task_id = self.task.id
     TimeSpent.create(person_id=person_id,
                      task_id=task_id,
                      date=datetime.date(2017, 9, 23),
                      duration=3600)
     TimeSpent.create(person_id=user_id,
                      task_id=task_id,
                      date=datetime.date(2017, 9, 23),
                      duration=7200)
     time_spents = self.get("/actions/tasks/%s/time-spents/2017-09-23/" %
                            task_id)
     self.assertEquals(time_spents["total"], 10800)
     self.assertEquals(time_spents[str(user_id)]["duration"], 7200)
     self.assertEquals(time_spents[str(person_id)]["duration"], 3600)
Ejemplo n.º 6
0
def create_or_update_time_spent(task_id, person_id, date, duration, add=False):
    """
    Create a new time spent if it doesn't exist. If it exists, it update it
    with the new duratin and returns it from the database.
    """
    try:
        time_spent = TimeSpent.get_by(task_id=task_id,
                                      person_id=person_id,
                                      date=date)
    except DataError:
        raise WrongDateFormatException

    task = Task.get(task_id)
    project_id = str(task.project_id)
    if time_spent is not None:
        if duration == 0:
            time_spent.delete()
        elif add:
            time_spent.update({"duration": time_spent.duration + duration})
        else:
            time_spent.update({"duration": duration})
        events.emit(
            "time-spent:update",
            {"time_spent_id": str(time_spent.id)},
            project_id=project_id,
        )
    else:
        time_spent = TimeSpent.create(task_id=task_id,
                                      person_id=person_id,
                                      date=date,
                                      duration=duration)
        persons_service.update_person_last_presence(person_id)
        events.emit(
            "time-spent:new",
            {"time_spent_id": str(time_spent.id)},
            project_id=project_id,
        )

    task.duration = 0
    time_spents = TimeSpent.get_all_by(task_id=task_id)
    for task_time_spent in time_spents:
        task.duration += task_time_spent.duration
    task.save()
    clear_task_cache(task_id)
    events.emit("task:update", {"task_id": task_id}, project_id=project_id)

    return time_spent.serialize()
Ejemplo n.º 7
0
def create_or_update_time_spent(task_id, person_id, date, duration, add=False):
    try:
        time_spent = TimeSpent.get_by(task_id=task_id,
                                      person_id=person_id,
                                      date=date)
    except DataError:
        raise WrongDateFormatException

    if time_spent is not None:
        if add:
            time_spent.update({"duration": time_spent.duration + duration})
        else:
            time_spent.update({"duration": duration})
    else:
        time_spent = TimeSpent.create(task_id=task_id,
                                      person_id=person_id,
                                      date=date,
                                      duration=duration)
    return time_spent.serialize()
Ejemplo n.º 8
0
def create_or_update_time_spent(
        task_id,
        person_id,
        date,
        duration,
        add=False,
        description=None,
        validation_status_id=None):
    """
    Create a new time spent if it doesn't exist. If it exists, it updates it
    with the new duratin and returns it from the database.
    """
    try:
        time_spent = TimeSpent.get_by(
            task_id=task_id, person_id=person_id, date=date
        )
    except DataError:
        raise WrongDateFormatException

    task = Task.get(task_id)
    project_id = str(task.project_id)
    if time_spent is not None:
        if duration == 0:
            time_spent.delete()
        elif add:
            time_spent.update({"duration": time_spent.duration + duration})
        else:
            time_spent.update({"duration": duration})

        if description:
            time_spent.update({"description": description, })

        if validation_status_id:
            time_spent.update({"validation_status_id": validation_status_id})

        events.emit(
            "time-spent:update",
            {"time_spent_id": str(time_spent.id)},
            project_id=project_id
        )
    else:
        if not validation_status_id:
            # Default value in migration does not work. See migration file
            # 18e010daad1d_add_timespent_description_and_validated.py
            validation_default_value = app.config["DEFAULT_TIMESPENT_VALIDATION_STATUS"]
            validation_status_id = TimeSpentStatus.query.filter(
                TimeSpentStatus.name.like(validation_default_value)).first().id

        time_spent = TimeSpent.create(
            task_id=task_id,
            person_id=person_id,
            date=date,
            duration=duration,
            description=description,
            validation_status_id=validation_status_id,
        )
        events.emit(
            "time-spent:new",
            {"time_spent_id": str(time_spent.id)},
            project_id=project_id
        )

    task.duration = 0
    time_spents = TimeSpent.get_all_by(task_id=task_id)
    for task_time_spent in time_spents:
        task.duration += task_time_spent.duration
    task.save()
    clear_task_cache(task_id)
    events.emit(
        "task:update",
        {"task_id": task_id},
        project_id=project_id
    )

    return time_spent.serialize()