mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Replace other choice fields with commonized status code
This commit is contained in:
parent
8d70d2f28a
commit
f731c45ce8
@ -7,6 +7,11 @@ class StatusCode:
|
|||||||
def items(cls):
|
def items(cls):
|
||||||
return cls.options.items()
|
return cls.options.items()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def label(cls, value):
|
||||||
|
""" Return the status code label associated with the provided value """
|
||||||
|
return cls.options.get(value, '')
|
||||||
|
|
||||||
|
|
||||||
class OrderStatus(StatusCode):
|
class OrderStatus(StatusCode):
|
||||||
|
|
||||||
@ -26,3 +31,48 @@ class OrderStatus(StatusCode):
|
|||||||
LOST: _("Lost"),
|
LOST: _("Lost"),
|
||||||
RETURNED: _("Returned"),
|
RETURNED: _("Returned"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class StockStatus(StatusCode):
|
||||||
|
|
||||||
|
OK = 10 # Item is OK
|
||||||
|
ATTENTION = 50 # Item requires attention
|
||||||
|
DAMAGED = 55 # Item is damaged
|
||||||
|
DESTROYED = 60 # Item is destroyed
|
||||||
|
LOST = 70 # Item has been lost
|
||||||
|
|
||||||
|
options = {
|
||||||
|
OK: _("OK"),
|
||||||
|
ATTENTION: _("Attention needed"),
|
||||||
|
DAMAGED: _("Damaged"),
|
||||||
|
DESTROYED: _("Destroyed"),
|
||||||
|
LOST: _("Lost"),
|
||||||
|
}
|
||||||
|
|
||||||
|
# The following codes correspond to parts that are 'available'
|
||||||
|
AVAILABLE_CODES = [
|
||||||
|
OK,
|
||||||
|
ATTENTION,
|
||||||
|
DAMAGED
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class BuildStatus(StatusCode):
|
||||||
|
|
||||||
|
# Build status codes
|
||||||
|
PENDING = 10 # Build is pending / active
|
||||||
|
ALLOCATED = 20 # Parts have been removed from stock
|
||||||
|
CANCELLED = 30 # Build was cancelled
|
||||||
|
COMPLETE = 40 # Build is complete
|
||||||
|
|
||||||
|
options = {
|
||||||
|
PENDING: _("Pending"),
|
||||||
|
ALLOCATED: _("Allocated"),
|
||||||
|
CANCELLED: _("Cancelled"),
|
||||||
|
COMPLETE: _("Complete"),
|
||||||
|
}
|
||||||
|
|
||||||
|
ACTIVE_CODES = [
|
||||||
|
PENDING,
|
||||||
|
ALLOCATED
|
||||||
|
]
|
||||||
|
@ -16,6 +16,8 @@ from django.db import models, transaction
|
|||||||
from django.db.models import Sum
|
from django.db.models import Sum
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator
|
||||||
|
|
||||||
|
from InvenTree.status_codes import BuildStatus
|
||||||
|
|
||||||
from stock.models import StockItem
|
from stock.models import StockItem
|
||||||
from part.models import Part, BomItem
|
from part.models import Part, BomItem
|
||||||
|
|
||||||
@ -68,22 +70,10 @@ class Build(models.Model):
|
|||||||
validators=[MinValueValidator(1)],
|
validators=[MinValueValidator(1)],
|
||||||
help_text='Number of parts to build'
|
help_text='Number of parts to build'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Build status codes
|
|
||||||
PENDING = 10 # Build is pending / active
|
|
||||||
ALLOCATED = 20 # Parts have been removed from stock
|
|
||||||
CANCELLED = 30 # Build was cancelled
|
|
||||||
COMPLETE = 40 # Build is complete
|
|
||||||
|
|
||||||
#: Build status codes
|
|
||||||
BUILD_STATUS_CODES = {PENDING: _("Pending"),
|
|
||||||
ALLOCATED: _("Allocated"),
|
|
||||||
CANCELLED: _("Cancelled"),
|
|
||||||
COMPLETE: _("Complete"),
|
|
||||||
}
|
|
||||||
|
|
||||||
status = models.PositiveIntegerField(default=PENDING,
|
status = models.PositiveIntegerField(default=BuildStatus.PENDING,
|
||||||
choices=BUILD_STATUS_CODES.items(),
|
choices=BuildStatus.items(),
|
||||||
validators=[MinValueValidator(0)],
|
validators=[MinValueValidator(0)],
|
||||||
help_text='Build status')
|
help_text='Build status')
|
||||||
|
|
||||||
@ -325,14 +315,12 @@ class Build(models.Model):
|
|||||||
- HOLDING
|
- HOLDING
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return self.status in [
|
return self.status in BuildStatus.ACTIVE_CODES
|
||||||
self.PENDING,
|
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_complete(self):
|
def is_complete(self):
|
||||||
""" Returns True if the build status is COMPLETE """
|
""" Returns True if the build status is COMPLETE """
|
||||||
return self.status == self.COMPLETE
|
return self.status == self.BuildStatus.COMPLETE
|
||||||
|
|
||||||
|
|
||||||
class BuildItem(models.Model):
|
class BuildItem(models.Model):
|
||||||
|
@ -33,6 +33,8 @@ from InvenTree import helpers
|
|||||||
from InvenTree import validators
|
from InvenTree import validators
|
||||||
from InvenTree.models import InvenTreeTree
|
from InvenTree.models import InvenTreeTree
|
||||||
|
|
||||||
|
from InvenTree.status_codes import BuildStatus, StockStatus
|
||||||
|
|
||||||
from company.models import SupplierPart
|
from company.models import SupplierPart
|
||||||
|
|
||||||
|
|
||||||
@ -454,14 +456,14 @@ class Part(models.Model):
|
|||||||
Builds marked as 'complete' or 'cancelled' are ignored
|
Builds marked as 'complete' or 'cancelled' are ignored
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return [b for b in self.builds.all() if b.is_active]
|
return self.builds.filter(status__in=BuildStatus.ACTIVE_CODES)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def inactive_builds(self):
|
def inactive_builds(self):
|
||||||
""" Return a list of inactive builds
|
""" Return a list of inactive builds
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return [b for b in self.builds.all() if not b.is_active]
|
return self.builds.exclude(status__in=BuildStatus.ACTIVE_CODES)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def quantity_being_built(self):
|
def quantity_being_built(self):
|
||||||
@ -531,7 +533,7 @@ class Part(models.Model):
|
|||||||
if self.is_template:
|
if self.is_template:
|
||||||
total = sum([variant.total_stock for variant in self.variants.all()])
|
total = sum([variant.total_stock for variant in self.variants.all()])
|
||||||
else:
|
else:
|
||||||
total = self.stock_entries.aggregate(total=Sum('quantity'))['total']
|
total = self.stock_entries.filter(status__in=StockStatus.AVAILABLE_CODES).aggregate(total=Sum('quantity'))['total']
|
||||||
|
|
||||||
if total:
|
if total:
|
||||||
return total
|
return total
|
||||||
|
@ -20,6 +20,7 @@ from .serializers import StockTrackingSerializer
|
|||||||
|
|
||||||
from InvenTree.views import TreeSerializer
|
from InvenTree.views import TreeSerializer
|
||||||
from InvenTree.helpers import str2bool
|
from InvenTree.helpers import str2bool
|
||||||
|
from InvenTree.status_codes import StockStatus
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@ -311,7 +312,7 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
else:
|
else:
|
||||||
item['location__path'] = None
|
item['location__path'] = None
|
||||||
|
|
||||||
item['status_text'] = StockItem.ITEM_STATUS_CODES[item['status']]
|
item['status_text'] = StockStatus.label(item['status'])
|
||||||
|
|
||||||
return Response(data)
|
return Response(data)
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ from django.dispatch import receiver
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from InvenTree import helpers
|
from InvenTree import helpers
|
||||||
|
|
||||||
|
from InvenTree.status_codes import StockStatus
|
||||||
from InvenTree.models import InvenTreeTree
|
from InvenTree.models import InvenTreeTree
|
||||||
|
|
||||||
from part.models import Part
|
from part.models import Part
|
||||||
@ -93,7 +94,7 @@ class StockItem(models.Model):
|
|||||||
stocktake_user: User that performed the most recent stocktake
|
stocktake_user: User that performed the most recent stocktake
|
||||||
review_needed: Flag if StockItem needs review
|
review_needed: Flag if StockItem needs review
|
||||||
delete_on_deplete: If True, StockItem will be deleted when the stock level gets to zero
|
delete_on_deplete: If True, StockItem will be deleted when the stock level gets to zero
|
||||||
status: Status of this StockItem (ref: ITEM_STATUS_CODES)
|
status: Status of this StockItem (ref: InvenTree.status_codes.StockStatus)
|
||||||
notes: Extra notes field
|
notes: Extra notes field
|
||||||
infinite: If True this StockItem can never be exhausted
|
infinite: If True this StockItem can never be exhausted
|
||||||
"""
|
"""
|
||||||
@ -256,23 +257,9 @@ class StockItem(models.Model):
|
|||||||
|
|
||||||
delete_on_deplete = models.BooleanField(default=True, help_text='Delete this Stock Item when stock is depleted')
|
delete_on_deplete = models.BooleanField(default=True, help_text='Delete this Stock Item when stock is depleted')
|
||||||
|
|
||||||
ITEM_OK = 10
|
|
||||||
ITEM_ATTENTION = 50
|
|
||||||
ITEM_DAMAGED = 55
|
|
||||||
ITEM_DESTROYED = 60
|
|
||||||
ITEM_LOST = 70
|
|
||||||
|
|
||||||
ITEM_STATUS_CODES = {
|
|
||||||
ITEM_OK: _("OK"),
|
|
||||||
ITEM_ATTENTION: _("Attention needed"),
|
|
||||||
ITEM_DAMAGED: _("Damaged"),
|
|
||||||
ITEM_DESTROYED: _("Destroyed"),
|
|
||||||
ITEM_LOST: _("Lost")
|
|
||||||
}
|
|
||||||
|
|
||||||
status = models.PositiveIntegerField(
|
status = models.PositiveIntegerField(
|
||||||
default=ITEM_OK,
|
default=StockStatus.OK,
|
||||||
choices=ITEM_STATUS_CODES.items(),
|
choices=StockStatus.items(),
|
||||||
validators=[MinValueValidator(0)])
|
validators=[MinValueValidator(0)])
|
||||||
|
|
||||||
notes = models.CharField(max_length=250, blank=True, help_text='Stock Item Notes')
|
notes = models.CharField(max_length=250, blank=True, help_text='Stock Item Notes')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user