Пример #1
0
    def get_awaiting_banktransactions(self):
        """
        Return awaiting bank transaction scheduled. To be awaiting :
        - have explicit state BankTransactionScheduler.STATE_WAITING
        OR
        - have state BankTransactionScheduler.STATE_FINISHED and being lower
          than the recurring datetime, depending on its type.
        """
        month_start = get_datetime_ranges(timezone.now(), GRANULARITY_MONTH)[0]
        week_start = get_datetime_ranges(timezone.now(), GRANULARITY_WEEK)[0]

        monthly = (
            Q(type=BankTransactionScheduler.TYPE_MONTHLY) &
            Q(last_action__lt=month_start)
        )
        weekly = (
            Q(type=BankTransactionScheduler.TYPE_WEEKLY) &
            Q(last_action__lt=week_start)
        )

        return self.filter(
            Q(state=BankTransactionScheduler.STATE_WAITING) |
            (
                Q(state=BankTransactionScheduler.STATE_FINISHED) &
                (monthly | weekly)
            )
        )
Пример #2
0
    def get_awaiting_banktransactions(self):
        """
        Return awaiting bank transaction scheduled. To be awaiting :
        - have explicit state BankTransactionScheduler.STATE_WAITING
        OR
        - have state BankTransactionScheduler.STATE_FINISHED and being lower
          than the recurring datetime, depending on its type.
        """
        month_start = get_datetime_ranges(timezone.now(), GRANULARITY_MONTH)[0]
        week_start = get_datetime_ranges(timezone.now(), GRANULARITY_WEEK)[0]

        monthly = (
            Q(type=BankTransactionScheduler.TYPE_MONTHLY) &
            Q(last_action__lt=month_start)
        )
        weekly = (
            Q(type=BankTransactionScheduler.TYPE_WEEKLY) &
            Q(last_action__lt=week_start)
        )

        return self.filter(
            Q(state=BankTransactionScheduler.STATE_WAITING) |
            (
                Q(state=BankTransactionScheduler.STATE_FINISHED) &
                (monthly | weekly)
            )
        )
Пример #3
0
    def test_month(self):

        s, e = get_datetime_ranges(
            datetime.datetime(2015, 2, 15, 12, 15),
            GRANULARITY_MONTH,
        )
        self.assertEqual(s, datetime.datetime(2015, 2, 1, 0, 0, 0, 0))
        self.assertEqual(e, datetime.datetime(2015, 2, 28, 23, 59, 59, 0))

        s, e = get_datetime_ranges(
            datetime.datetime(2016, 2, 15, 12, 15),
            GRANULARITY_MONTH,
        )
        self.assertEqual(s, datetime.datetime(2016, 2, 1, 0, 0, 0, 0))
        self.assertEqual(e, datetime.datetime(2016, 2, 29, 23, 59, 59, 0))
Пример #4
0
    def test_week(self):

        with self.settings(LANGUAGE_CODE='en-us'):
            s, e = get_datetime_ranges(
                datetime.datetime(2015, 4, 29, 15, 4),
                GRANULARITY_WEEK,
            )
            self.assertEqual(s, datetime.datetime(2015, 4, 26, 0, 0, 0, 0))
            self.assertEqual(e, datetime.datetime(2015, 5, 2, 23, 59, 59, 0))

        with self.settings(LANGUAGE_CODE='fr-fr'):
            s, e = get_datetime_ranges(
                datetime.datetime(2015, 4, 29, 17, 55),
                GRANULARITY_WEEK,
            )
            self.assertEqual(s, datetime.datetime(2015, 4, 27, 0, 0, 0, 0))
            self.assertEqual(e, datetime.datetime(2015, 5, 3, 23, 59, 59, 0))

        with self.settings(LANGUAGE_CODE='fr-fr'):
            s, e = get_datetime_ranges(
                datetime.datetime(2015, 7, 13, 17, 14), GRANULARITY_WEEK
            )
            self.assertEqual(s, datetime.datetime(2015, 7, 13, 0, 0, 0, 0))
            self.assertEqual(e, datetime.datetime(2015, 7, 19, 23, 59, 59, 0))