2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 12:06:44 +00:00

Add option to enable / disable stock expiry feature

- Simply hides fields in form views
This commit is contained in:
Oliver Walters 2021-01-05 08:50:07 +11:00
parent 1335c85de1
commit d0fb69e67d
5 changed files with 40 additions and 2 deletions

View File

@ -159,7 +159,14 @@ class InvenTreeSetting(models.Model):
'default': False,
'validator': bool,
},
'STOCK_ENABLE_EXPIRY': {
'name': _('Stock Expiry'),
'description': _('Enable stock expiry functionality'),
'default': False,
'validator': bool,
},
'STOCK_ALLOW_EXPIRED_SALE': {
'name': _('Sell Expired Stock'),
'description': _('Allow sale of expired stock'),
@ -373,6 +380,10 @@ class InvenTreeSetting(models.Model):
if setting.is_bool():
value = InvenTree.helpers.str2bool(value)
if setting.is_int():
# TODO - Coerce to an integer value
pass
else:
value = backup_value
@ -523,7 +534,7 @@ class InvenTreeSetting(models.Model):
- 'neg' / 'negative' = any negative integer value (including zero)
"""
valiator = InvenTreeSetting.get_setting_validator(self.key)
validator = InvenTreeSetting.get_setting_validator(self.key)
return validator in [int, 'int', 'pos', 'positive', 'neg', 'negative']

View File

@ -21,3 +21,11 @@ def currency_code_default():
code = 'USD'
return code
def stock_expiry_enabled():
"""
Returns True if the stock expiry feature is enabled
"""
return InvenTreeSetting.get_setting('STOCK_ENABLE_EXPIRY')

View File

@ -35,6 +35,8 @@ from .models import PartSellPriceBreak
from common.models import InvenTreeSetting
from company.models import SupplierPart
import common.settings as inventree_settings
from . import forms as part_forms
from .bom import MakeBomTemplate, BomUploadManager, ExportBom, IsValidBOMFormat
@ -626,6 +628,10 @@ class PartCreate(AjaxCreateView):
"""
form = super(AjaxCreateView, self).get_form()
# Hide the "default expiry" field if the feature is not enabled
if not inventree_settings.stock_expiry_enabled():
form.fields.pop('default_expiry')
# Hide the default_supplier field (there are no matching supplier parts yet!)
form.fields['default_supplier'].widget = HiddenInput()
@ -918,6 +924,10 @@ class PartEdit(AjaxUpdateView):
form = super(AjaxUpdateView, self).get_form()
# Hide the "default expiry" field if the feature is not enabled
if not inventree_settings.stock_expiry_enabled():
form.fields.pop('default_expiry')
part = self.get_object()
form.fields['default_supplier'].queryset = SupplierPart.objects.filter(part=part)

View File

@ -1302,6 +1302,10 @@ class StockItemEdit(AjaxUpdateView):
form = super(AjaxUpdateView, self).get_form()
# Hide the "expiry date" field if the feature is not enabled
if not common.settings.stock_expiry_enabled():
form.fields.pop('expiry_date')
item = self.get_object()
# If the part cannot be purchased, hide the supplier_part field
@ -1513,6 +1517,10 @@ class StockItemCreate(AjaxCreateView):
form = super().get_form()
# Hide the "expiry date" field if the feature is not enabled
if not common.settings.stock_expiry_enabled():
form.fields.pop('expiry_date')
part = self.get_part(form=form)
if part is not None:

View File

@ -15,6 +15,7 @@
<table class='table table-striped table-condensed'>
{% include "InvenTree/settings/header.html" %}
<tbody>
{% include "InvenTree/settings/setting.html" with key="STOCK_ENABLE_EXPIRY" %}
{% include "InvenTree/settings/setting.html" with key="STOCK_ALLOW_EXPIRED_SALE" %}
{% include "InvenTree/settings/setting.html" with key="STOCK_ALLOW_EXPIRED_BUILD" %}
</tbody>