2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-03-04 03:11:46 +00:00

Allow Zero Quantity BOM Item with System Setting (#11437)

* allow zero qty bom item with setting

* add allow zero bom qty setting to docs

---------

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
Jacob Felknor
2026-03-02 17:10:20 -07:00
committed by GitHub
parent 3bbdddf51d
commit 41a617febd
4 changed files with 25 additions and 2 deletions

View File

@@ -170,6 +170,7 @@ Configuration of label printing:
{{ globalsetting("PART_SALABLE") }} {{ globalsetting("PART_SALABLE") }}
{{ globalsetting("PART_VIRTUAL") }} {{ globalsetting("PART_VIRTUAL") }}
{{ globalsetting("PART_COPY_BOM") }} {{ globalsetting("PART_COPY_BOM") }}
{{ globalsetting("PART_BOM_ALLOW_ZERO_QUANTITY") }}
{{ globalsetting("PART_COPY_PARAMETERS") }} {{ globalsetting("PART_COPY_PARAMETERS") }}
{{ globalsetting("PART_COPY_TESTS") }} {{ globalsetting("PART_COPY_TESTS") }}
{{ globalsetting("PART_CATEGORY_PARAMETERS") }} {{ globalsetting("PART_CATEGORY_PARAMETERS") }}

View File

@@ -637,6 +637,14 @@ SYSTEM_SETTINGS: dict[str, InvenTreeSettingsKeyType] = {
'default': False, 'default': False,
'validator': bool, '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': { 'LABEL_ENABLE': {
'name': _('Enable label printing'), 'name': _('Enable label printing'),
'description': _('Enable label printing from the web interface'), 'description': _('Enable label printing from the web interface'),

View File

@@ -22,6 +22,7 @@ from sql_util.utils import SubqueryCount
import common.currency import common.currency
import common.filters import common.filters
import common.models
import common.serializers import common.serializers
import company.models import company.models
import InvenTree.helpers import InvenTree.helpers
@@ -1656,8 +1657,20 @@ class BomItemSerializer(
def validate_quantity(self, quantity): def validate_quantity(self, quantity):
"""Perform validation for the BomItem quantity field.""" """Perform validation for the BomItem quantity field."""
if quantity <= 0: allow_zero_qty = common.models.InvenTreeSetting.get_setting(
raise serializers.ValidationError(_('Quantity must be greater than zero')) '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 return quantity

View File

@@ -217,6 +217,7 @@ export default function SystemSettings() {
'PART_SALABLE', 'PART_SALABLE',
'PART_VIRTUAL', 'PART_VIRTUAL',
'PART_COPY_BOM', 'PART_COPY_BOM',
'PART_BOM_ALLOW_ZERO_QUANTITY',
'PART_COPY_PARAMETERS', 'PART_COPY_PARAMETERS',
'PART_COPY_TESTS', 'PART_COPY_TESTS',
'PART_CATEGORY_PARAMETERS', 'PART_CATEGORY_PARAMETERS',