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:
parent
1335c85de1
commit
d0fb69e67d
@ -159,7 +159,14 @@ class InvenTreeSetting(models.Model):
|
|||||||
'default': False,
|
'default': False,
|
||||||
'validator': bool,
|
'validator': bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'STOCK_ENABLE_EXPIRY': {
|
||||||
|
'name': _('Stock Expiry'),
|
||||||
|
'description': _('Enable stock expiry functionality'),
|
||||||
|
'default': False,
|
||||||
|
'validator': bool,
|
||||||
|
},
|
||||||
|
|
||||||
'STOCK_ALLOW_EXPIRED_SALE': {
|
'STOCK_ALLOW_EXPIRED_SALE': {
|
||||||
'name': _('Sell Expired Stock'),
|
'name': _('Sell Expired Stock'),
|
||||||
'description': _('Allow sale of expired stock'),
|
'description': _('Allow sale of expired stock'),
|
||||||
@ -373,6 +380,10 @@ class InvenTreeSetting(models.Model):
|
|||||||
if setting.is_bool():
|
if setting.is_bool():
|
||||||
value = InvenTree.helpers.str2bool(value)
|
value = InvenTree.helpers.str2bool(value)
|
||||||
|
|
||||||
|
if setting.is_int():
|
||||||
|
# TODO - Coerce to an integer value
|
||||||
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
value = backup_value
|
value = backup_value
|
||||||
|
|
||||||
@ -523,7 +534,7 @@ class InvenTreeSetting(models.Model):
|
|||||||
- 'neg' / 'negative' = any negative integer value (including zero)
|
- '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']
|
return validator in [int, 'int', 'pos', 'positive', 'neg', 'negative']
|
||||||
|
|
||||||
|
@ -21,3 +21,11 @@ def currency_code_default():
|
|||||||
code = 'USD'
|
code = 'USD'
|
||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
|
|
||||||
|
def stock_expiry_enabled():
|
||||||
|
"""
|
||||||
|
Returns True if the stock expiry feature is enabled
|
||||||
|
"""
|
||||||
|
|
||||||
|
return InvenTreeSetting.get_setting('STOCK_ENABLE_EXPIRY')
|
||||||
|
@ -35,6 +35,8 @@ from .models import PartSellPriceBreak
|
|||||||
from common.models import InvenTreeSetting
|
from common.models import InvenTreeSetting
|
||||||
from company.models import SupplierPart
|
from company.models import SupplierPart
|
||||||
|
|
||||||
|
import common.settings as inventree_settings
|
||||||
|
|
||||||
from . import forms as part_forms
|
from . import forms as part_forms
|
||||||
from .bom import MakeBomTemplate, BomUploadManager, ExportBom, IsValidBOMFormat
|
from .bom import MakeBomTemplate, BomUploadManager, ExportBom, IsValidBOMFormat
|
||||||
|
|
||||||
@ -626,6 +628,10 @@ class PartCreate(AjaxCreateView):
|
|||||||
"""
|
"""
|
||||||
form = super(AjaxCreateView, self).get_form()
|
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!)
|
# Hide the default_supplier field (there are no matching supplier parts yet!)
|
||||||
form.fields['default_supplier'].widget = HiddenInput()
|
form.fields['default_supplier'].widget = HiddenInput()
|
||||||
|
|
||||||
@ -918,6 +924,10 @@ class PartEdit(AjaxUpdateView):
|
|||||||
|
|
||||||
form = super(AjaxUpdateView, self).get_form()
|
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()
|
part = self.get_object()
|
||||||
|
|
||||||
form.fields['default_supplier'].queryset = SupplierPart.objects.filter(part=part)
|
form.fields['default_supplier'].queryset = SupplierPart.objects.filter(part=part)
|
||||||
|
@ -1302,6 +1302,10 @@ class StockItemEdit(AjaxUpdateView):
|
|||||||
|
|
||||||
form = super(AjaxUpdateView, self).get_form()
|
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()
|
item = self.get_object()
|
||||||
|
|
||||||
# If the part cannot be purchased, hide the supplier_part field
|
# If the part cannot be purchased, hide the supplier_part field
|
||||||
@ -1513,6 +1517,10 @@ class StockItemCreate(AjaxCreateView):
|
|||||||
|
|
||||||
form = super().get_form()
|
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)
|
part = self.get_part(form=form)
|
||||||
|
|
||||||
if part is not None:
|
if part is not None:
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
<table class='table table-striped table-condensed'>
|
<table class='table table-striped table-condensed'>
|
||||||
{% include "InvenTree/settings/header.html" %}
|
{% include "InvenTree/settings/header.html" %}
|
||||||
<tbody>
|
<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_SALE" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="STOCK_ALLOW_EXPIRED_BUILD" %}
|
{% include "InvenTree/settings/setting.html" with key="STOCK_ALLOW_EXPIRED_BUILD" %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user