mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Added MinValue validator(s)
This commit is contained in:
parent
057fd1dd20
commit
6c7f5fdaf3
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.db import models
|
||||
from django.db.models import Sum
|
||||
from django.core.validators import MinValueValidator
|
||||
|
||||
from InvenTree.models import InvenTreeTree
|
||||
|
||||
@ -35,7 +36,7 @@ class Part(models.Model):
|
||||
category = models.ForeignKey(PartCategory, on_delete=models.CASCADE)
|
||||
|
||||
# Minimum "allowed" stock level
|
||||
minimum_stock = models.PositiveIntegerField(default=0)
|
||||
minimum_stock = models.PositiveIntegerField(default=0, validators=[MinValueValidator(0)])
|
||||
|
||||
# Units of quantity for this part. Default is "pcs"
|
||||
units = models.CharField(max_length=20, default="pcs", blank=True)
|
||||
@ -112,7 +113,8 @@ class PartParameterTemplate(models.Model):
|
||||
|
||||
format = models.PositiveIntegerField(
|
||||
default=PARAM_NUMERIC,
|
||||
choices=PARAM_TYPE_CODES.items())
|
||||
choices=PARAM_TYPE_CODES.items(),
|
||||
validators=[MinValueValidator(0)])
|
||||
|
||||
def __str__(self):
|
||||
return "{name} ({units})".format(
|
||||
|
@ -1,5 +1,4 @@
|
||||
from django_filters.rest_framework import FilterSet, DjangoFilterBackend
|
||||
from django_filters import NumberFilter
|
||||
|
||||
from rest_framework import generics, permissions
|
||||
|
||||
|
@ -5,6 +5,7 @@ from django.db import models
|
||||
|
||||
from InvenTree.models import InvenTreeTree
|
||||
from part.models import Part
|
||||
from django.core.validators import MinValueValidator
|
||||
|
||||
|
||||
class ProjectCategory(InvenTreeTree):
|
||||
@ -46,7 +47,7 @@ class ProjectPart(models.Model):
|
||||
|
||||
part = models.ForeignKey(Part, on_delete=models.CASCADE)
|
||||
project = models.ForeignKey(Project, on_delete=models.CASCADE)
|
||||
quantity = models.PositiveIntegerField(default=1)
|
||||
quantity = models.PositiveIntegerField(default=1, validators=[MinValueValidator(0)])
|
||||
|
||||
class Meta:
|
||||
unique_together = ('part', 'project')
|
||||
@ -66,7 +67,8 @@ class ProjectPart(models.Model):
|
||||
overage = models.FloatField(default=0)
|
||||
overage_type = models.PositiveIntegerField(
|
||||
default=OVERAGE_ABSOLUTE,
|
||||
choices=OVARAGE_CODES.items())
|
||||
choices=OVARAGE_CODES.items(),
|
||||
validators=[MinValueValidator(0)])
|
||||
"""
|
||||
|
||||
# Set if the part is generated by the project,
|
||||
@ -89,6 +91,6 @@ class ProjectRun(models.Model):
|
||||
"""
|
||||
|
||||
project = models.ForeignKey(Project, on_delete=models.CASCADE)
|
||||
quantity = models.PositiveIntegerField(default=1)
|
||||
quantity = models.PositiveIntegerField(default=1, validators=[MinValueValidator(0)])
|
||||
|
||||
run_date = models.DateField(auto_now_add=True)
|
||||
|
@ -1,6 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.db import models
|
||||
from django.core.validators import MinValueValidator
|
||||
|
||||
from supplier.models import SupplierPart
|
||||
from part.models import Part
|
||||
@ -21,7 +22,7 @@ class StockItem(models.Model):
|
||||
part = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='locations')
|
||||
supplier_part = models.ForeignKey(SupplierPart, blank=True, null=True, on_delete=models.SET_NULL)
|
||||
location = models.ForeignKey(StockLocation, on_delete=models.CASCADE)
|
||||
quantity = models.PositiveIntegerField()
|
||||
quantity = models.PositiveIntegerField(validators=[MinValueValidator(0)])
|
||||
updated = models.DateField(auto_now=True)
|
||||
|
||||
# last time the stock was checked / counted
|
||||
@ -50,7 +51,8 @@ class StockItem(models.Model):
|
||||
|
||||
status = models.PositiveIntegerField(
|
||||
default=ITEM_IN_STOCK,
|
||||
choices=ITEM_STATUS_CODES.items())
|
||||
choices=ITEM_STATUS_CODES.items(),
|
||||
validators=[MinValueValidator(0)])
|
||||
|
||||
notes = models.CharField(max_length=100, blank=True)
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models
|
||||
from django.core.validators import MinValueValidator
|
||||
|
||||
from InvenTree.models import Company
|
||||
from part.models import Part
|
||||
@ -54,10 +55,10 @@ class SupplierPart(models.Model):
|
||||
packaging = models.CharField(max_length=50, blank=True)
|
||||
|
||||
# multiple that the part is provided in
|
||||
multiple = models.PositiveIntegerField(default=1)
|
||||
multiple = models.PositiveIntegerField(default=1, validators=[MinValueValidator(0)])
|
||||
|
||||
# Mimumum number required to order
|
||||
minimum = models.PositiveIntegerField(default=1)
|
||||
minimum = models.PositiveIntegerField(default=1, validators=[MinValueValidator(0)])
|
||||
|
||||
# lead time for parts that cannot be delivered immediately
|
||||
lead_time = models.DurationField(blank=True, null=True)
|
||||
@ -75,7 +76,7 @@ class SupplierPriceBreak(models.Model):
|
||||
"""
|
||||
|
||||
part = models.ForeignKey(SupplierPart, on_delete=models.CASCADE, related_name='price_breaks')
|
||||
quantity = models.PositiveIntegerField()
|
||||
quantity = models.PositiveIntegerField(validators=[MinValueValidator(0)])
|
||||
cost = models.DecimalField(max_digits=10, decimal_places=3)
|
||||
|
||||
class Meta:
|
||||
|
@ -1,5 +1,4 @@
|
||||
from django_filters.rest_framework import FilterSet, DjangoFilterBackend
|
||||
from django_filters import NumberFilter
|
||||
|
||||
from rest_framework import generics, permissions
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user