Allow update requests for editing only remarks on transactions

This commit is contained in:
Keannu Bernasol 2024-01-03 17:14:35 +08:00
parent 7a8281dabd
commit d9d94c03ef
2 changed files with 4 additions and 4 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 108 KiB

View file

@ -159,11 +159,11 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer):
)
# Transaction Status Validation
# Check if the update involves the transaction status
if 'transaction_status' in validated_data:
# Check if the update involves changing the transaction status
if 'transaction_status' in validated_data and validated_data.get('transaction_status') != instance.transaction_status:
# For already finalized/done transactions (Rejected or Finalized ones)
# Do not allow any changes to already finalized transactions
# Do not allow any changes to status for already finalized transactions
if instance.transaction_status in ['Rejected', 'Finalized']:
raise serializers.ValidationError(
"Unable to update rejected or finalized transaction. Please create a new one"
@ -236,7 +236,7 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer):
)
# If the transaction changes from Borrowed to Finalized and there are no breakages, label the selected equipment's statuses as Available again from Borrowed
if instance.transaction_status == "Borrowed" and validated_data.get('transaction_status') == "Finalized":
if instance.transaction_status == "Returned: Pending Checking" and validated_data.get('transaction_status') == "Finalized":
equipments = instance.equipments.all()
# Iterate through each of those equipment instances and change their status field to "Available"
# This updates the status field of all equipment instances in a single query