2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-05 13:10:57 +00:00

Update BomItem 'validated' field (#4486)

* Adds new "validated" field to the BomItem model

- Previously this was dynamically calculated (very expensive)
- Now cached and updated whenever a BomItem instance is saved
- Will make the BOM API much more responsive
- Cleanup BomItem list API code also

* Adds data migration to update existing BomItem objects

* Exclude 'validated' field from BomItemResource class
This commit is contained in:
Oliver
2023-03-14 13:53:33 +11:00
committed by GitHub
parent 06f8a50956
commit 1ba51e51c3
6 changed files with 84 additions and 34 deletions

View File

@ -3543,6 +3543,10 @@ class BomItem(DataImportMixin, models.Model):
def save(self, *args, **kwargs):
"""Enforce 'clean' operation when saving a BomItem instance"""
self.clean()
# Update the 'validated' field based on checksum calculation
self.validated = self.is_line_valid
super().save(*args, **kwargs)
# A link to the parent part
@ -3588,7 +3592,16 @@ class BomItem(DataImportMixin, models.Model):
# Note attached to this BOM line item
note = models.CharField(max_length=500, blank=True, verbose_name=_('Note'), help_text=_('BOM item notes'))
checksum = models.CharField(max_length=128, blank=True, verbose_name=_('Checksum'), help_text=_('BOM line checksum'))
checksum = models.CharField(
max_length=128, blank=True,
verbose_name=_('Checksum'), help_text=_('BOM line checksum')
)
validated = models.BooleanField(
default=False,
verbose_name=_('Validated'),
help_text=_('This BOM item has been validated')
)
inherited = models.BooleanField(
default=False,