2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-15 03:25:42 +00:00

Add some helper magic for setting objects

- If the setting is defined as a "bool" then the returned value is automatically cast to a bool
- Add some more unit testing
This commit is contained in:
Oliver Walters
2020-11-09 23:44:54 +11:00
parent 75ab7b247b
commit c95f124578
5 changed files with 112 additions and 7 deletions

View File

@ -85,6 +85,13 @@ class InvenTreeSetting(models.Model):
'validator': bool
},
'PART_COMPONENT': {
'name': _('Component'),
'description': _('Parts can be used as sub-components by default'),
'default': True,
'validator': bool,
},
'PART_PURCHASEABLE': {
'name': _('Purchaseable'),
'description': _('Parts are purchaseable by default'),
@ -264,6 +271,11 @@ class InvenTreeSetting(models.Model):
if setting:
value = setting.value
# If the particular setting is defined as a boolean, cast the value to a boolean
if setting.is_bool():
value = InvenTree.helpers.str2bool(value)
else:
value = backup_value