From a7229b5b0b03106bddeae0130447b5ff2c560b64 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 28 Jul 2021 22:50:03 +1000 Subject: [PATCH 1/8] Merge pull request #1874 from SchrodingersGat/docker-dev-fix Copy static files when starting dev server (cherry picked from commit 50eb70f538a0788a4e565db0b4a5775a2ee5bf78) --- docker/start_dev_server.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/start_dev_server.sh b/docker/start_dev_server.sh index fcd178915c..a12a958a9a 100644 --- a/docker/start_dev_server.sh +++ b/docker/start_dev_server.sh @@ -45,5 +45,7 @@ python3 manage.py migrate --noinput || exit 1 python3 manage.py migrate --run-syncdb || exit 1 python3 manage.py clearsessions || exit 1 +invoke static + # Launch a development server python3 manage.py runserver ${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT} From 0a73032950a7698393cc2b57a50a457426c527ed Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 29 Jul 2021 08:27:20 +1000 Subject: [PATCH 2/8] Merge pull request #1877 from eeintech/fix_search_js Fixed missing comma propagating to translated JS files (cherry picked from commit 2009773d9dca7ee309e70e14bd9aa656b54843c9) --- InvenTree/templates/js/inventree.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/templates/js/inventree.js b/InvenTree/templates/js/inventree.js index aa574eae83..aa87008fbe 100644 --- a/InvenTree/templates/js/inventree.js +++ b/InvenTree/templates/js/inventree.js @@ -94,7 +94,7 @@ function inventreeDocReady() { {% if request.user %} limit: {% settings_value 'SEARCH_PREVIEW_RESULTS' user=request.user %}, {% else %} - limit: 25 + limit: 25, {% endif %} offset: 0 }, From cd39fd1dc2356e9fcffd9eb4df8483b5903cc2f3 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 2 Aug 2021 08:34:52 +1000 Subject: [PATCH 3/8] Merge pull request #1890 from matmair/fix-for-1888 catch connection errors in exchange update (cherry picked from commit db57e9516bbb53f008a970331b83939c7e007d57) --- InvenTree/InvenTree/exchange.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/exchange.py b/InvenTree/InvenTree/exchange.py index c75a827cc7..9981e52ff7 100644 --- a/InvenTree/InvenTree/exchange.py +++ b/InvenTree/InvenTree/exchange.py @@ -1,4 +1,5 @@ from common.settings import currency_code_default, currency_codes +from urllib.error import HTTPError, URLError from djmoney.contrib.exchange.backends.base import SimpleExchangeBackend @@ -26,4 +27,8 @@ class InvenTreeExchange(SimpleExchangeBackend): symbols = ','.join(currency_codes()) - super().update_rates(base=base_currency, symbols=symbols) + try: + super().update_rates(base=base_currency, symbols=symbols) + # catch connection errors + except (HTTPError, URLError): + print('Encountered connection error while updating') From 20cc95298296c5a8e2364ce771f8e8a8479e879e Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 2 Aug 2021 08:38:34 +1000 Subject: [PATCH 4/8] Merge pull request #1887 from matmair/settings-safety settings fixes (cherry picked from commit d154ca08ea31f990b8de765cce211b362914afb2) --- .../management/commands/clean_settings.py | 38 +++++++++++++++++++ InvenTree/common/models.py | 16 ++++---- InvenTree/templates/js/dynamic/settings.js | 4 +- tasks.py | 10 ++++- 4 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 InvenTree/InvenTree/management/commands/clean_settings.py diff --git a/InvenTree/InvenTree/management/commands/clean_settings.py b/InvenTree/InvenTree/management/commands/clean_settings.py new file mode 100644 index 0000000000..e0fd09e6c7 --- /dev/null +++ b/InvenTree/InvenTree/management/commands/clean_settings.py @@ -0,0 +1,38 @@ +""" +Custom management command to cleanup old settings that are not defined anymore +""" + +from django.core.management.base import BaseCommand + + +class Command(BaseCommand): + """ + Cleanup old (undefined) settings in the database + """ + + def handle(self, *args, **kwargs): + + print("Collecting settings") + from common.models import InvenTreeSetting, InvenTreeUserSetting + + # general settings + db_settings = InvenTreeSetting.objects.all() + model_settings = InvenTreeSetting.GLOBAL_SETTINGS + + # check if key exist and delete if not + for setting in db_settings: + if setting.key not in model_settings: + setting.delete() + print(f"deleted setting '{setting.key}'") + + # user settings + db_settings = InvenTreeUserSetting.objects.all() + model_settings = InvenTreeUserSetting.GLOBAL_SETTINGS + + # check if key exist and delete if not + for setting in db_settings: + if setting.key not in model_settings: + setting.delete() + print(f"deleted user setting '{setting.key}'") + + print("checked all settings") diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 54dc21c1b5..5d75a4dd74 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -20,6 +20,7 @@ from djmoney.contrib.exchange.models import convert_money from djmoney.contrib.exchange.exceptions import MissingRate from django.utils.translation import ugettext_lazy as _ +from django.utils.html import format_html from django.core.validators import MinValueValidator, URLValidator from django.core.exceptions import ValidationError @@ -58,12 +59,13 @@ class BaseInvenTreeSetting(models.Model): # Query the database for setting in results: - settings.append({ - "key": setting.key.upper(), - "value": setting.value - }) + if setting.key: + settings.append({ + "key": setting.key.upper(), + "value": setting.value + }) - keys.add(setting.key.upper()) + keys.add(setting.key.upper()) # Specify any "default" values which are not in the database for key in cls.GLOBAL_SETTINGS.keys(): @@ -90,10 +92,10 @@ class BaseInvenTreeSetting(models.Model): # Numerical values remain the same elif cls.validator_is_int(validator): pass - + # Wrap strings with quotes else: - value = f"'{value}'" + value = format_html("'{}'", value) setting["value"] = value diff --git a/InvenTree/templates/js/dynamic/settings.js b/InvenTree/templates/js/dynamic/settings.js index 4cc824ed6c..ad4e297c4a 100644 --- a/InvenTree/templates/js/dynamic/settings.js +++ b/InvenTree/templates/js/dynamic/settings.js @@ -6,12 +6,12 @@ var user_settings = { {% for setting in USER_SETTINGS %} - {{ setting.key }}: {{ setting.value|safe }}, + {{ setting.key }}: {{ setting.value }}, {% endfor %} }; var global_settings = { {% for setting in GLOBAL_SETTINGS %} - {{ setting.key }}: {{ setting.value|safe }}, + {{ setting.key }}: {{ setting.value }}, {% endfor %} }; \ No newline at end of file diff --git a/tasks.py b/tasks.py index b78a135b08..a9168f4649 100644 --- a/tasks.py +++ b/tasks.py @@ -137,6 +137,14 @@ def rebuild(c): manage(c, "rebuild_models") +@task +def clean_settings(c): + """ + Clean the setting tables of old settings + """ + + manage(c, "clean_settings") + @task def migrate(c): """ @@ -167,7 +175,7 @@ def static(c): manage(c, "collectstatic --no-input") -@task(pre=[install, migrate, static]) +@task(pre=[install, migrate, static, clean_settings]) def update(c): """ Update InvenTree installation. From b18f360daf0a910109a9dbe5bcf3f424e6dff900 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 2 Aug 2021 08:43:04 +1000 Subject: [PATCH 5/8] 0.4.2 --- InvenTree/InvenTree/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index bb7d310851..4aac8fca83 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -8,7 +8,7 @@ import re import common.models -INVENTREE_SW_VERSION = "0.4.1" +INVENTREE_SW_VERSION = "0.4.2" INVENTREE_API_VERSION = 8 From 073bb7c48823a9b32ba6ac035c2d21a0a05790ba Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 3 Aug 2021 10:03:05 +1000 Subject: [PATCH 6/8] Merge pull request #1894 from SchrodingersGat/non-int-serial-fix Fix for non-integer serial numbers (cherry picked from commit 529742b5203005d5d71921c1ee32cd1bc540af4d) --- .../stock/templates/stock/item_base.html | 2 +- InvenTree/stock/views.py | 44 +++++++++++++------ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index b16d9b0b1a..91c3209013 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -253,7 +253,7 @@ {{ previous.serial }} ‹ {% endif %} - {{ item.serial }} + {{ item.serial }} {% if next %} {{ next.serial }} diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 80968e5aa9..7b6fbc527e 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -92,21 +92,39 @@ class StockItemDetail(InvenTreeRoleMixin, DetailView): data = super().get_context_data(**kwargs) if self.object.serialized: - serial_elem = {int(a.serial): a for a in self.object.part.stock_items.all() if a.serialized} - serials = serial_elem.keys() - current = int(self.object.serial) - # previous - for nbr in range(current - 1, -1, -1): - if nbr in serials: - data['previous'] = serial_elem.get(nbr, None) - break + serial_elem = {} - # next - for nbr in range(current + 1, max(serials) + 1): - if nbr in serials: - data['next'] = serial_elem.get(nbr, None) - break + try: + current = int(self.object.serial) + + for item in self.object.part.stock_items.all(): + + if item.serialized: + try: + sn = int(item.serial) + serial_elem[sn] = item + except ValueError: + # We only support integer serial number progression + pass + + serials = serial_elem.keys() + + # previous + for nbr in range(current - 1, min(serials), -1): + if nbr in serials: + data['previous'] = serial_elem.get(nbr, None) + break + + # next + for nbr in range(current + 1, max(serials) + 1): + if nbr in serials: + data['next'] = serial_elem.get(nbr, None) + break + + except ValueError: + # We only support integer serial number progression + pass return data From a846334698469d7514f69958c2888ff3f0307dd9 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 9 Aug 2021 09:45:56 +1000 Subject: [PATCH 7/8] 0.4.4 Bump release version --- InvenTree/InvenTree/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index 4aac8fca83..4fd722b064 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -8,7 +8,7 @@ import re import common.models -INVENTREE_SW_VERSION = "0.4.2" +INVENTREE_SW_VERSION = "0.4.4" INVENTREE_API_VERSION = 8 From 47c385cac28eae3057d058cb9e614297ae228133 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 11 Aug 2021 00:30:14 +1000 Subject: [PATCH 8/8] Bump version number -> 0.4.5 --- InvenTree/InvenTree/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index 8be4cf4791..c25b1abb67 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -8,7 +8,7 @@ import re import common.models -INVENTREE_SW_VERSION = "0.4.4" +INVENTREE_SW_VERSION = "0.4.5" INVENTREE_API_VERSION = 9