Skip to content

Commit

Permalink
fix(asset): fixed linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aeswibon committed Dec 8, 2023
1 parent 457a8a1 commit dc90af2
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions care/facility/api/serializers/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
from rest_framework.validators import UniqueValidator

from care.facility.api.serializers import TIMESTAMP_FIELDS
from care.facility.api.serializers.facility import (
FacilityBareMinimumSerializer,
)
from care.facility.api.serializers.facility import FacilityBareMinimumSerializer
from care.facility.models.asset import (
Asset,
AssetAvailabilityRecord,
Expand Down Expand Up @@ -156,15 +154,11 @@ class AssetSerializer(ModelSerializer):
id = UUIDField(source="external_id", read_only=True)
status = ChoiceField(choices=StatusChoices, read_only=True)
asset_type = ChoiceField(choices=AssetTypeChoices)
location_object = AssetLocationSerializer(
source="current_location", read_only=True
)
location_object = AssetLocationSerializer(source="current_location", read_only=True)
location = UUIDField(write_only=True, required=True)
last_service = AssetServiceSerializer(read_only=True)
last_serviced_on = serializers.DateField(write_only=True, required=False)
note = serializers.CharField(
write_only=True, required=False, allow_blank=True
)
note = serializers.CharField(write_only=True, required=False, allow_blank=True)
resolved_middleware = ResolvedMiddlewareField(read_only=True)

class Meta:
Expand Down Expand Up @@ -194,9 +188,7 @@ def validate(self, attrs):
attrs["current_location"] = location

# validate that warraty date is not in the past
if warranty_amc_end_of_validity := attrs.get(
"warranty_amc_end_of_validity"
):
if warranty_amc_end_of_validity := attrs.get("warranty_amc_end_of_validity"):
# pop out warranty date if it is not changed
if (
self.instance
Expand All @@ -213,9 +205,7 @@ def validate(self, attrs):
# validate that last serviced date is not in the future
if "last_serviced_on" in attrs and attrs["last_serviced_on"]:
if attrs["last_serviced_on"] > datetime.now().date():
raise ValidationError(
"Last serviced on cannot be in the future"
)
raise ValidationError("Last serviced on cannot be in the future")

# only allow setting asset class on creation (or updation if asset class is not set)
if (
Expand Down Expand Up @@ -274,17 +264,14 @@ def update(self, instance, validated_data):

if (
"current_location" in validated_data
and instance.current_location
!= validated_data["current_location"]
and instance.current_location != validated_data["current_location"]
):
if (
instance.current_location.facility.id
!= validated_data["current_location"].facility.id
):
raise ValidationError(
{
"location": "Interfacility transfer is not allowed here"
}
{"location": "Interfacility transfer is not allowed here"}
)
AssetTransaction(
from_location=instance.current_location,
Expand Down Expand Up @@ -319,9 +306,7 @@ class Meta:


class UserDefaultAssetLocationSerializer(ModelSerializer):
location_object = AssetLocationSerializer(
source="location", read_only=True
)
location_object = AssetLocationSerializer(source="location", read_only=True)

class Meta:
model = UserDefaultAssetLocation
Expand Down

0 comments on commit dc90af2

Please sign in to comment.