From 3be1c46daf921ec66ef8c5634358fcd8eabdf35e Mon Sep 17 00:00:00 2001
From: Bram Sedana Wehantouw <bram.sedana@ui.ac.id>
Date: Sat, 12 Oct 2019 23:51:07 +0700
Subject: [PATCH] 1606824502 72 Added new field to vacancy

---
 assets/js/CreateVacancy.jsx                   |  2 +
 .../js/__test__/components/Vacancy-test.jsx   |  4 +
 .../__test__/components/VacancyList-test.jsx  | 16 ++++
 assets/js/components/CompanyVacancy.jsx       |  1 +
 assets/js/components/Vacancy.jsx              |  4 +
 ...benefits.py => 0002_auto_20191012_2328.py} |  8 +-
 core/models/vacancies.py                      |  1 +
 core/serializers/vacancies.py                 |  6 +-
 core/tests/test_create_vacancies.py           | 90 ++++++++++++-------
 core/tests/test_vacancies.py                  | 45 +++++-----
 core/views/vacancies.py                       |  5 +-
 11 files changed, 123 insertions(+), 59 deletions(-)
 rename core/migrations/{0002_vacancy_benefits.py => 0002_auto_20191012_2328.py} (60%)

diff --git a/assets/js/CreateVacancy.jsx b/assets/js/CreateVacancy.jsx
index d60ea5ca..92511abc 100644
--- a/assets/js/CreateVacancy.jsx
+++ b/assets/js/CreateVacancy.jsx
@@ -102,6 +102,7 @@ export default class CreateVacancy extends React.Component {
     data.salary = this.state.salary;
     data.open_time = this.state.open_time.format();
     data.close_time = this.state.close_time.format();
+    data.max_accepted_applicants = this.state.max_accepted_applicants;
     data.working_period = this.state.working_period;
     if (!this.state.vacancyId) {
       data.company = this.state.company.id;
@@ -140,6 +141,7 @@ export default class CreateVacancy extends React.Component {
             <CKEditor value={this.state.responsibilities} onChange={this.handleResponsibilities} /> }
           <script>CKEDITOR.replace( 'responsibilities' );</script>
           <br />
+          <Form.Field label="Jumlah yang Diterima" name="max_accepted_applicants" control={Input} onChange={this.handleChange} value={this.state.max_accepted_applicants} required />
           <label htmlFor="benefits"> <b> Keuntungan </b> </label>
           { !this.state.loading && <CKEditor value={this.state.benefits} onChange={this.handleBenefits} /> }
           <script>CKEDITOR.replace( 'benefits' );</script>  
diff --git a/assets/js/__test__/components/Vacancy-test.jsx b/assets/js/__test__/components/Vacancy-test.jsx
index ccebc277..15222c19 100755
--- a/assets/js/__test__/components/Vacancy-test.jsx
+++ b/assets/js/__test__/components/Vacancy-test.jsx
@@ -25,6 +25,8 @@ describe('Vacancy', () => {
     updated: '2017-03-28T07:34:13.122093Z',
     working_period: 'Juli-Agustus',
     verified: true,
+    max_accepted_applicants: 3,
+    total_accepted_applicants: 0,
   };
 
   const response2 = {
@@ -46,6 +48,8 @@ describe('Vacancy', () => {
     updated: '2017-03-28T07:34:13.122093Z',
     working_period: 'Oktober-Desember',
     verified: true,
+    max_accepted_applicants: 3,
+    total_accepted_applicants: 0,
   };
 
   const studentUser = {
diff --git a/assets/js/__test__/components/VacancyList-test.jsx b/assets/js/__test__/components/VacancyList-test.jsx
index 3e79c55f..c3dce105 100644
--- a/assets/js/__test__/components/VacancyList-test.jsx
+++ b/assets/js/__test__/components/VacancyList-test.jsx
@@ -148,6 +148,8 @@ describe('VacancyList', () => {
       status: 0,
       bookmarked: false,
       id: 4,
+      max_accepted_applicants: 3,
+      total_accepted_applicants: 0,
       working_period: 'Juli-Agustus',
     },
     {
@@ -182,6 +184,8 @@ describe('VacancyList', () => {
       status: 1,
       bookmarked: false,
       id: 4,
+      max_accepted_applicants: 3,
+      total_accepted_applicants: 0,
       working_period: 'Juli-Agustus',
     },
     {
@@ -216,6 +220,8 @@ describe('VacancyList', () => {
       status: 2,
       bookmarked: true,
       id: 4,
+      max_accepted_applicants: 3,
+      total_accepted_applicants: 0,
       working_period: 'Juli-Agustus',
     },
     {
@@ -250,6 +256,8 @@ describe('VacancyList', () => {
       status: 3,
       bookmarked: true,
       id: 4,
+      max_accepted_applicants: 3,
+      total_accepted_applicants: 0,
       working_period: 'Juli-Agustus',
     },
     {
@@ -284,6 +292,8 @@ describe('VacancyList', () => {
       status: 4,
       bookmarked: true,
       id: 4,
+      max_accepted_applicants: 3,
+      total_accepted_applicants: 0,
       working_period: 'Juli-Agustus',
     },
   ];
@@ -306,6 +316,8 @@ describe('VacancyList', () => {
     open_time: '2017-03-28T05:55:38Z',
     updated: '2017-03-28T07:34:13.122093Z',
     verified: true,
+    max_accepted_applicants: 3,
+    total_accepted_applicants: 0,
     working_period: 'Juli-Agustus',
   }, {
       salary: '1',
@@ -325,6 +337,8 @@ describe('VacancyList', () => {
     open_time: '2017-03-28T05:55:38Z',
     updated: '2017-03-28T07:34:13.122093Z',
     verified: true,
+    max_accepted_applicants: 3,
+    total_accepted_applicants: 0,
     working_period: 'Juli-Agustus',
   }];
 
@@ -346,6 +360,8 @@ describe('VacancyList', () => {
     open_time: '2017-03-28T05:55:38Z',
     updated: '2017-03-28T07:34:13.122093Z',
     verified: true,
+    max_accepted_applicants: 3,
+    total_accepted_applicants: 0,
     working_period: 'Juli-Agustus',
   }];
 
diff --git a/assets/js/components/CompanyVacancy.jsx b/assets/js/components/CompanyVacancy.jsx
index c986fc28..07e1413f 100755
--- a/assets/js/components/CompanyVacancy.jsx
+++ b/assets/js/components/CompanyVacancy.jsx
@@ -37,6 +37,7 @@ export default class CompanyVacancy extends React.Component {
             <Grid.Column floated="left">
               <p>{ this.state.count } Pendaftar<br/>
               { this.state.countNew } Pendaftar Baru<br/><br/>
+              { this.props.data.total_accepted_applicants } / {this.props.data.max_accepted_applicants } Diterima<br/>
               Ditutup {moment(moment(this.props.data.close_time)).fromNow()}</p>
             </Grid.Column>
             <Grid.Column floated="right">
diff --git a/assets/js/components/Vacancy.jsx b/assets/js/components/Vacancy.jsx
index 704349f0..597139de 100644
--- a/assets/js/components/Vacancy.jsx
+++ b/assets/js/components/Vacancy.jsx
@@ -139,6 +139,10 @@ export default class Vacancy extends React.Component {
                 { this.props.data.company.address }<br />
                 { this.props.data.working_period}<br />
                 { this.state.count } orang telah mendaftar!<br />
+                <b>
+                  { this.props.data.total_accepted_applicants }
+                  / { this.props.data.max_accepted_applicants }
+                  diterima </b><br />
                 <b>{`Ditutup ${moment(moment(this.props.data.close_time)).fromNow()}`}</b><br />
                 Rp. { this.props.data.salary } <br />
                 <b>{this.props.data.apply_before}</b>
diff --git a/core/migrations/0002_vacancy_benefits.py b/core/migrations/0002_auto_20191012_2328.py
similarity index 60%
rename from core/migrations/0002_vacancy_benefits.py
rename to core/migrations/0002_auto_20191012_2328.py
index a519fdf9..ee3e65f4 100644
--- a/core/migrations/0002_vacancy_benefits.py
+++ b/core/migrations/0002_auto_20191012_2328.py
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# Generated by Django 1.11.17 on 2019-10-12 15:05
+# Generated by Django 1.11.17 on 2019-10-12 16:28
 from __future__ import unicode_literals
 
 from django.db import migrations, models
@@ -17,4 +17,10 @@ class Migration(migrations.Migration):
             name='benefits',
             field=models.TextField(blank=True),
         ),
+        migrations.AddField(
+            model_name='vacancy',
+            name='max_accepted_applicants',
+            field=models.IntegerField(default=3),
+            preserve_default=False,
+        ),
     ]
diff --git a/core/models/vacancies.py b/core/models/vacancies.py
index 5444e59a..bd3149ba 100644
--- a/core/models/vacancies.py
+++ b/core/models/vacancies.py
@@ -16,6 +16,7 @@ class Vacancy(models.Model):
     updated = models.DateTimeField(auto_now=True)
     name = models.CharField(max_length=100, null=False)
     amount = models.IntegerField(null=True)
+    max_accepted_applicants = models.IntegerField()
     benefits = models.TextField(blank=True)
     working_period = models.CharField(max_length=100, null=True)
     tag = models.TextField(blank=True)
diff --git a/core/serializers/vacancies.py b/core/serializers/vacancies.py
index 5dc7b409..518a3e8a 100644
--- a/core/serializers/vacancies.py
+++ b/core/serializers/vacancies.py
@@ -9,7 +9,11 @@ class VacancySerializer(serializers.ModelSerializer):
     company = CompanySerializer()
     status = serializers.SerializerMethodField('_get_app_status')
     bookmarked = serializers.SerializerMethodField('_get_bookmarked_status')
+    total_accepted_applicants = serializers.SerializerMethodField('_get_total_accepted_applicants')
 
+    def _get_total_accepted_applicants(self, instance):
+        return len(Application.objects.filter(vacancy = instance, status = 4))
+    
     def _get_app_status(self, instance):
         try:
             request = self.context.get("request")
@@ -33,7 +37,7 @@ class VacancySerializer(serializers.ModelSerializer):
     class Meta:
         model = Vacancy
         fields = ['company', 'verified', 'open_time', 'description', 'close_time', 'created','apply_before', 'updated', 'name', \
-                  'status', 'bookmarked', 'id', 'salary', 'responsibilities', 'requirements','working_period', 'benefits']
+                  'status', 'bookmarked', 'id', 'salary', 'responsibilities', 'requirements','working_period', 'benefits', 'max_accepted_applicants', 'total_accepted_applicants']
 
 def name_position_validator(names):
     for name in names.split(" "):
diff --git a/core/tests/test_create_vacancies.py b/core/tests/test_create_vacancies.py
index 491e7f63..9e7dfd4f 100644
--- a/core/tests/test_create_vacancies.py
+++ b/core/tests/test_create_vacancies.py
@@ -23,7 +23,8 @@ class CreateAndUpdateVacancyTest(APITestCase):
 
         url = '/api/vacancies/'
         response = self.client.post(url, {'company': new_company.pk, 'open_time': self.today,
-        	 'close_time': self.tomorrow, 'name': 'new vacancy', 'description': 'new_vacancy', 'requirements': 'new_vacancy', 'working_period':'3 Bulan'}, format='json')
+        	 'close_time': self.tomorrow, 'name': 'new vacancy', 'description': 'new_vacancy	', 'requirements': 'new_vacancy',
+             'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_200_OK)
 
         vacancies = Vacancy.objects.count()
@@ -38,7 +39,8 @@ class CreateAndUpdateVacancyTest(APITestCase):
         url = '/api/vacancies/'
         response = self.client.post(url, {'company': new_company.pk, 'open_time': self.today,
                                           'close_time': self.tomorrow, 'name': 'new vacancy',
-                                          'description': 'new_vacancy	', 'amount': 10, 'requirements': 'new_vacancy', 'working_period':'3 Bulan'}, format='json')
+                                          'description': 'new_vacancy	', 'amount': 10, 'requirements': 'new_vacancy',
+                                          'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_200_OK)
 
         vacancy = Vacancy.objects.first()
@@ -54,7 +56,8 @@ class CreateAndUpdateVacancyTest(APITestCase):
         url = '/api/vacancies/'
         response = self.client.post(url, {'company': new_company.pk, 'open_time': self.today,
                                           'close_time': self.tomorrow, 'name': 'new vacancy',
-                                          'description': 'new_vacancy	', 'amount': 10, 'responsibilities': 'new_vacancy', 'requirements':'new_vacancy', 'working_period':'3 Bulan'}, format='json')
+                                          'description': 'new_vacancy	', 'amount': 10, 'responsibilities': 'new_vacancy', 'requirements':'new_vacancy',
+                                          'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_200_OK)
 
         vacancy = Vacancy.objects.first()
@@ -69,7 +72,8 @@ class CreateAndUpdateVacancyTest(APITestCase):
         url = '/api/vacancies/'
         response = self.client.post(url, {'company': new_company.pk, 'open_time': self.today,
                                           'close_time': self.tomorrow, 'name': 'new vacancy',
-                                          'description': 'new_vacancy   ', 'amount': 10, 'benefits':'new_vacancy', 'requirements': 'new_vacancy', 'working_period':'3 Bulan'}, format='json')
+                                          'description': 'new_vacancy   ', 'amount': 10, 'benefits':'new_vacancy', 'requirements': 'new_vacancy',
+                                          'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         print(response)
         self.assertEqual(response.status_code, status.HTTP_200_OK)
 
@@ -84,7 +88,8 @@ class CreateAndUpdateVacancyTest(APITestCase):
 
         url = '/api/vacancies/'
         response = self.client.post(url, {'company': new_company.pk, 'open_time': self.today,
-        	 'close_time': self.yesterday, 'name': 'new_vacancy', 'description': 'new_vacancy', 'responsibilities': 'new_vacancy', 'requirements': 'new_vacancy', 'working_period':'3 Bulan'}, format='json')
+        	 'close_time': self.yesterday, 'name': 'new_vacancy', 'description': 'new_vacancy', 'responsibilities': 'new_vacancy', 'requirements': 'new_vacancy',
+             'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 
         vacancies = Vacancy.objects.count()
@@ -99,7 +104,8 @@ class CreateAndUpdateVacancyTest(APITestCase):
         url = '/api/vacancies/'
         response = self.client.post(url, {'company': new_company.pk, 'open_time': self.today,
                                           'close_time': self.tomorrow, 'name': 'new_vacancy',
-                                          'description': 'new_vacancy	', 'amount': 'sepuluh', 'salary':'dua juta', 'requirements': 'new_vacancy', 'working_period':'3 Bulan'}, format='json')
+                                          'description': 'new_vacancy	', 'amount': 'sepuluh', 'salary':'dua juta', 'requirements': 'new_vacancy', 
+                                          'max_accepted_applicants':3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 
         vacancies_count = Vacancy.objects.count()
@@ -114,7 +120,8 @@ class CreateAndUpdateVacancyTest(APITestCase):
         url = '/api/vacancies/'
         response = self.client.post(url, {'company': new_company.pk, 'open_time': self.today,
                                           'close_time': self.tomorrow, 'name': 'new_vacancy',
-                                          'description': 'new_vacancy   ', 'amount': 'sepuluh', 'benefits':'new_vacancy', 'working_period':'3 Bulan'}, format='json')
+                                          'description': 'new_vacancy   ', 'amount': 'sepuluh', 'benefits':'new_vacancy',
+                                          'max_accepted_applicants':3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 
         vacancies_count = Vacancy.objects.count()
@@ -127,11 +134,12 @@ class CreateAndUpdateVacancyTest(APITestCase):
         self.client.force_authenticate(user=superuser)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time= self.today,
-                                              description="lalala", close_time= self.tomorrow, name='new_company')
+                                              description="lalala", close_time= self.tomorrow, name='new_company', max_accepted_applicants=3)
 
         url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
         response = self.client.patch(url, {'open_time': self.today, 'close_time': self.tomorrow,
-        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'responsibilities': 'new_vacancy2', 'requirements': 'new_vacancy2', 'working_period':'3 Bulan'}, format='json')
+        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'responsibilities': 'new_vacancy2', 'requirements': 'new_vacancy2',
+            'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_200_OK)
 
     def test_update_vacancy_with_amount_salary_success(self):
@@ -141,11 +149,12 @@ class CreateAndUpdateVacancyTest(APITestCase):
         self.client.force_authenticate(user=superuser)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time= self.today,
-                                              description="lalala", close_time= self.tomorrow, name='new_company')
+                                              description="lalala", close_time= self.tomorrow, name='new_company', max_accepted_applicants=3)
 
         url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
         response = self.client.patch(url, {'open_time': self.today, 'close_time': self.tomorrow,
-        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 10, 'salary': 2, 'responsibilities': 'new_vacancy2', 'requirements': 'new_vacancy2', 'working_period':'3 Bulan'}, format='json')
+        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 10, 'salary': 2, 'responsibilities': 'new_vacancy2', 'requirements': 'new_vacancy2',
+            'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_200_OK)
 
         vacancy = Vacancy.objects.first()
@@ -158,10 +167,10 @@ class CreateAndUpdateVacancyTest(APITestCase):
         self.client.force_authenticate(user=superuser)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time=self.today,
-                                              description="lalala", close_time=self.tomorrow, name='new_company')
+                                              description="lalala", close_time=self.tomorrow, name='new_company', max_accepted_applicants=3)
 
         url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
-        response = self.client.patch(url, {'open_time': self.today, 'close_time': self.tomorrow, 'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 10, 'benefits':'new_vacancy2', 'responsibilities': 'new_vacancy2', 'requirements': 'new_vacancy', 'working_period':'3 Bulan'}, format='json')
+        response = self.client.patch(url, {'open_time': self.today, 'close_time': self.tomorrow, 'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 10, 'benefits':'new_vacancy2', 'responsibilities': 'new_vacancy2', 'requirements': 'new_vacancy', 'working_period':'3 Bulan', 'max_accepted_applicants': 3}, format='json')
         self.assertEqual(response.status_code, status.HTTP_200_OK)
 
         vacancy = Vacancy.objects.first()
@@ -175,11 +184,12 @@ class CreateAndUpdateVacancyTest(APITestCase):
         self.client.force_authenticate(user=superuser)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time= self.today,
-                                              description="lalala", close_time=self.tomorrow, name='new_company')
+                                              description="lalala", close_time=self.tomorrow, name='new_company', max_accepted_applicants=3)
 
         url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
         response = self.client.patch(url, {'open_time': self.today, 'close_time': self.tomorrow,
-        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 10, 'responsibilities': 'new_vacancy2', 'requirements': 'new_vacancy2', 'working_period':'3 Bulan'}, format='json')
+        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 10, 'responsibilities': 'new_vacancy2', 'requirements': 'new_vacancy2',
+            'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_200_OK)
 
         vacancy = Vacancy.objects.first()
@@ -192,11 +202,12 @@ class CreateAndUpdateVacancyTest(APITestCase):
         self.client.force_authenticate(user=superuser)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time= self.today,
-                                              description="lalala", close_time= self.tomorrow, name='new_company')
+                                              description="lalala", close_time= self.tomorrow, name='new_company', max_accepted_applicants=3)
 
         url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
         response = self.client.patch(url, {'open_time': self.today, 'close_time': self.yesterday,
-        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'responsibilities': 'new_vacancy2', 'requirements': 'new_vacancy2', 'working_period':'3 Bulan'}, format='json')
+        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'responsibilities': 'new_vacancy2', 'requirements': 'new_vacancy2',
+            'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 
     def test_update_vacancy_with_amount_salary_string_failed(self):
@@ -206,11 +217,13 @@ class CreateAndUpdateVacancyTest(APITestCase):
         self.client.force_authenticate(user=superuser)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time= self.today,
-                                              description="lalala", close_time= self.tomorrow, name='new_company')
+                                              description="lalala", close_time= self.tomorrow, name='new_company',
+                                              max_accepted_applicants=3)
 
         url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
         response = self.client.patch(url, {'open_time': self.today, 'close_time': self.yesterday,
-        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 'sepuluh', 'salary': 'dua juta', 'requirements': 'new_vacancy', 'working_period':'3 Bulan'}, format='json')
+        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 'sepuluh', 'salary': 'dua juta', 'requirements': 'new_vacancy',
+            'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 
         vacancy = Vacancy.objects.first()
@@ -224,7 +237,8 @@ class CreateAndUpdateVacancyTest(APITestCase):
         
         url = '/api/vacancies/'
         response = self.client.post(url, {'company': new_company.pk, 'open_time': self.today,
-        	 'close_time': self.today, 'name': 'new_vacancy', 'description': 'new_vacancy', 'working_period':'3 Bulan'}, format='json')
+        	 'close_time': self.today, 'name': 'new_vacancy', 'description': 'new_vacancy',
+             'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         
         self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 
@@ -239,7 +253,8 @@ class CreateAndUpdateVacancyTest(APITestCase):
 
         url = '/api/vacancies/'
         response = self.client.post(url, {'company': new_company.pk, 'open_time': datetime.fromtimestamp(0),
-        	 'close_time': datetime.fromtimestamp(0), 'name': 'new_vacancy', 'description': 'new_vacancy', 'working_period':'3 Bulan'}, format='json')
+        	 'close_time': datetime.fromtimestamp(0), 'name': 'new_vacancy', 'description': 'new_vacancy',
+             'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
 
         self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 
@@ -253,11 +268,13 @@ class CreateAndUpdateVacancyTest(APITestCase):
         self.client.force_authenticate(user=superuser)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time= self.today,
-                                              description="lalala", close_time= self.tomorrow, name='new_company')
+                                              description="lalala", close_time= self.tomorrow, name='new_company',
+                                              max_accepted_applicants=3)
 
         url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
         response = self.client.patch(url, {'open_time': self.today, 'close_time': self.today,
-        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'requirements': 'new_vacancy2', 'working_period':'3 Bulan'}, format='json')
+        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'requirements': 'new_vacancy2',
+            'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
 
         self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 
@@ -268,12 +285,13 @@ class CreateAndUpdateVacancyTest(APITestCase):
         self.client.force_authenticate(user=superuser)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time= self.today,
-                                              description="lalala", close_time= self.tomorrow, name='new_company')
+                                              description="lalala", close_time= self.tomorrow, name='new_company', max_accepted_applicants=3)
 
         url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
 
         response = self.client.patch(url, {'open_time': datetime.fromtimestamp(0), 'close_time': datetime.fromtimestamp(0),
-        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 'sepuluh', 'requirements': 'new_vacancy2', 'working_period':'3 Bulan'}, format='json')
+        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 'sepuluh', 'requirements': 'new_vacancy2',
+            'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 
         vacancy = Vacancy.objects.first()
@@ -286,10 +304,10 @@ class CreateAndUpdateVacancyTest(APITestCase):
         self.client.force_authenticate(user=superuser)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time=self.today,
-                                              description="lalala", close_time=self.tomorrow, name='new_company')
+                                              description="lalala", close_time=self.tomorrow, name='new_company', max_accepted_applicants=3)
 
         url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
-        response = self.client.patch(url, {'open_time': self.today, 'close_time': self.tomorrow,'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 'sepuluh', 'benefits':'new_vacancy2', 'requirements': 'new_vacancy', 'working_period':'3 Bulan'}, format='json')
+        response = self.client.patch(url, {'open_time': self.today, 'close_time': self.tomorrow,'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 'sepuluh', 'benefits':'new_vacancy2', 'requirements': 'new_vacancy', 'working_period':'3 Bulan', 'max_accepted_applicants': 3}, format='json')
         self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 
         vacancy = Vacancy.objects.first()
@@ -302,11 +320,12 @@ class CreateAndUpdateVacancyTest(APITestCase):
         self.client.force_authenticate(user=superuser)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time= self.today,
-                                              description="lalala", close_time= self.tomorrow, name='new_company')
+                                              description="lalala", close_time= self.tomorrow, name='new_company', max_accepted_applicants=3)
 
         url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
         response = self.client.patch(url, {'open_time': self.today, 'close_time': self.tomorrow,
-        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'responsibilities': 'new_vacancy2', 'amount': 'sepuluh', 'requirements': 'new_vacancy2', 'working_period':'3 Bulan'}, format='json')
+        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'responsibilities': 'new_vacancy2', 'amount': 'sepuluh', 'requirements': 'new_vacancy2',
+            'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 
         vacancy = Vacancy.objects.first()
@@ -320,7 +339,8 @@ class CreateAndUpdateVacancyTest(APITestCase):
 
         url = '/api/vacancies/'
         response = self.client.post(url, {'company': new_company.pk, 'open_time': self.yesterday,
-        	 'close_time': self.today, 'name': 'new_vacancy', 'description': 'new_vacancy', 'responsibilities': 'new_vacancy', 'requirements': 'new_vacancy', 'working_period':'3 Bulan'}, format='json')
+        	 'close_time': self.today, 'name': 'new_vacancy', 'description': 'new_vacancy', 'responsibilities': 'new_vacancy', 'requirements': 'new_vacancy',
+             'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 
         vacancies = Vacancy.objects.count()
@@ -333,11 +353,12 @@ class CreateAndUpdateVacancyTest(APITestCase):
         self.client.force_authenticate(user=superuser)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time= self.today,
-                                              description="lalala", close_time= self.tomorrow, name='new_company')
+                                              description="lalala", close_time= self.tomorrow, name='new_company', max_accepted_applicants=3)
 
         url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
         response = self.client.patch(url, {'open_time': self.yesterday, 'close_time': self.today,
-        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'responsibilities': 'new_vacancy2', 'requirements': 'new_vacancy2','working_period':'3 Bulan'}, format='json')
+        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'responsibilities': 'new_vacancy2', 'requirements': 'new_vacancy2',
+            'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 
     def test_new_vacancy_with_tag(self):
@@ -350,11 +371,12 @@ class CreateAndUpdateVacancyTest(APITestCase):
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time= self.today,
                                               description="lalala", close_time=self.tomorrow, name='new_company',
-                                              tag=VACANCY_TAG, working_period="3 Bulan")
+                                              tag=VACANCY_TAG, max_accepted_applicants=3, working_period="3 Bulan")
 
         url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
         response = self.client.patch(url, {'open_time': self.today, 'close_time': self.tomorrow,
-        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 10, 'responsibilities': 'new_vacancy2', 'requirements': 'new_vacancy2','working_period':'3 Bulan'}, format='json')
+        	'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 10, 'responsibilities': 'new_vacancy2', 'requirements': 'new_vacancy2',
+            'max_accepted_applicants': 3, 'working_period':'3 Bulan'}, format='json')
         self.assertEqual(response.status_code, status.HTTP_200_OK)
 
         vacancy = Vacancy.objects.first()
diff --git a/core/tests/test_vacancies.py b/core/tests/test_vacancies.py
index d43c2588..07a0f67e 100755
--- a/core/tests/test_vacancies.py
+++ b/core/tests/test_vacancies.py
@@ -112,7 +112,7 @@ class ApplicationTests(APITestCase):
         new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                              address=None)
         new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
-                                             description="lalala",working_period="3 Bulan", requirements= "requirements", close_time=(timezone.now() + timedelta(days=1)))
+                                             description="lalala", max_accepted_applicants=3, working_period="3 Bulan", requirements= "requirements", close_time=(timezone.now() + timedelta(days=1)))
 
         url = '/api/students/' + str(student_id) + '/applied-vacancies/'
         response = self.client.post(url, {'vacancy_id': new_vacancy.pk, 'cover_letter': 'this is a cover letter.'},
@@ -135,7 +135,7 @@ class ApplicationTests(APITestCase):
         new_student = Student.objects.create(user=new_user2, npm=1234123412)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
-                                             description="lalala",working_period="3 Bulan" ,close_time=datetime.today())
+                                             description="lalala", close_time=datetime.today(), max_accepted_applicants=3, working_period="3 Bulan")
 
         application = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="lorem ipsum")
 
@@ -157,7 +157,7 @@ class ApplicationTests(APITestCase):
                                              address=None)
         new_student = Student.objects.create(user=new_user2, npm=1234123412)
         new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
-                                             description="lalala", working_period="3 Bulan",close_time=datetime.today())
+                                             description="lalala", close_time=datetime.today(), max_accepted_applicants=3, working_period="3 Bulan")
 
         url = '/api/applications/' + str(new_vacancy.pk) + '/count/'
 
@@ -196,7 +196,7 @@ class ApplicationTests(APITestCase):
         new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                              address=None)
         new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
-                                             description="lalala", working_period="3 Bulan",close_time=(timezone.now() - timedelta(days=1)))
+                                             description="lalala", close_time=(timezone.now() - timedelta(days=1)), max_accepted_applicants=3, working_period="3 Bulan")
         url = '/api/students/' + str(student_id) + '/applied-vacancies/'
         response = self.client.post(url, {'vacancy_id': new_vacancy.pk, 'cover_letter': 'this is a cover letter.'},
                                     format='json')
@@ -308,7 +308,7 @@ class BookmarkApplicationTests(APITestCase):
         new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                              address=None)
         new_vacancy = Vacancy.objects.create(company=new_company, verified=True, requirements= "requirements", open_time=datetime.fromtimestamp(1541319300.0),
-                                             description="lalala", working_period="3 Bulan",close_time=timezone.now())
+                                             description="lalala", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
 
         url = '/api/students/' + str(student_id) + '/bookmarked-vacancies/'
         response = self.client.post(url, {'vacancy_id': new_vacancy.pk}, format='json')
@@ -332,8 +332,8 @@ class VacancyTest(APITestCase):
     def test_search_vacancy(self, m):
         superuser = User.objects.create_user('dummy.company', 'dummy.company@company.com', 'lalala123')
         company = Company.objects.create(user=superuser, description="This is a test company")
-        Vacancy.objects.create(company=company, open_time=datetime.now(), close_time=datetime.now(), name="Software Engineer",working_period="3 Bulan")
-        Vacancy.objects.create(company=company, open_time=datetime.now(), close_time=datetime.now(), name="Data Engineer",working_period="3 Bulan")
+        Vacancy.objects.create(company=company, open_time=datetime.now(), close_time=datetime.now(), name="Software Engineer", max_accepted_applicants=3, working_period="3 Bulan")
+        Vacancy.objects.create(company=company, open_time=datetime.now(), close_time=datetime.now(), name="Data Engineer", max_accepted_applicants=3, working_period="3 Bulan")
         m.get('https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG',
               json={"username": 'dummy.mahasiswa', "role": 'mahasiswa', "identity_number": '1234567890'},
               status_code=200)
@@ -389,9 +389,9 @@ class VacancyTest(APITestCase):
         open_time = datetime(2019, 10, 20)
         close_time = datetime(2019, 12, 20)
         vacancy1 = Vacancy.objects.create(company=new_company, verified=True, open_time=open_time,
-                                            description='', close_time=close_time, name='vacancy1',working_period="3 Bulan")
+                                            description='', close_time=close_time, name='vacancy1', max_accepted_applicants=3, working_period="3 Bulan")
         vacancy2 = Vacancy.objects.create(company=new_company2, verified=True, open_time=open_time,
-                                            description='', close_time=close_time, name='vacancy2',working_period="3 Bulan")
+                                            description='', close_time=close_time, name='vacancy2', max_accepted_applicants=3, working_period="3 Bulan")
         url = '/api/vacancies/?company={}&company={}'.format(new_company.id, new_company2.id)
         response = self.client.get(url, format='json')
         vacancies = Vacancy.objects.filter(company__id__in=[new_company.id, new_company2.id])
@@ -451,7 +451,7 @@ class VacancyTest(APITestCase):
         new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                              address=None)
         new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
-                                             description="expired vacancy", close_time=datetime.fromtimestamp(1541319301.0),working_period="3 Bulan")
+                                             description="expired vacancy", close_time=datetime.fromtimestamp(1541319301.0), max_accepted_applicants=3, working_period="3 Bulan")
 
         url = '/api/vacancies/?opened_only=true'
         response = self.client.get(url, format='json')
@@ -478,7 +478,8 @@ class VacancyTest(APITestCase):
                                              address=None)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
-                                             description="lalala", close_time=timezone.now() + timedelta(minutes = 10),working_period="3 Bulan")
+                                             description="lalala", close_time=timezone.now() + timedelta(minutes = 10),
+                                             max_accepted_applicants=3, working_period="3 Bulan")
         self.client.force_authenticate(user=superuser)
 
         response = new_vacancy.apply_before
@@ -562,7 +563,7 @@ class CompanyListsTests(APITestCase):
         new_student = Student.objects.create(user=new_user2, npm=1234123412)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
-                                             description="lalala", requirements= "requirements", close_time=timezone.now(),working_period="3 Bulan")
+                                             description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
         new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
 
         self.client.force_authenticate(new_user)
@@ -580,7 +581,7 @@ class CompanyListsTests(APITestCase):
         new_student = Student.objects.create(user=new_user2, npm=1234123412)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
-                                             description="lalala", requirements= "requirements", close_time=timezone.now(),working_period="3 Bulan")
+                                             description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
         new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
 
         new_user3 = User.objects.create_user('dummy.company4', 'dummy.company4@company.com', 'lalala123')
@@ -602,7 +603,7 @@ class CompanyListsTests(APITestCase):
         new_student = Student.objects.create(user=new_user2, npm=1234123412)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
-                                             description="lalala", requirements= "requirements", close_time=timezone.now(),working_period="3 Bulan")
+                                             description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
         new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
 
         new_user3 = User.objects.create_user('dummy.company4', 'dummy.company4@company.com', 'lalala123')
@@ -624,7 +625,7 @@ class CompanyListsTests(APITestCase):
         new_student = Student.objects.create(user=new_user2, npm=1234123412)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
-                                             description="lalala", requirements= "requirements", close_time=timezone.now(),working_period="3 Bulan")
+                                             description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
         new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
 
         self.client.force_authenticate(new_user)
@@ -642,7 +643,7 @@ class CompanyListsTests(APITestCase):
         new_student = Student.objects.create(user=new_user2, npm=1234123412)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
-                                             description="lalala", requirements= "requirements", close_time=timezone.now(),working_period="3 Bulan")
+                                             description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
         new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
 
         self.client.force_authenticate(new_user)
@@ -661,7 +662,7 @@ class CompanyListsTests(APITestCase):
         new_student = Student.objects.create(user=new_user2, npm=1234123412)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
-                                             description="lalala", requirements= "requirements", close_time=timezone.now(),working_period="3 Bulan")
+                                             description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
         new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
 
         self.client.force_authenticate(new_user)
@@ -680,7 +681,7 @@ class CompanyListsTests(APITestCase):
         new_student = Student.objects.create(user=new_user2, npm=1234123412)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
-                                             description="lalala", requirements= "requirements", close_time=timezone.now(),working_period="3 Bulan")
+                                             description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3, working_period="3 Bulan")
         new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
 
         self.client.force_authenticate(new_user)
@@ -730,7 +731,7 @@ class SupervisorApprovalTests(APITestCase):
         new_company2 = Company.objects.create(user=new_user2, description="lalala", status=Company.VERIFIED, logo=None,
                                               address=None)
         new_vacancy2 = Vacancy.objects.create(company=new_company2, verified=False, open_time=datetime.fromtimestamp(1541319300.0),
-                                              description="lalala", requirements= "requirements", close_time=timezone.now())
+                                              description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3)
 
         url = '/api/vacancies/' + str(new_vacancy2.pk) + '/verify/'
         response = self.client.patch(url, {'verified': True}, format='json')
@@ -746,7 +747,7 @@ class SupervisorApprovalTests(APITestCase):
         self.client.force_authenticate(user=new_user)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time=datetime.fromtimestamp(1541319300.0),
-                                             description="lalala", requirements= "requirements", close_time=timezone.now())
+                                             description="lalala", requirements= "requirements", close_time=timezone.now(), max_accepted_applicants=3)
 
         url = '/api/vacancies/' + str(new_vacancy.pk) + '/verify/'
         response = self.client.patch(url, format='json')
@@ -1006,10 +1007,10 @@ class AcceptOneOfferTests(APITestCase):
                                               address=None)
 
         new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
-                                             description="lalala", requirements= "requirements", close_time=datetime.today())
+                                             description="lalala", requirements= "requirements", close_time=datetime.today(), max_accepted_applicants=3)
 
         new_vacancy2 = Vacancy.objects.create(company=new_company2, verified=True, open_time=datetime.fromtimestamp(0),
-                                             description="lalala", requirements= "requirements", close_time=datetime.today())
+                                             description="lalala", requirements= "requirements", close_time=datetime.today(), max_accepted_applicants=3)
 
         new_user3 = User.objects.create_user('dummy.student', 'dummy.student@company.com', 'lalala123')
         new_student = Student.objects.create(user=new_user3, npm=1234123412)
diff --git a/core/views/vacancies.py b/core/views/vacancies.py
index b7f35b9d..bc4c1cd3 100644
--- a/core/views/vacancies.py
+++ b/core/views/vacancies.py
@@ -98,13 +98,14 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
             
         # if close_time < open_time:
         #     raise ValidationError('Waktu tutup lowongan harus lebih dari waktu buka lowongan!')
+        max_accepted_applicants = data['max_accepted_applicants']
         if open_time < str(datetime.today()):
             raise ValidationError('Waktu buka lowongan harus lebih dari hari ini!')
         elif close_time <= open_time:
             raise ValidationError('Waktu tutup lowongan harus lebih dari waktu buka lowongan dan tidak sama dengan waktu pembukaan lowongan!')
         elif close_time == open_time:
             raise ValidationError('Waktu tutup dan buka lowongan tidak boleh sama!')
-        vacancy = Vacancy(company=company, open_time=open_time, close_time=close_time, name=name, description=description, salary=salary, working_period=working_period, tag=tag)
+        vacancy = Vacancy(company=company, open_time=open_time, close_time=close_time, name=name, description=description, salary=salary, working_period=working_period, tag=tag, max_accepted_applicants=max_accepted_applicants)
         if 'benefits' in data:
             vacancy.benefits = data['benefits']
         if 'amount' in data:
@@ -130,6 +131,7 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
         description = data['description']
         working_period = data['working_period']
         requirements = data['requirements']
+        max_accepted_applicants = data['max_accepted_applicants']
         if open_time < str(datetime.today()):
             raise ValidationError('Waktu buka lowongan harus lebih dari hari ini!')
         elif close_time <= open_time:
@@ -141,6 +143,7 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
         vacancy.name = name
         vacancy.salary = salary
         vacancy.description = description
+        vacancy.max_accepted_applicants = max_accepted_applicants
         vacancy.working_period = working_period
         vacancy.responsibilities = data.get('responsibilities')
         if 'benefits' in data:
-- 
GitLab