Exemplo n.º 1
0
 def set_last_used(self, request: HttpRequest, queryset: QuerySet) -> None:
     """Set the last used date of selected accounts"""
     if request.user.has_perm("payments.change_bankaccount"):
         updated = services.update_last_used(queryset)
         _show_message(
             self,
             request,
             updated,
             message=_("Successfully updated %(count)d %(items)s."),
             error=_("The selected account(s) could not be updated."),
         )
Exemplo n.º 2
0
    def test_update_last_used(self):
        BankAccount.objects.create(
            owner=self.member,
            initials="J",
            last_name="Test",
            iban="NL91ABNA0417164300",
            mandate_no="11-1",
            valid_from=timezone.now().date() - timezone.timedelta(days=2000),
            valid_until=timezone.now().date() - timezone.timedelta(days=1500),
            signature="base64,png",
        )
        BankAccount.objects.create(
            owner=self.member,
            initials="J",
            last_name="Test",
            iban="NL91ABNA0417164300",
            mandate_no="11-2",
            valid_from=timezone.now().date() - timezone.timedelta(days=5),
            last_used=timezone.now().date() - timezone.timedelta(days=5),
            signature="base64,png",
        )

        self.assertEqual(services.update_last_used(BankAccount.objects), 1)

        self.assertEqual(
            BankAccount.objects.filter(mandate_no="11-2").first().last_used,
            timezone.now().date(),
        )

        self.assertEqual(
            services.update_last_used(
                BankAccount.objects,
                timezone.datetime(year=2018, month=12, day=12)),
            1,
        )

        self.assertEqual(
            BankAccount.objects.filter(mandate_no="11-2").first().last_used,
            timezone.datetime(year=2018, month=12, day=12).date(),
        )