Add consumables and additional members field to transaction

This commit is contained in:
Keannu Bernasol 2024-01-05 19:33:25 +08:00
parent 1757538db1
commit 004896cb26
10 changed files with 12 additions and 18 deletions

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.7 on 2023-12-29 10:21 # Generated by Django 4.2.7 on 2024-01-05 10:26
import accounts.models import accounts.models
import django.contrib.auth.models import django.contrib.auth.models

View file

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.7 on 2023-12-29 10:09 # Generated by Django 4.2.7 on 2024-01-05 10:26
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion

View file

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.7 on 2023-12-29 10:09 # Generated by Django 4.2.7 on 2024-01-05 10:26
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models

View file

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,4 +1,4 @@
# Generated by Django 4.2.7 on 2023-12-29 10:09 # Generated by Django 4.2.7 on 2024-01-05 10:26
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
@ -11,8 +11,8 @@ class Migration(migrations.Migration):
initial = True initial = True
dependencies = [ dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('equipments', '0001_initial'), ('equipments', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
] ]
operations = [ operations = [
@ -21,6 +21,8 @@ class Migration(migrations.Migration):
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('remarks', models.TextField(max_length=512, null=True)), ('remarks', models.TextField(max_length=512, null=True)),
('additional_members', models.TextField(max_length=512, null=True)),
('consumables', models.TextField(max_length=512, null=True)),
('transaction_status', models.CharField(choices=[('Pending Approval', 'Pending Approval'), ('Approved', 'Approved'), ('Rejected', 'Rejected'), ('Cancelled', 'Cancelled'), ('Borrowed', 'Borrowed'), ('Returned: Pending Checking', 'Returned: Pending Checking'), ('With Breakages: Pending Resolution', 'With Breakages: Pending Resolution'), ('Finalized', 'Finalized')], default='Pending', max_length=40)), ('transaction_status', models.CharField(choices=[('Pending Approval', 'Pending Approval'), ('Approved', 'Approved'), ('Rejected', 'Rejected'), ('Cancelled', 'Cancelled'), ('Borrowed', 'Borrowed'), ('Returned: Pending Checking', 'Returned: Pending Checking'), ('With Breakages: Pending Resolution', 'With Breakages: Pending Resolution'), ('Finalized', 'Finalized')], default='Pending', max_length=40)),
('subject', models.TextField(max_length=128)), ('subject', models.TextField(max_length=128)),
('timestamp', models.DateTimeField(default=django.utils.timezone.now, editable=False)), ('timestamp', models.DateTimeField(default=django.utils.timezone.now, editable=False)),

View file

@ -28,6 +28,8 @@ class Transaction(models.Model):
borrower = models.ForeignKey( borrower = models.ForeignKey(
CustomUser, on_delete=models.SET_NULL, null=True, related_name='borrowed_transactions') CustomUser, on_delete=models.SET_NULL, null=True, related_name='borrowed_transactions')
remarks = models.TextField(max_length=512, null=True) remarks = models.TextField(max_length=512, null=True)
additional_members = models.TextField(max_length=512, null=True)
consumables = models.TextField(max_length=512, null=True)
teacher = models.ForeignKey( teacher = models.ForeignKey(
CustomUser, on_delete=models.SET_NULL, null=True, related_name='teacher_transactions') CustomUser, on_delete=models.SET_NULL, null=True, related_name='teacher_transactions')
equipments = models.ManyToManyField(EquipmentInstance) equipments = models.ManyToManyField(EquipmentInstance)

View file

@ -32,6 +32,8 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer):
equipments = serializers.SlugRelatedField( equipments = serializers.SlugRelatedField(
many=True, slug_field='id', queryset=EquipmentInstance.objects.all(), required=True) many=True, slug_field='id', queryset=EquipmentInstance.objects.all(), required=True)
subject = serializers.CharField(required=True, allow_null=False) subject = serializers.CharField(required=True, allow_null=False)
additional_members = serializers.CharField(required=False, allow_null=True)
consumables = serializers.CharField(required=False, allow_null=True)
timestamp = serializers.DateTimeField( timestamp = serializers.DateTimeField(
format="%m-%d-%Y %I:%M %p", read_only=True) format="%m-%d-%Y %I:%M %p", read_only=True)
@ -41,7 +43,7 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = Transaction model = Transaction
fields = ['id', 'borrower', 'teacher', 'subject', fields = ['id', 'borrower', 'teacher', 'subject',
'equipments', 'remarks', 'transaction_status', 'timestamp'] 'equipments', 'remarks', 'transaction_status', 'additional_members', 'consumables', 'timestamp']
read_only_fields = ['id', 'timestamp'] read_only_fields = ['id', 'timestamp']
def to_representation(self, instance): def to_representation(self, instance):

View file

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.