mirror of
https://github.com/inventree/InvenTree.git
synced 2026-11-26 17:48:54 +00:00
[bug] Fix for STOCKTAKE_AUTO_DAYS (#13376)
Previously had incorrect MinValueValidator
This commit is contained in:
1 parent
0c7551b8ae
commit
2bd548296b
2 files changed
+28
-2
No files matched your search
@@ -197,8 +197,10 @@ SYSTEM_SETTINGS: dict[str, InvenTreeSettingsKeyType] = {
|
||||
},
|
||||
'STOCKTAKE_AUTO_DAYS': {
|
||||
'name': _('Automatic Stocktake Period'),
|
||||
'description': _('Number of days between automatic stocktake recording'),
|
||||
'validator': [int, MinValueValidator(1)],
|
||||
'description': _(
|
||||
'Number of days between automatic stocktake recording (set to zero to disable)'
|
||||
),
|
||||
'validator': [int, MinValueValidator(0)],
|
||||
'default': 7,
|
||||
'units': _('days'),
|
||||
},
|
||||
|
||||
@@ -1065,3 +1065,27 @@ class PartStockHistoryTest(InvenTreeTestCase):
|
||||
N_STOCKTAKE = PartStocktake.objects.count()
|
||||
perform_stocktake()
|
||||
self.assertEqual(PartStocktake.objects.count(), N_STOCKTAKE)
|
||||
|
||||
def test_auto_stocktake_period(self):
|
||||
"""Test that STOCKTAKE_AUTO_DAYS can be set to zero to disable automatic stocktake."""
|
||||
from part.models import PartStocktake
|
||||
from part.tasks import scheduled_stocktake_reports
|
||||
|
||||
set_global_setting('STOCKTAKE_ENABLE', True)
|
||||
|
||||
# Negative values are not allowed
|
||||
with self.assertRaises(ValidationError):
|
||||
set_global_setting('STOCKTAKE_AUTO_DAYS', -1)
|
||||
|
||||
# Zero is allowed, and disables automatic stocktake
|
||||
set_global_setting('STOCKTAKE_AUTO_DAYS', 0)
|
||||
self.assertEqual(get_global_setting('STOCKTAKE_AUTO_DAYS'), 0)
|
||||
|
||||
N = PartStocktake.objects.count()
|
||||
scheduled_stocktake_reports()
|
||||
self.assertEqual(PartStocktake.objects.count(), N)
|
||||
|
||||
# A positive value enables automatic stocktake
|
||||
set_global_setting('STOCKTAKE_AUTO_DAYS', 1)
|
||||
scheduled_stocktake_reports()
|
||||
self.assertGreater(PartStocktake.objects.count(), N)
|
||||
Reference in new issue
Block a user