Fakultas Ilmu Komputer UI

Commit d96130bf authored by Glenda Emanuella Sutanto's avatar Glenda Emanuella Sutanto

Merge branch 'hotfix' into 'staging'

Display last cart + create all_carts_are_expired attribute in user serializer

See merge request !88
parents 56719bc2 637cf487
Pipeline #84173 passed with stages
in 16 minutes and 27 seconds
......@@ -26,13 +26,21 @@ class UserAuthSerializer(serializers.ModelSerializer):
result['transaction_status'] = None
result['cart_id'] = None
result['all_carts_are_expired'] = None
if instance.cart.exists():
active_carts = instance.cart.filter(program_end_date__gte=datetime.date.today())
if len(active_carts) > 0:
last_active_cart = active_carts.order_by('-id')[0]
result['transaction_status'] = last_active_cart.transaction_status
result['cart_id'] = last_active_cart.id
result['transaction_status'] = instance.cart.last().transaction_status
result['cart_id'] = instance.cart.last().id
all_carts_are_expired = True
for cart in instance.cart.all():
if cart.program_end_date is None:
continue
if cart.program_end_date >= datetime.date.today():
all_carts_are_expired = False
break
result['all_carts_are_expired'] = all_carts_are_expired
result['nutritionist'] = None
......
import json
import datetime
from unittest.mock import patch
from rest_framework import status
from rest_framework.test import APITestCase
......@@ -99,7 +100,8 @@ class UserModelTests(APITestCase):
cls.cart = Cart.objects.create(
program=cls.dietela_program,
nutritionist=cls.nutritionist,
user=cls.custom_user_1
user=cls.custom_user_1,
program_end_date=datetime.date(2021,6,28)
)
def test_create_user(self):
......
Markdown is supported
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