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:
@@ -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'),
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user