diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..5c98b428844d9f7d529e2b6fb918d15bf072f3df --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/backend.iml b/.idea/backend.iml new file mode 100644 index 0000000000000000000000000000000000000000..d6ebd4805981b8400db3e3291c74a743fef9a824 --- /dev/null +++ b/.idea/backend.iml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$" /> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module> \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000000000000000000000000000000000000..a55e7a179bde3e4e772c29c0c85e53354aa54618 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ +<component name="ProjectCodeStyleConfiguration"> + <state> + <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" /> + </state> +</component> \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000000000000000000000000000000000000..15a15b218a29e09c9190992732698d646e4d659a --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Encoding" addBOMForNewFiles="with NO BOM" /> +</project> \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..28a804d8932aba40f168fd757a74cb718a955a1a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="JavaScriptSettings"> + <option name="languageLevel" value="ES6" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..e066844ef633dcf7d83f24067bbb6305f517da56 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/backend.iml" filepath="$PROJECT_DIR$/.idea/backend.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..35eb1ddfbbc029bcab630581847471d7f238ec53 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000000000000000000000000000000000..60d50f36149616fac27948df9fbc77ae18513c3d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,34 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": "(lldb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "enter program name, for example ${workspaceFolder}/a.out", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "lldb" + }, + { + "name": "clang - Build and debug active file", + "type": "cppdbg", + "request": "launch", + "program": "${fileDirname}/${fileBasenameNoExtension}", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "lldb", + "preLaunchTask": "C/C++: clang build active file" + } + ] +} \ No newline at end of file diff --git a/api/migrations/0002_remove_user_phone_number.py b/api/migrations/0002_remove_user_phone_number.py new file mode 100644 index 0000000000000000000000000000000000000000..b331b407658d91a32fbc2ffa0c9211cd69dd4b8d --- /dev/null +++ b/api/migrations/0002_remove_user_phone_number.py @@ -0,0 +1,17 @@ +# Generated by Django 3.0.7 on 2020-10-02 03:19 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='user', + name='phone_number', + ), + ] diff --git a/api/migrations/0003_user_phone_number.py b/api/migrations/0003_user_phone_number.py new file mode 100644 index 0000000000000000000000000000000000000000..0d8eace5c637eb9ec0c9675795f5703732a7a1f2 --- /dev/null +++ b/api/migrations/0003_user_phone_number.py @@ -0,0 +1,20 @@ +# Generated by Django 3.0.7 on 2020-10-02 04:19 + +from django.db import migrations +import phonenumber_field.modelfields + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0002_remove_user_phone_number'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='phone_number', + field=phonenumber_field.modelfields.PhoneNumberField(default=0, max_length=128, region=None, unique=True, verbose_name='phone number'), + preserve_default=False, + ), + ] diff --git a/api/migrations/0004_batch.py b/api/migrations/0004_batch.py new file mode 100644 index 0000000000000000000000000000000000000000..c08163d4385a6bd6ff33812c3b411364e40df5dc --- /dev/null +++ b/api/migrations/0004_batch.py @@ -0,0 +1,29 @@ +# Generated by Django 3.0.7 on 2020-10-02 05:14 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0003_user_phone_number'), + ] + + operations = [ + migrations.CreateModel( + name='Batch', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200, verbose_name='name')), + ('start_date_time', models.DateTimeField(verbose_name='start date and time')), + ('end_date_time', models.DateTimeField(verbose_name='end date and time')), + ('shipping_cost', models.IntegerField(verbose_name='shipping cost')), + ], + options={ + 'verbose_name': 'batch', + 'verbose_name_plural': 'batches', + 'ordering': ['-start_date_time', '-end_date_time', 'name', 'id'], + }, + ), + ] diff --git a/api/migrations/0005_auto_20201002_1217.py b/api/migrations/0005_auto_20201002_1217.py new file mode 100644 index 0000000000000000000000000000000000000000..a26cca8cd24dd55b3f8dcc83a1cb5b3577875cd8 --- /dev/null +++ b/api/migrations/0005_auto_20201002_1217.py @@ -0,0 +1,32 @@ +# Generated by Django 3.0.7 on 2020-10-02 05:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0004_batch'), + ] + + operations = [ + migrations.AlterModelOptions( + name='batch', + options={'ordering': ['-start_date_time', '-end_date_time', 'batch_name', 'id'], 'verbose_name': 'batch', 'verbose_name_plural': 'batches'}, + ), + migrations.RenameField( + model_name='batch', + old_name='name', + new_name='batch_name', + ), + migrations.AlterField( + model_name='batch', + name='end_date_time', + field=models.DateTimeField(verbose_name='end date & time'), + ), + migrations.AlterField( + model_name='batch', + name='start_date_time', + field=models.DateTimeField(verbose_name='start date & time'), + ), + ] diff --git a/api/models.py b/api/models.py index c493722d016da2b543f5ca3181a4cf617fc88792..8efec19822f6872693b4fc9880d8b3d1bad1413d 100644 --- a/api/models.py +++ b/api/models.py @@ -13,6 +13,8 @@ from api import constants, utils class User(auth_models.AbstractUser): + REQUIRED_FIELDS = ['phone_number'] + id = db_models.UUIDField(default=uuid.uuid4, primary_key=True, verbose_name=_('ID')) first_name = None last_name = None @@ -559,3 +561,5 @@ class ShipmentConfig(solo_models.SingletonModel): def __str__(self): return 'Shipment Configuration' + + diff --git a/api/seeds.py b/api/seeds.py index aff4d0050aebbc0c93effef957f3e69a6c9821a9..0711fb9d7250fccf6a8e7dceb04d2c0c5a0e6787 100644 --- a/api/seeds.py +++ b/api/seeds.py @@ -75,3 +75,10 @@ SHIPMENT_CONFIG_DATA = { 'same_urban_village_different_hamlet_costs': '2000', 'same_sub_district_different_urban_village_costs': '3000', } + +BATCH_DATA = { + 'batch_name': 'Batch 1', + 'start_date_time': '2020-10-03T00:00:00+07:00', + 'end_date_time': '2020-10-09T00:00:00+07:00', + 'shipping_cost': '60000', +} \ No newline at end of file diff --git a/api/tests.py b/api/tests.py index a0e3dc0486cf78e26898d40abad1038a55408df1..6aaabcdffe91e508b56c935edfe9ef1c06462d1c 100644 --- a/api/tests.py +++ b/api/tests.py @@ -1855,3 +1855,15 @@ class ShipmentConfigTest(rest_framework_test.APITestCase): http_authorization=self.superuser_http_authorization ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + +class BatchTest(rest_framework_test.APITestCase): + def setUp(self): + self.superuser = models.User.objects.create_superuser(**seeds.SUPERUSER_DATA) + self.superuser_http_authorization = get_http_authorization( + seeds.SUPERUSER_DATA['username'], + seeds.SUPERUSER_DATA['password'] + ) + + def test_batch_model_string_representation(self): + batch = models.Batch.objects.create(**seeds.BATCH_DATA) + self.assertEqual(str(batch), seeds.BATCH_DATA['batch_name'])