mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Display overage values in BOM table
This commit is contained in:
parent
68ae38a7d7
commit
8c92c2c2a1
@ -261,7 +261,7 @@ class Build(models.Model):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
item = BomItem.objects.get(part=self.part.id, sub_part=part.id)
|
item = BomItem.objects.get(part=self.part.id, sub_part=part.id)
|
||||||
return item.quantity * self.quantity
|
return item.get_required_quantity(self.quantity)
|
||||||
except BomItem.DoesNotExist:
|
except BomItem.DoesNotExist:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@ -1,89 +0,0 @@
|
|||||||
"""
|
|
||||||
TODO - Implement part parameters, and templates
|
|
||||||
|
|
||||||
See code below
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PartParameterTemplate(models.Model):
|
|
||||||
""" A PartParameterTemplate pre-defines a parameter field,
|
|
||||||
ready to be copied for use with a given Part.
|
|
||||||
A PartParameterTemplate can be optionally associated with a PartCategory
|
|
||||||
"""
|
|
||||||
name = models.CharField(max_length=20, unique=True)
|
|
||||||
units = models.CharField(max_length=10, blank=True)
|
|
||||||
|
|
||||||
# Parameter format
|
|
||||||
PARAM_NUMERIC = 10
|
|
||||||
PARAM_TEXT = 20
|
|
||||||
PARAM_BOOL = 30
|
|
||||||
|
|
||||||
PARAM_TYPE_CODES = {
|
|
||||||
PARAM_NUMERIC: _("Numeric"),
|
|
||||||
PARAM_TEXT: _("Text"),
|
|
||||||
PARAM_BOOL: _("Bool")
|
|
||||||
}
|
|
||||||
|
|
||||||
format = models.PositiveIntegerField(
|
|
||||||
default=PARAM_NUMERIC,
|
|
||||||
choices=PARAM_TYPE_CODES.items(),
|
|
||||||
validators=[MinValueValidator(0)])
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return "{name} ({units})".format(
|
|
||||||
name=self.name,
|
|
||||||
units=self.units)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
verbose_name = "Parameter Template"
|
|
||||||
verbose_name_plural = "Parameter Templates"
|
|
||||||
|
|
||||||
|
|
||||||
class CategoryParameterLink(models.Model):
|
|
||||||
""" Links a PartParameterTemplate to a PartCategory
|
|
||||||
"""
|
|
||||||
category = models.ForeignKey(PartCategory, on_delete=models.CASCADE)
|
|
||||||
template = models.ForeignKey(PartParameterTemplate, on_delete=models.CASCADE)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return "{name} - {cat}".format(
|
|
||||||
name=self.template.name,
|
|
||||||
cat=self.category)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
verbose_name = "Category Parameter"
|
|
||||||
verbose_name_plural = "Category Parameters"
|
|
||||||
unique_together = ('category', 'template')
|
|
||||||
|
|
||||||
|
|
||||||
class PartParameter(models.Model):
|
|
||||||
""" PartParameter is associated with a single part
|
|
||||||
"""
|
|
||||||
|
|
||||||
part = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='parameters')
|
|
||||||
template = models.ForeignKey(PartParameterTemplate)
|
|
||||||
|
|
||||||
# Value data
|
|
||||||
value = models.CharField(max_length=50, blank=True)
|
|
||||||
min_value = models.CharField(max_length=50, blank=True)
|
|
||||||
max_value = models.CharField(max_length=50, blank=True)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return "{name} : {val}{units}".format(
|
|
||||||
name=self.template.name,
|
|
||||||
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"
|
|
||||||
unique_together = ('part', 'template')
|
|
@ -104,8 +104,6 @@ class PartStarSerializer(InvenTreeModelSerializer):
|
|||||||
class BomItemSerializer(InvenTreeModelSerializer):
|
class BomItemSerializer(InvenTreeModelSerializer):
|
||||||
""" Serializer for BomItem object """
|
""" Serializer for BomItem object """
|
||||||
|
|
||||||
# url = serializers.CharField(source='get_absolute_url', read_only=True)
|
|
||||||
|
|
||||||
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
|
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
|
||||||
sub_part_detail = PartBriefSerializer(source='sub_part', many=False, read_only=True)
|
sub_part_detail = PartBriefSerializer(source='sub_part', many=False, read_only=True)
|
||||||
|
|
||||||
@ -113,12 +111,12 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
|||||||
model = BomItem
|
model = BomItem
|
||||||
fields = [
|
fields = [
|
||||||
'pk',
|
'pk',
|
||||||
# 'url',
|
|
||||||
'part',
|
'part',
|
||||||
'part_detail',
|
'part_detail',
|
||||||
'sub_part',
|
'sub_part',
|
||||||
'sub_part_detail',
|
'sub_part_detail',
|
||||||
'quantity',
|
'quantity',
|
||||||
|
'overage',
|
||||||
'note',
|
'note',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -113,6 +113,15 @@ function loadBomTable(table, options) {
|
|||||||
title: 'Required',
|
title: 'Required',
|
||||||
searchable: false,
|
searchable: false,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
|
formatter: function(value, row, index, field) {
|
||||||
|
var text = value;
|
||||||
|
|
||||||
|
if (row.overage) {
|
||||||
|
text += "<small> (+" + row.overage + ") </small>";
|
||||||
|
}
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user