Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add min_quntity to facilityinventorysummary and add migration #1763

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions care/facility/api/serializers/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ def create(self, validated_data):
pass

summary_obj.is_low = current_quantity < current_min_quantity
summary_obj.min_quantity_required = (
current_quantity
if current_quantity < current_min_quantity
else current_min_quantity
)

validated_data["current_stock"] = current_quantity

Expand Down Expand Up @@ -207,6 +212,11 @@ def create(self, validated_data):
facility=validated_data["facility"], item=item
)
summary_obj.is_low = summary_obj.quantity < validated_data["min_quantity"]
summary_obj.min_quantity_required = (
summary_obj.quantity
if summary_obj.quantity < validated_data["min_quantity"]
else validated_data["min_quantity"]
)
summary_obj.save()
except FacilityInventorySummary.DoesNotExist:
pass
Expand All @@ -225,6 +235,11 @@ def update(self, instance, validated_data):
facility=instance.facility, item=item
)
summary_obj.is_low = summary_obj.quantity < validated_data["min_quantity"]
summary_obj.min_quantity_required = (
summary_obj.quantity
if summary_obj.quantity < validated_data["min_quantity"]
else validated_data["min_quantity"]
)
summary_obj.save()
except FacilityInventorySummary.DoesNotExist:
pass
Expand Down