Fakultas Ilmu Komputer UI

Add program end date field in cart

parent 96412075
PROGRAM_DURATION = {
"BABY_1": 30,
"BABY_3": 90,
"GOALS_1": 30,
"GOALS_3": 90,
"GOALS_6": 180,
"BALANCED_1": 30,
"BALANCED_3": 90,
"BALANCED_6": 180,
"TRIAL": 7
}
# Generated by Django 3.1 on 2021-05-31 04:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('payment', '0005_auto_20210510_2324'),
]
operations = [
migrations.AddField(
model_name='cart',
name='program_end_date',
field=models.DateField(blank=True, null=True),
),
]
......@@ -22,6 +22,7 @@ class Cart(models.Model):
)
transaction_status = models.CharField(max_length=128,\
choices=TRANSACTION_STATUS.choices, default=TRANSACTION_STATUS.UNPAID)
program_end_date = models.DateField(null=True,blank=True)
def __str__(self):
return f"{self.user} - {self.program.unique_code} - {self.nutritionist}"
import json
from unittest.mock import patch
from datetime import date, timedelta
from rest_framework.test import APITestCase
from django.test import TestCase
from rest_framework import status
from rest_framework.response import Response
from constants.transaction_status import TransactionStatus as TRANSACTION_STATUS
from constants.program_duration import PROGRAM_DURATION
from .models import Cart
from .serializers import CartSerializer
from .views import PaymentViewSet
from authentication.models import CustomUser
from dietela_quiz.models import *
from dietela_program.models import DietelaProgram
......@@ -38,8 +37,8 @@ class CartTests(APITestCase):
)
cls.dietela_program_3 = DietelaProgram.objects.create(
unique_code="PRG3",
name="Program 3",
unique_code="TRIAL",
name="One Week Trial",
price=300000.00,
)
......@@ -170,6 +169,8 @@ class CartTests(APITestCase):
response = self.client.get(url, request_params)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.cart_3.transaction_status = 'pending'
self.cart_3.program_end_date = date.today() + \
timedelta(days=PROGRAM_DURATION[self.cart_3.program.unique_code])
self.assertEqual(response.data, CartSerializer(self.cart_3).data)
self.assertEqual(DietQuestionnaire.objects.count(), 1)
self.assertEqual(DietQuestionnaire.objects.last().user, self.cart_3.user)
......
import json
import os
from datetime import timedelta, date
from rest_framework import viewsets, status
from rest_framework.response import Response
import requests
from constants.transaction_status import TransactionStatus as TRANSACTION_STATUS
from constants.string_constants import CART_NOT_FOUND_MESSAGE
from constants.program_duration import PROGRAM_DURATION
from dietela_program.serializers import DietelaProgramSerializer
from dietela_program.models import DietelaProgram
from diet_questionnaire.models import DietQuestionnaire
......@@ -119,6 +121,8 @@ class MidtransRedirectionViewSet(viewsets.ViewSet):
status=status.HTTP_400_BAD_REQUEST)
cart.transaction_status = transaction_status
cart.program_end_date = date.today() + timedelta(days=\
PROGRAM_DURATION[cart.program.unique_code])
cart.save()
DietQuestionnaire.objects.create(user=cart.user)
......
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