mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-05 13:10:57 +00:00
Adds 'consumable' field to BomItem model (#2890)
* Adds 'consumable' field to BomItem model * Add consumable field to API * Consumable items always count as "allocated" for a build * Add new BOM fields to BOM item checksum calculation * Display 'consumable' status in BOM table * Fix order of database migrations * Update unit tests * Fix for BOM table * Remove "infinite" field from StockItem model - Not used anywhere for functionality - Hidden from the user - Now replaced by the "consumable" concept in the BuildOrder model * Update build order allocation table display * Prevent auto-allocation of stock to consumable BOM items * Ignore consumable BOM items when allocating stock to a build order * Reimplmement "footer" row for BOM table * Fix "can_build" calculation - Ignore "consumable" BOM items * Unrelated typo fix * Tweak BOM table * More visual tweaks to BOM table * Add unit test for consumable field
This commit is contained in:
@ -1134,7 +1134,12 @@ class Part(InvenTreeBarcodeMixin, MetadataMixin, MPTTModel):
|
||||
total = None
|
||||
|
||||
# Prefetch related tables, to reduce query expense
|
||||
queryset = self.get_bom_items().prefetch_related(
|
||||
queryset = self.get_bom_items()
|
||||
|
||||
# Ignore 'consumable' BOM items for this calculation
|
||||
queryset = queryset.filter(consumable=False)
|
||||
|
||||
queryset = queryset.prefetch_related(
|
||||
'sub_part__stock_items',
|
||||
'sub_part__stock_items__allocations',
|
||||
'sub_part__stock_items__sales_order_allocations',
|
||||
@ -2526,6 +2531,7 @@ class BomItem(DataImportMixin, models.Model):
|
||||
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
|
||||
consumable: Boolean field describing if this BomItem is considered a 'consumable'
|
||||
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
|
||||
@ -2544,6 +2550,7 @@ class BomItem(DataImportMixin, models.Model):
|
||||
'allow_variants': {},
|
||||
'inherited': {},
|
||||
'optional': {},
|
||||
'consumable': {},
|
||||
'note': {},
|
||||
'part': {
|
||||
'label': _('Part'),
|
||||
@ -2649,7 +2656,17 @@ class BomItem(DataImportMixin, models.Model):
|
||||
# Quantity required
|
||||
quantity = models.DecimalField(default=1.0, max_digits=15, decimal_places=5, validators=[MinValueValidator(0)], verbose_name=_('Quantity'), help_text=_('BOM quantity for this BOM item'))
|
||||
|
||||
optional = models.BooleanField(default=False, verbose_name=_('Optional'), help_text=_("This BOM item is optional"))
|
||||
optional = models.BooleanField(
|
||||
default=False,
|
||||
verbose_name=_('Optional'),
|
||||
help_text=_("This BOM item is optional")
|
||||
)
|
||||
|
||||
consumable = models.BooleanField(
|
||||
default=False,
|
||||
verbose_name=_('Consumable'),
|
||||
help_text=_("This BOM item is consumable (it is not tracked in build orders)")
|
||||
)
|
||||
|
||||
overage = models.CharField(max_length=24, blank=True, validators=[validators.validate_overage],
|
||||
verbose_name=_('Overage'),
|
||||
@ -2698,6 +2715,14 @@ class BomItem(DataImportMixin, models.Model):
|
||||
result_hash.update(str(self.optional).encode())
|
||||
result_hash.update(str(self.inherited).encode())
|
||||
|
||||
# Optionally encoded for backwards compatibility
|
||||
if self.consumable:
|
||||
result_hash.update(str(self.consumable).encode())
|
||||
|
||||
# Optionally encoded for backwards compatibility
|
||||
if self.allow_variants:
|
||||
result_hash.update(str(self.allow_variants).encode())
|
||||
|
||||
return str(result_hash.digest())
|
||||
|
||||
def validate_hash(self, valid=True):
|
||||
|
Reference in New Issue
Block a user