From ae7f4e33d52f671584e9e99fc2b486f55f831edc Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 26 Dec 2024 10:42:07 +1100 Subject: [PATCH 1/4] Zero stock fix (#8766) * Change backend validation - Allow stock adjustments with zero quantity * Frontend changes --- src/backend/InvenTree/stock/models.py | 9 +++++++-- src/backend/InvenTree/stock/serializers.py | 4 +++- src/frontend/src/pages/stock/StockDetail.tsx | 3 +-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/backend/InvenTree/stock/models.py b/src/backend/InvenTree/stock/models.py index bd88bf7700..a8baa6c475 100644 --- a/src/backend/InvenTree/stock/models.py +++ b/src/backend/InvenTree/stock/models.py @@ -1504,17 +1504,22 @@ class StockItem( """ return self.children.count() - def is_in_stock(self, check_status: bool = True): + def is_in_stock( + self, check_status: bool = True, check_quantity: bool = True + ) -> bool: """Return True if this StockItem is "in stock". Args: check_status: If True, check the status of the StockItem. Defaults to True. + check_quantity: If True, check the quantity of the StockItem. Defaults to True. """ if check_status and self.status not in StockStatusGroups.AVAILABLE_CODES: return False + if check_quantity and self.quantity <= 0: + return False + return all([ - self.quantity > 0, # Quantity must be greater than zero self.sales_order is None, # Not assigned to a SalesOrder self.belongs_to is None, # Not installed inside another StockItem self.customer is None, # Not assigned to a customer diff --git a/src/backend/InvenTree/stock/serializers.py b/src/backend/InvenTree/stock/serializers.py index 55164bca3e..49cb20b27d 100644 --- a/src/backend/InvenTree/stock/serializers.py +++ b/src/backend/InvenTree/stock/serializers.py @@ -1571,7 +1571,9 @@ class StockAdjustmentItemSerializer(serializers.Serializer): 'STOCK_ALLOW_OUT_OF_STOCK_TRANSFER', backup_value=False, cache=False ) - if not allow_out_of_stock_transfer and not pk.is_in_stock(check_status=False): + if not allow_out_of_stock_transfer and not pk.is_in_stock( + check_status=False, check_quantity=False + ): raise ValidationError(_('Stock item is not in stock')) return pk diff --git a/src/frontend/src/pages/stock/StockDetail.tsx b/src/frontend/src/pages/stock/StockDetail.tsx index c362501458..0f408e0289 100644 --- a/src/frontend/src/pages/stock/StockDetail.tsx +++ b/src/frontend/src/pages/stock/StockDetail.tsx @@ -661,7 +661,6 @@ export default function StockDetail() { const stockActions = useMemo(() => { const inStock = user.hasChangeRole(UserRoles.stock) && - stockitem.quantity > 0 && !stockitem.sales_order && !stockitem.belongs_to && !stockitem.customer && @@ -717,7 +716,7 @@ export default function StockDetail() { { name: t`Remove`, tooltip: t`Remove Stock`, - hidden: serialized || !inStock, + hidden: serialized || !inStock || stockitem.quantity <= 0, icon: , onClick: () => { stockitem.pk && removeStockItem.open(); From d4ee8c53b21143bdf151010ebb3d3e27e1c3fb09 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 26 Dec 2024 11:25:58 +1100 Subject: [PATCH 2/4] Fix default value for SESSION_COOKIE_SECURE (#8767) - Default value was previously 'True' - Documentation indicated that it was 'False' - Value in config_template.yaml was 'False' (but commented out) --- src/backend/InvenTree/InvenTree/settings.py | 4 +++- src/backend/InvenTree/config_template.yaml | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/backend/InvenTree/InvenTree/settings.py b/src/backend/InvenTree/InvenTree/settings.py index 2a02e6f669..301f11fac4 100644 --- a/src/backend/InvenTree/InvenTree/settings.py +++ b/src/backend/InvenTree/InvenTree/settings.py @@ -1177,7 +1177,9 @@ SESSION_COOKIE_SECURE = ( if DEBUG else ( SESSION_COOKIE_SAMESITE == 'None' - or get_boolean_setting('INVENTREE_SESSION_COOKIE_SECURE', 'cookie.secure', True) + or get_boolean_setting( + 'INVENTREE_SESSION_COOKIE_SECURE', 'cookie.secure', False + ) ) ) diff --git a/src/backend/InvenTree/config_template.yaml b/src/backend/InvenTree/config_template.yaml index 7dcdde460d..99213ce9c3 100644 --- a/src/backend/InvenTree/config_template.yaml +++ b/src/backend/InvenTree/config_template.yaml @@ -124,9 +124,9 @@ use_x_forwarded_host: false use_x_forwarded_port: false # Cookie settings (nominally the default settings should be fine) -#cookie: -# secure: false -# samesite: false +cookie: + secure: false + samesite: false # Cross Origin Resource Sharing (CORS) settings (see https://github.com/adamchainz/django-cors-headers) cors: From da21e39e849fde93cc2c8aa9119dbf8a8583c41d Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Thu, 26 Dec 2024 10:16:53 +0100 Subject: [PATCH 3/4] Turn off debug by default (#8743) * turn off debug by default * fix log level / debug settings for workflows * fix typo --- .github/workflows/check_translations.yaml | 3 ++- .github/workflows/qc_checks.yaml | 16 +++++++++++----- .github/workflows/translations.yaml | 3 ++- src/backend/InvenTree/InvenTree/settings.py | 2 +- src/backend/InvenTree/config_template.yaml | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/check_translations.yaml b/.github/workflows/check_translations.yaml index c8628e1010..ec07c26f64 100644 --- a/.github/workflows/check_translations.yaml +++ b/.github/workflows/check_translations.yaml @@ -22,7 +22,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} INVENTREE_DB_NAME: "./test_db.sqlite" INVENTREE_DB_ENGINE: django.db.backends.sqlite3 - INVENTREE_DEBUG: info + INVENTREE_DEBUG: true + INVENTREE_LOG_LEVEL: INFO INVENTREE_MEDIA_ROOT: ./media INVENTREE_STATIC_ROOT: ./static INVENTREE_BACKUP_DIR: ./backup diff --git a/.github/workflows/qc_checks.yaml b/.github/workflows/qc_checks.yaml index 7b685369a3..a0c737f551 100644 --- a/.github/workflows/qc_checks.yaml +++ b/.github/workflows/qc_checks.yaml @@ -242,6 +242,8 @@ jobs: INVENTREE_PYTHON_TEST_USERNAME: testuser INVENTREE_PYTHON_TEST_PASSWORD: testpassword INVENTREE_SITE_URL: http://127.0.0.1:12345 + INVENTREE_DEBUG: true + INVENTREE_LOG_LEVEL: INFO steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4.2.2 @@ -324,7 +326,8 @@ jobs: INVENTREE_DB_PASSWORD: password INVENTREE_DB_HOST: "127.0.0.1" INVENTREE_DB_PORT: 5432 - INVENTREE_DEBUG: info + INVENTREE_DEBUG: true + INVENTREE_LOG_LEVEL: INFO INVENTREE_CACHE_HOST: localhost INVENTREE_PLUGINS_ENABLED: true @@ -372,7 +375,8 @@ jobs: INVENTREE_DB_PASSWORD: password INVENTREE_DB_HOST: "127.0.0.1" INVENTREE_DB_PORT: 3306 - INVENTREE_DEBUG: info + INVENTREE_DEBUG: true + INVENTREE_LOG_LEVEL: INFO INVENTREE_PLUGINS_ENABLED: true services: @@ -417,7 +421,8 @@ jobs: INVENTREE_DB_PASSWORD: password INVENTREE_DB_HOST: "127.0.0.1" INVENTREE_DB_PORT: 5432 - INVENTREE_DEBUG: info + INVENTREE_DEBUG: true + INVENTREE_LOG_LEVEL: INFO INVENTREE_PLUGINS_ENABLED: false services: @@ -459,7 +464,8 @@ jobs: env: INVENTREE_DB_ENGINE: sqlite3 INVENTREE_DB_NAME: /home/runner/work/InvenTree/db.sqlite3 - INVENTREE_DEBUG: info + INVENTREE_DEBUG: true + INVENTREE_LOG_LEVEL: INFO INVENTREE_PLUGINS_ENABLED: false steps: @@ -517,7 +523,7 @@ jobs: env: INVENTREE_DB_ENGINE: sqlite3 INVENTREE_DB_NAME: /home/runner/work/InvenTree/db.sqlite3 - INVENTREE_DEBUG: True + INVENTREE_DEBUG: true INVENTREE_PLUGINS_ENABLED: false VITE_COVERAGE: true diff --git a/.github/workflows/translations.yaml b/.github/workflows/translations.yaml index 82fd505457..dc769e7f28 100644 --- a/.github/workflows/translations.yaml +++ b/.github/workflows/translations.yaml @@ -23,7 +23,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} INVENTREE_DB_NAME: "./test_db.sqlite" INVENTREE_DB_ENGINE: django.db.backends.sqlite3 - INVENTREE_DEBUG: info + INVENTREE_DEBUG: true + INVENTREE_LOG_LEVEL: INFO INVENTREE_MEDIA_ROOT: ./media INVENTREE_STATIC_ROOT: ./static INVENTREE_BACKUP_DIR: ./backup diff --git a/src/backend/InvenTree/InvenTree/settings.py b/src/backend/InvenTree/InvenTree/settings.py index 301f11fac4..e86f087a42 100644 --- a/src/backend/InvenTree/InvenTree/settings.py +++ b/src/backend/InvenTree/InvenTree/settings.py @@ -77,7 +77,7 @@ if version_file.exists(): # Default action is to run the system in Debug mode # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = get_boolean_setting('INVENTREE_DEBUG', 'debug', True) +DEBUG = get_boolean_setting('INVENTREE_DEBUG', 'debug', False) # Configure logging settings LOG_LEVEL = get_setting('INVENTREE_LOG_LEVEL', 'log_level', 'WARNING') diff --git a/src/backend/InvenTree/config_template.yaml b/src/backend/InvenTree/config_template.yaml index 99213ce9c3..65c13d569c 100644 --- a/src/backend/InvenTree/config_template.yaml +++ b/src/backend/InvenTree/config_template.yaml @@ -26,7 +26,7 @@ database: # PORT: Database host port (if required) # Set debug to False to run in production mode, or use the environment variable INVENTREE_DEBUG -debug: True +debug: False # Additional debug options debug_querycount: False From 1d22b89ed6fe3229848880320dd2337659c13656 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 26 Dec 2024 23:43:49 +1100 Subject: [PATCH 4/4] DB CI Checks (#8773) * Update test databases in CI * Add new target --- .github/workflows/qc_checks.yaml | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/workflows/qc_checks.yaml b/.github/workflows/qc_checks.yaml index a0c737f551..bcf585be54 100644 --- a/.github/workflows/qc_checks.yaml +++ b/.github/workflows/qc_checks.yaml @@ -480,12 +480,6 @@ jobs: - name: Fetch Database run: git clone --depth 1 https://github.com/inventree/test-db ./test-db - - name: Latest Database - run: | - cp test-db/latest.sqlite3 /home/runner/work/InvenTree/db.sqlite3 - chmod +rw /home/runner/work/InvenTree/db.sqlite3 - invoke migrate - - name: 0.10.0 Database run: | rm /home/runner/work/InvenTree/db.sqlite3 @@ -500,13 +494,6 @@ jobs: chmod +rw /home/runner/work/InvenTree/db.sqlite3 invoke migrate - - name: 0.12.0 Database - run: | - rm /home/runner/work/InvenTree/db.sqlite3 - cp test-db/stable_0.12.0.sqlite3 /home/runner/work/InvenTree/db.sqlite3 - chmod +rw /home/runner/work/InvenTree/db.sqlite3 - invoke migrate - - name: 0.13.5 Database run: | rm /home/runner/work/InvenTree/db.sqlite3 @@ -514,6 +501,21 @@ jobs: chmod +rw /home/runner/work/InvenTree/db.sqlite3 invoke migrate + - name: 0.16.0 Database + run: | + rm /home/runner/work/InvenTree/db.sqlite3 + cp test-db/stable_0.13.5.sqlite3 /home/runner/work/InvenTree/db.sqlite3 + chmod +rw /home/runner/work/InvenTree/db.sqlite3 + invoke migrate + + - name: 0.17.0 Database + run: | + rm /home/runner/work/InvenTree/db.sqlite3 + cp test-db/stable_0.13.5.sqlite3 /home/runner/work/InvenTree/db.sqlite3 + chmod +rw /home/runner/work/InvenTree/db.sqlite3 + invoke migrate + + platform_ui: name: Tests - Platform UI runs-on: ubuntu-20.04