Skip to content

Commit

Permalink
Add validations for negative values in inventory and min quanityt (#2005
Browse files Browse the repository at this point in the history
)

Add validations for negative values in inventory

Co-authored-by: Aakash Singh <[email protected]>
  • Loading branch information
Pranshu1902 and sainak authored Apr 3, 2024
1 parent 182b43f commit ce619ef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.10 on 2024-03-22 11:21

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("facility", "0421_merge_20240318_1434"),
]

operations = [
migrations.AlterField(
model_name="facilityinventorylog",
name="quantity",
field=models.FloatField(
default=0, validators=[django.core.validators.MinValueValidator(0.0)]
),
),
migrations.AlterField(
model_name="facilityinventoryminquantity",
name="min_quantity",
field=models.FloatField(
default=0, validators=[django.core.validators.MinValueValidator(0.0)]
),
),
]
5 changes: 3 additions & 2 deletions care/facility/models/inventory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.auth import get_user_model
from django.core.validators import MinValueValidator
from django.db import models
from django.db.models import Index

Expand Down Expand Up @@ -108,7 +109,7 @@ class FacilityInventoryLog(FacilityBaseModel, FacilityRelatedPermissionMixin):
)
current_stock = models.FloatField(default=0)
quantity_in_default_unit = models.FloatField(default=0)
quantity = models.FloatField(default=0)
quantity = models.FloatField(default=0, validators=[MinValueValidator(0.0)])
unit = models.ForeignKey(
FacilityInventoryUnit, on_delete=models.SET_NULL, null=True, blank=False
)
Expand Down Expand Up @@ -157,7 +158,7 @@ class FacilityInventoryMinQuantity(FacilityBaseModel, FacilityRelatedPermissionM
item = models.ForeignKey(
FacilityInventoryItem, on_delete=models.SET_NULL, null=True, blank=False
)
min_quantity = models.FloatField(default=0)
min_quantity = models.FloatField(default=0, validators=[MinValueValidator(0.0)])

class Meta:
constraints = [
Expand Down

0 comments on commit ce619ef

Please sign in to comment.