mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
commit
fa82494667
@ -8,6 +8,6 @@ before_install:
|
||||
- pip install djangorestframework
|
||||
|
||||
script:
|
||||
- "pep8 --exclude=migrations --ignore=E402,W293,E501 InvenTree"
|
||||
- python pep_check.py
|
||||
- python InvenTree/manage.py check
|
||||
- python InvenTree/manage.py test --noinput
|
@ -38,7 +38,7 @@ class InvenTreeTree(models.Model):
|
||||
abstract = True
|
||||
|
||||
name = models.CharField(max_length=100)
|
||||
description = models.CharField(max_length=250)
|
||||
description = models.CharField(max_length=250, blank=True)
|
||||
parent = models.ForeignKey('self',
|
||||
on_delete=models.CASCADE,
|
||||
blank=True,
|
||||
@ -83,7 +83,7 @@ class InvenTreeTree(models.Model):
|
||||
for a in available:
|
||||
if a.id not in childs:
|
||||
acceptable.append(a)
|
||||
|
||||
|
||||
return acceptable
|
||||
|
||||
@property
|
||||
|
@ -39,20 +39,13 @@ class Part(models.Model):
|
||||
verbose_name = "Part"
|
||||
verbose_name_plural = "Parts"
|
||||
|
||||
@property
|
||||
def stock_list(self):
|
||||
""" Return a list of all stock objects associated with this part
|
||||
"""
|
||||
|
||||
return self.stockitem_set.all()
|
||||
|
||||
@property
|
||||
def stock(self):
|
||||
""" Return the total stock quantity for this part.
|
||||
Part may be stored in multiple locations
|
||||
"""
|
||||
|
||||
stocks = self.stock_list
|
||||
stocks = self.locations.all()
|
||||
if len(stocks) == 0:
|
||||
return 0
|
||||
|
||||
@ -132,8 +125,7 @@ class PartParameter(models.Model):
|
||||
""" PartParameter is associated with a single part
|
||||
"""
|
||||
|
||||
part = models.ForeignKey(Part, on_delete=models.CASCADE)
|
||||
|
||||
part = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='parameters')
|
||||
template = models.ForeignKey(PartParameterTemplate)
|
||||
|
||||
# Value data
|
||||
@ -145,10 +137,10 @@ class PartParameter(models.Model):
|
||||
# from being added to the same part
|
||||
def save(self, *args, **kwargs):
|
||||
params = PartParameter.objects.filter(part=self.part, template=self.template)
|
||||
if len(params) > 0:
|
||||
raise ValidationError("Parameter '{param}' already exists for {part}".format(
|
||||
param=self.template.name,
|
||||
part=self.part.name))
|
||||
if len(params) > 1:
|
||||
return
|
||||
if len(params) == 1 and params[0].id != self.id:
|
||||
return
|
||||
|
||||
super(PartParameter, self).save(*args, **kwargs)
|
||||
|
||||
@ -158,6 +150,14 @@ class PartParameter(models.Model):
|
||||
val=self.value,
|
||||
units=self.template.units)
|
||||
|
||||
@property
|
||||
def units(self):
|
||||
return self.template.units
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.template.name
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Part Parameter"
|
||||
verbose_name_plural = "Part Parameters"
|
||||
|
@ -1,16 +1,29 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from .models import Part, PartCategory
|
||||
from .models import Part, PartCategory, PartParameter
|
||||
|
||||
|
||||
class ParameterSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = PartParameter
|
||||
fields = ('name',
|
||||
'value',
|
||||
'units')
|
||||
|
||||
|
||||
class PartSerializer(serializers.ModelSerializer):
|
||||
|
||||
params = ParameterSerializer(source='parameters', many=True)
|
||||
|
||||
class Meta:
|
||||
model = Part
|
||||
fields = ('pk',
|
||||
'name',
|
||||
'IPN',
|
||||
'description',
|
||||
'category',
|
||||
'stock')
|
||||
'stock',
|
||||
'params')
|
||||
|
||||
|
||||
class PartCategorySerializer(serializers.ModelSerializer):
|
||||
|
@ -12,13 +12,15 @@ class Warehouse(InvenTreeTree):
|
||||
|
||||
class StockItem(models.Model):
|
||||
part = models.ForeignKey(Part,
|
||||
on_delete=models.CASCADE)
|
||||
on_delete=models.CASCADE,
|
||||
related_name='locations')
|
||||
location = models.ForeignKey(Warehouse, on_delete=models.CASCADE)
|
||||
quantity = models.IntegerField()
|
||||
updated = models.DateField(auto_now=True)
|
||||
|
||||
# Stock status types
|
||||
ITEM_IN_PROGRESS = 0
|
||||
ITEM_INCOMING = 5
|
||||
ITEM_DAMAGED = 10
|
||||
ITEM_ATTENTION = 20
|
||||
ITEM_COMPLETE = 50
|
||||
@ -26,6 +28,7 @@ class StockItem(models.Model):
|
||||
status = models.IntegerField(default=ITEM_IN_PROGRESS,
|
||||
choices=[
|
||||
(ITEM_IN_PROGRESS, "In progress"),
|
||||
(ITEM_INCOMING, "Incoming"),
|
||||
(ITEM_DAMAGED, "Damaged"),
|
||||
(ITEM_ATTENTION, "Requires attention"),
|
||||
(ITEM_COMPLETE, "Complete")
|
||||
|
3
pep_check.py
Normal file
3
pep_check.py
Normal file
@ -0,0 +1,3 @@
|
||||
import subprocess
|
||||
|
||||
subprocess.call(['pep8', '--exclude=migrations', '--ignore=EC04,W293,E501', 'InvenTree'])
|
Loading…
Reference in New Issue
Block a user