diff --git a/docs/docs/settings/global.md b/docs/docs/settings/global.md index d443084077..66dddda681 100644 --- a/docs/docs/settings/global.md +++ b/docs/docs/settings/global.md @@ -170,6 +170,7 @@ Configuration of label printing: {{ globalsetting("PART_SALABLE") }} {{ globalsetting("PART_VIRTUAL") }} {{ globalsetting("PART_COPY_BOM") }} +{{ globalsetting("PART_BOM_ALLOW_ZERO_QUANTITY") }} {{ globalsetting("PART_COPY_PARAMETERS") }} {{ globalsetting("PART_COPY_TESTS") }} {{ globalsetting("PART_CATEGORY_PARAMETERS") }} diff --git a/src/backend/InvenTree/common/setting/system.py b/src/backend/InvenTree/common/setting/system.py index 156e6e61b3..00fb35a558 100644 --- a/src/backend/InvenTree/common/setting/system.py +++ b/src/backend/InvenTree/common/setting/system.py @@ -637,6 +637,14 @@ SYSTEM_SETTINGS: dict[str, InvenTreeSettingsKeyType] = { 'default': False, 'validator': bool, }, + 'PART_BOM_ALLOW_ZERO_QUANTITY': { + 'name': _('Allow BOM Zero Quantity'), + 'description': _( + 'Accept a zero quantity for BOM item for part. Enables using setup quantity to define a quantity required per build, independent of build quantity' + ), + 'default': False, + 'validator': bool, + }, 'LABEL_ENABLE': { 'name': _('Enable label printing'), 'description': _('Enable label printing from the web interface'), diff --git a/src/backend/InvenTree/part/serializers.py b/src/backend/InvenTree/part/serializers.py index bb27afe074..8102ac4641 100644 --- a/src/backend/InvenTree/part/serializers.py +++ b/src/backend/InvenTree/part/serializers.py @@ -22,6 +22,7 @@ from sql_util.utils import SubqueryCount import common.currency import common.filters +import common.models import common.serializers import company.models import InvenTree.helpers @@ -1656,8 +1657,20 @@ class BomItemSerializer( def validate_quantity(self, quantity): """Perform validation for the BomItem quantity field.""" - if quantity <= 0: - raise serializers.ValidationError(_('Quantity must be greater than zero')) + allow_zero_qty = common.models.InvenTreeSetting.get_setting( + 'PART_BOM_ALLOW_ZERO_QUANTITY', False + ) + + if allow_zero_qty: + if quantity < 0: + raise serializers.ValidationError( + _('Quantity must be greater than or equal to zero') + ) + else: + if quantity <= 0: + raise serializers.ValidationError( + _('Quantity must be greater than zero') + ) return quantity diff --git a/src/frontend/src/pages/Index/Settings/SystemSettings.tsx b/src/frontend/src/pages/Index/Settings/SystemSettings.tsx index e27fb6aa9e..0c3d4604cd 100644 --- a/src/frontend/src/pages/Index/Settings/SystemSettings.tsx +++ b/src/frontend/src/pages/Index/Settings/SystemSettings.tsx @@ -217,6 +217,7 @@ export default function SystemSettings() { 'PART_SALABLE', 'PART_VIRTUAL', 'PART_COPY_BOM', + 'PART_BOM_ALLOW_ZERO_QUANTITY', 'PART_COPY_PARAMETERS', 'PART_COPY_TESTS', 'PART_CATEGORY_PARAMETERS',