Fakultas Ilmu Komputer UI

Commit d761bcae authored by Rayhan Muzakki's avatar Rayhan Muzakki 💬
Browse files

Pbi9

parent 28e62449
......@@ -757,6 +757,30 @@ class UserTest(rest_framework_test.APITestCase):
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_user_transactionsort_list_success(self):
response = request(
'GET',
'user-list-sorttransaction',
http_authorization=self.superuser_http_authorization
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_user_cashsort_list_success(self):
response = request(
'GET',
'user-list-sortcash',
http_authorization=self.superuser_http_authorization
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_user_goodssort_list_success(self):
response = request(
'GET',
'user-list-sortgoods',
http_authorization=self.superuser_http_authorization
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_user_detail_success(self):
response = request(
'GET',
......
......@@ -52,6 +52,9 @@ urlpatterns = [
),
urls.path('users/', api_views.UserList.as_view(), name='user-list'),
urls.path('users/sorttransaction', api_views.UserListTransaction.as_view(), name='user-list-sorttransaction'),
urls.path('users/sortcash', api_views.UserListCash.as_view(), name='user-list-sortcash'),
urls.path('users/sortgoods', api_views.UserListGoods.as_view(), name='user-list-sortgoods'),
urls.path('users/<str:pk>/', api_views.UserDetail.as_view(), name='user-detail'),
urls.path(
'bank-account-transfer-destinations/',
......
......@@ -122,21 +122,6 @@ def validate_product_stock(cart_items):
def get_batch_transaction(transaction):
today = timezone.now().date()
transaction_batch = models.Batch.objects.filter(start_date__lte=today, end_date__gt=today).first()
if transaction_batch is None:
days_to_saturday = 5 - today.weekday()
if days_to_saturday == -1:
end_date = today + timedelta(days=6)
start_date = end_date - timedelta(days=7)
else:
end_date = today + timedelta(days=days_to_saturday)
start_date = end_date - timedelta(days=7)
transaction_batch = models.Batch.objects.create(
batch_name='Auto Batch',
start_date=start_date,
end_date=end_date,
shipping_cost=0
)
transaction_batch.save()
return transaction_batch
def get_transfer_destination(program_donation):
......
......@@ -496,6 +496,56 @@ class UserList(generics.ListCreateAPIView):
search_fields = ['username', 'full_name', 'phone_number']
serializer_class = api_serializers.UserSerializer
class UserListTransaction(generics.ListCreateAPIView):
filter_backends = [
rest_framework.DjangoFilterBackend,
rest_framework_filters.OrderingFilter,
rest_framework_filters.SearchFilter,
]
filterset_fields = ['username', 'phone_number']
ordering_fields = [
'username', 'full_name', 'phone_number',
'number_of_transactions', 'number_of_cash_donations', 'number_of_goods_donations'
]
pagination_class = paginations.SmallResultsSetPagination
permission_classes = [rest_framework_permissions.IsAdminUser]
queryset = models.User.objects.all().order_by('-number_of_transactions')
search_fields = ['username', 'full_name', 'phone_number']
serializer_class = api_serializers.UserSerializer
class UserListCash(generics.ListCreateAPIView):
filter_backends = [
rest_framework.DjangoFilterBackend,
rest_framework_filters.OrderingFilter,
rest_framework_filters.SearchFilter,
]
filterset_fields = ['username', 'phone_number']
ordering_fields = [
'username', 'full_name', 'phone_number',
'number_of_transactions', 'number_of_cash_donations', 'number_of_goods_donations'
]
pagination_class = paginations.SmallResultsSetPagination
permission_classes = [rest_framework_permissions.IsAdminUser]
queryset = models.User.objects.all().order_by('-number_of_cash_donations')
search_fields = ['username', 'full_name', 'phone_number']
serializer_class = api_serializers.UserSerializer
class UserListGoods(generics.ListCreateAPIView):
filter_backends = [
rest_framework.DjangoFilterBackend,
rest_framework_filters.OrderingFilter,
rest_framework_filters.SearchFilter,
]
filterset_fields = ['username', 'phone_number']
ordering_fields = [
'username', 'full_name', 'phone_number',
'number_of_transactions', 'number_of_cash_donations', 'number_of_goods_donations'
]
pagination_class = paginations.SmallResultsSetPagination
permission_classes = [rest_framework_permissions.IsAdminUser]
queryset = models.User.objects.all().order_by('-number_of_goods_donations')
search_fields = ['username', 'full_name', 'phone_number']
serializer_class = api_serializers.UserSerializer
class UserDetail(generics.RetrieveUpdateDestroyAPIView):
permission_classes = [
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment