Skip to content
Merged
1 change: 1 addition & 0 deletions doc/release/RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
* [OSDEV-1589](https://opensupplyhub.atlassian.net/browse/OSDEV-1589) - Fixed layout issue on new `contribute` page.
* [OSDEV-1739](https://opensupplyhub.atlassian.net/browse/OSDEV-1739) - Applied state cleanup on modal unmount to prevent the same dialog from appearing when clicking on a different production location.
* [OSDEV-1744](https://opensupplyhub.atlassian.net/browse/OSDEV-1744) - Fixed the issue where the text `by user ID:` appeared even when `user_id` was `null` in Contribution Record page.
* [OSDEV-1778](https://opensupplyhub.atlassian.net/browse/OSDEV-1778) - Fixed the validation for number of workers field in POST, PATH production locations API. The min field must be less than or equal to the max field.
* [OSDEV-1779](https://opensupplyhub.atlassian.net/browse/OSDEV-1779) - SLC. Made Parent Company field as regular text field and apply snake_case keys to standard keys (e.g. `location_type`, `number_of_workers`, `parent_company`, `processing_type` and `product_type`) in request payload from production location info page to conform API specs.
* [OSDEV-1745](https://opensupplyhub.atlassian.net/browse/OSDEV-1745) - The `Search by Name and Address` tab was defined as default on the Production Location Search page.

Expand Down
38 changes: 38 additions & 0 deletions src/django/api/serializers/v1/number_of_workers_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,44 @@ class NumberOfWorkersSerializer(serializers.Serializer):
}
)

def validate(self, data):
min_value = data.get('min')
max_value = data.get('max')

if (
min_value is not None
and max_value is not None
and min_value > max_value
):
raise serializers.ValidationError(
{"min": ('The min field must be less than or equal'
' to the max field.')}
)

return data

@staticmethod
def validate_object(value):
return isinstance(value, dict)

def to_internal_value(self, data):
errors = []

if not isinstance(data.get('min'), int):
errors.append({
"field": "min",
"detail":
"The min field must be an integer."
})

if not isinstance(data.get('max'), int):
errors.append({
"field": "max",
"detail":
"The max field must be an integer."
})

if len(errors) > 0:
raise serializers.ValidationError(errors)

return super().to_internal_value(data)
Loading