mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add "optional" field to BomItem
- Defaults to False - Indicates that the BomItem is "optional" for a build - Will be used in the future when calculating if a Build output is fully allocated!
This commit is contained in:
parent
c1595396c4
commit
3ee7be1d58
@ -765,20 +765,30 @@ class BomList(generics.ListCreateAPIView):
|
||||
|
||||
queryset = super().filter_queryset(queryset)
|
||||
|
||||
params = self.request.query_params
|
||||
|
||||
# Filter by "optional" status?
|
||||
optional = params.get('optional', None)
|
||||
|
||||
if optional is not None:
|
||||
optional = str2bool(optional)
|
||||
|
||||
queryset = queryset.filter(optional=optional)
|
||||
|
||||
# Filter by part?
|
||||
part = self.request.query_params.get('part', None)
|
||||
part = params.get('part', None)
|
||||
|
||||
if part is not None:
|
||||
queryset = queryset.filter(part=part)
|
||||
|
||||
# Filter by sub-part?
|
||||
sub_part = self.request.query_params.get('sub_part', None)
|
||||
sub_part = params.get('sub_part', None)
|
||||
|
||||
if sub_part is not None:
|
||||
queryset = queryset.filter(sub_part=sub_part)
|
||||
|
||||
# Filter by "trackable" status of the sub-part
|
||||
trackable = self.request.query_params.get('trackable', None)
|
||||
trackable = params.get('trackable', None)
|
||||
|
||||
if trackable is not None:
|
||||
trackable = str2bool(trackable)
|
||||
|
@ -231,7 +231,8 @@ class EditBomItemForm(HelperForm):
|
||||
'quantity',
|
||||
'reference',
|
||||
'overage',
|
||||
'note'
|
||||
'note',
|
||||
'optional',
|
||||
]
|
||||
|
||||
# Prevent editing of the part associated with this BomItem
|
||||
|
18
InvenTree/part/migrations/0051_bomitem_optional.py
Normal file
18
InvenTree/part/migrations/0051_bomitem_optional.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.7 on 2020-10-04 13:34
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('part', '0050_auto_20200917_2315'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='bomitem',
|
||||
name='optional',
|
||||
field=models.BooleanField(default=False, help_text='This BOM item is optional'),
|
||||
),
|
||||
]
|
@ -1500,6 +1500,7 @@ class BomItem(models.Model):
|
||||
part: Link to the parent part (the part that will be produced)
|
||||
sub_part: Link to the child part (the part that will be consumed)
|
||||
quantity: Number of 'sub_parts' consumed to produce one 'part'
|
||||
optional: Boolean field describing if this BomItem is optional
|
||||
reference: BOM reference field (e.g. part designators)
|
||||
overage: Estimated losses for a Build. Can be expressed as absolute value (e.g. '7') or a percentage (e.g. '2%')
|
||||
note: Note field for this BOM item
|
||||
@ -1533,6 +1534,8 @@ class BomItem(models.Model):
|
||||
# Quantity required
|
||||
quantity = models.DecimalField(default=1.0, max_digits=15, decimal_places=5, validators=[MinValueValidator(0)], help_text=_('BOM quantity for this BOM item'))
|
||||
|
||||
optional = models.BooleanField(default=False, help_text=_("This BOM item is optional"))
|
||||
|
||||
overage = models.CharField(max_length=24, blank=True, validators=[validators.validate_overage],
|
||||
help_text=_('Estimated build wastage quantity (absolute or percentage)')
|
||||
)
|
||||
|
@ -403,6 +403,7 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
||||
'quantity',
|
||||
'reference',
|
||||
'price_range',
|
||||
'optional',
|
||||
'overage',
|
||||
'note',
|
||||
'validated',
|
||||
|
@ -169,6 +169,10 @@ function loadBomTable(table, options) {
|
||||
// Let's make it a bit more pretty
|
||||
text = parseFloat(text);
|
||||
|
||||
if (row.optional) {
|
||||
text += " ({% trans "Optional" %})";
|
||||
}
|
||||
|
||||
if (row.overage) {
|
||||
text += "<small> (+" + row.overage + ") </small>";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user