From d72efc3757310461524148cd21c7aa56bcb0d939 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 1 May 2022 22:30:24 +1000 Subject: [PATCH] Small tweaks - Factor out native_value property (not needed!) - PEP fixes --- InvenTree/common/models.py | 15 ++------------- InvenTree/common/tests.py | 5 ++--- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index a7a75fa180..543451b35e 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -398,17 +398,6 @@ class BaseInvenTreeSetting(models.Model): def units(self): return self.__class__.get_setting_units(self.key) - @property - def native_value(self): - - if self.is_bool(): - return self.as_bool() - - if self.is_int(): - return self.as_int() - - return self.value - def clean(self, **kwargs): """ If a validator (or multiple validators) are defined for a particular setting key, @@ -418,7 +407,7 @@ class BaseInvenTreeSetting(models.Model): super().clean() # Encode as native values - self.value = self.native_value + self.value = self.to_native_value() validator = self.__class__.get_setting_validator(self.key, **kwargs) @@ -1432,7 +1421,7 @@ class InvenTreeUserSetting(BaseInvenTreeSetting): ('MMM DD YYYY', 'Feb 22 2022'), ] }, - + 'DISPLAY_SCHEDULE_TAB': { 'name': _('Part Scheduling'), 'description': _('Display part scheduling information'), diff --git a/InvenTree/common/tests.py b/InvenTree/common/tests.py index dd98a79bc7..a8948fd29d 100644 --- a/InvenTree/common/tests.py +++ b/InvenTree/common/tests.py @@ -158,7 +158,6 @@ class SettingsTest(TestCase): raise ValueError(f'Non-boolean default value specified for {key}') # pragma: no cover - class GlobalSettingsApiTest(InvenTreeAPITestCase): """ Tests for the global settings API @@ -238,7 +237,7 @@ class UserSettingsApiTest(InvenTreeAPITestCase): ) # Check default values - self.assertEqual(setting.native_value, True) + self.assertEqual(setting.to_native_value(), True) # Fetch via API url = reverse('api-user-setting-detail', kwargs={'pk': setting.pk}) @@ -363,7 +362,7 @@ class UserSettingsApiTest(InvenTreeAPITestCase): ) setting.refresh_from_db() - self.assertEqual(setting.native_value, v) + self.assertEqual(setting.to_native_value(), v) # Set invalid options via the API # Note that this particular setting has a MinValueValidator(1) associated with it