Exemple #1
0
    def get_reporting_period(project, search_date):
        """Returns the reporting period that is currently valid. Valid is a reporting period when the provided date
          lies between begin and end of the reporting period

        Args:
          no arguments

        Returns:
          reporting_period (ReportPeriod)

        Raises:
          ReportPeriodNotFound when there is no valid reporting Period"""
        current_valid_reporting_period = None
        for reporting_period in ReportingPeriod.objects.filter(project=project):
            if reporting_period.begin <= search_date <= reporting_period.end:
                return reporting_period
        if not current_valid_reporting_period:
            raise ReportingPeriodNotFound("Reporting Period does not exist")
Exemple #2
0
    def get_all_predecessors(target_reporting_period, project):
        """Returns all reporting periods which have been valid before the provided target_reporting_period

        Args:
          no arguments

        Returns:
          predecessor_reporting_periods[] (Array of ReportPeriod)

        Raises:
          ReportPeriodNotFound when there is no valid reporting Period"""
        predecessor_reporting_periods = list()
        for reporting_period in ReportingPeriod.objects.filter(
                project=project):
            if reporting_period.end <= target_reporting_period.begin:
                predecessor_reporting_periods.append(reporting_period)
        if len(predecessor_reporting_periods) == 0:
            raise ReportingPeriodNotFound("Reporting Period does not exist")
        return predecessor_reporting_periods
Exemple #3
0
    def get_all_prior_reporting_periods(target_reporting_period, project):
        """Returns the reporting period that is currently valid. Valid is a reporting period when the current date
          lies between begin and end of the reporting period

        Args:
          no arguments

        Returns:
          reporting_period (List of ReportPeriod)

        Raises:
          ReportPeriodNotFound when there is no valid reporting Period"""
        reporting_periods = []
        for reporting_period in ReportingPeriod.objects.filter(
                project=project):
            if reporting_period.end < reporting_period.begin:
                reporting_period.append(reporting_period)
        if reporting_periods:
            raise ReportingPeriodNotFound("Reporting Period does not exist")
        return reporting_periods
Exemple #4
0
    def get_latest_reporting_period(project):
        """Returns the latest reporting period

        Args:
          no arguments

        Returns:
          reporting_period (ReportPeriod)

        Raises:
          ReportPeriodNotFound when there is no valid reporting Period"""
        latest_reporting_period = None
        reporting_periods = ReportingPeriod.objects.filter(project=project)
        for reporting_period in reporting_periods:
            if latest_reporting_period is None:
                latest_reporting_period = reporting_period
            else:
                if latest_reporting_period.end <= reporting_period.begin:
                    latest_reporting_period = reporting_period
        if not latest_reporting_period:
            raise ReportingPeriodNotFound("Reporting Period does not exist")
        return latest_reporting_period
Exemple #5
0
    def get_predecessor(target_reporting_period, project):
        """Returns the reporting period which was valid right before the provided target_reporting_period

        Args:
          no arguments

        Returns:
          predecessor_reporting_period (ReportPeriod)

        Raises:
          ReportPeriodNotFound when there is no valid reporting Period"""
        predecessor_reporting_period = None
        reporting_periods = ReportingPeriod.objects.filter(project=project)
        for reporting_period in reporting_periods:
            if reporting_period.end <= target_reporting_period.begin and\
                    predecessor_reporting_period is None:
                predecessor_reporting_period = reporting_period
            elif reporting_period.end <= target_reporting_period.begin and\
                    reporting_period.end <= predecessor_reporting_period.begin:
                predecessor_reporting_period = reporting_period
        if predecessor_reporting_period is None:
            raise ReportingPeriodNotFound("Reporting Period does not exist")
        return predecessor_reporting_period