Repository: paperless-ngx/paperless-ngx

Issue:
[BUG] Disabling PAPERLESS_CONSUMER_ENABLE_BARCODES does not have the intended effect.
### Description

My paperless setup has the following config:
```
PAPERLESS_WORKER_TIMEOUT=3600
PAPERLESS_CONSUMER_ENABLE_ASN_BARCODE=true
PAPERLESS_CONSUMER_ASN_BARCODE_PREFIX=00
PAPERLESS_CONSUMER_ENABLE_BARCODES=false
```
However, if I ingest a document that has multiple barcodes it is still getting split. 
[sample.pdf](https://github.com/paperless-ngx/paperless-ngx/files/14248594/sample.pdf)

![image](https://github.com/paperless-ngx/paperless-ngx/assets/7033315/297c390d-4f78-4aee-a5f9-d6c9f75caa5f)

See [Discussion](https://github.com/paperless-ngx/paperless-ngx/discussions/5733)

### Steps to reproduce

1. Set the config as mentioned above
1. Ingest 
[sample.pdf](https://github.com/paperless-ngx/paperless-ngx/files/14248600/sample.pdf)


### Webserver logs

```bash
[2024-02-12 19:20:05,992] [DEBUG] [paperless.tasks] Skipping plugin CollatePlugin
[2024-02-12 19:20:05,993] [DEBUG] [paperless.tasks] Executing plugin BarcodePlugin
[2024-02-12 19:20:05,995] [DEBUG] [paperless.barcodes] Scanning for barcodes using PYZBAR
[2024-02-12 19:20:08,016] [DEBUG] [paperless.barcodes] Barcode of type CODE39 found: 07000000000000
[2024-02-12 19:20:08,559] [DEBUG] [paperless.barcodes] Barcode of type CODE39 found: 07000000000000
[2024-02-12 19:20:08,570] [DEBUG] [paperless.barcodes] Found ASN Barcode: 07000000000000
[2024-02-12 19:20:08,572] [INFO] [paperless.barcodes] Found ASN in barcode: 7000000000000
[2024-02-12 19:20:08,585] [DEBUG] [paperless.barcodes] Starting new document at idx 1
[2024-02-12 19:20:08,587] [DEBUG] [paperless.barcodes] Split into 2 new documents
[2024-02-12 19:20:08,590] [DEBUG] [paperless.barcodes] pdf no:0 has 1 pages
[2024-02-12 19:20:08,597] [DEBUG] [paperless.barcodes] pdf no:1 has 1 pages
```


### Browser logs

_No response_

### Paperless-ngx version

2.5.0

### Host OS

Raspberry PI arm64 Docker Compose

### Installation method

Docker - official image

### Browser

_No response_

### Configuration changes

PAPERLESS_WORKER_TIMEOUT=3600 PAPERLESS_CONSUMER_ENABLE_ASN_BARCODE=true PAPERLESS_CONSUMER_ASN_BARCODE_PREFIX=00 PAPERLESS_CONSUMER_ENABLE_BARCODES=false

### Other

_No response_

### Please confirm the following

- [X] I believe this issue is a bug that affects all users of Paperless-ngx, not something specific to my installation.
- [X] I have already searched for relevant existing issues and discussions before opening this report.
- [X] I have updated the title field above with a concise description.


Discussion:

Resolving patch:
diff --git a/src/documents/barcodes.py b/src/documents/barcodes.py
--- a/src/documents/barcodes.py
+++ b/src/documents/barcodes.py
@@ -88,64 +88,71 @@ def run(self) -> Optional[str]:
         self.detect()
 
         # Update/overwrite an ASN if possible
-        located_asn = self.asn
-        if located_asn is not None:
+        if (
+            settings.CONSUMER_ENABLE_ASN_BARCODE
+            and (located_asn := self.asn) is not None
+        ):
             logger.info(f"Found ASN in barcode: {located_asn}")
             self.metadata.asn = located_asn
 
         # try reading tags from barcodes
-        if settings.CONSUMER_ENABLE_TAG_BARCODE:
-            tags = self.tags
-            if tags is not None and len(tags) > 0:
-                if self.metadata.tag_ids:
-                    self.metadata.tag_ids += tags
-                else:
-                    self.metadata.tag_ids = tags
-                logger.info(f"Found tags in barcode: {tags}")
-
-        separator_pages = self.get_separation_pages()
-        if not separator_pages:
-            return "No pages to split on!"
-
-        # We have pages to split against
-
-        # Note this does NOT use the base_temp_dir, as that will be removed
-        tmp_dir = Path(
-            tempfile.mkdtemp(
-                dir=settings.SCRATCH_DIR,
-                prefix="paperless-barcode-split-",
-            ),
-        ).resolve()
-
-        from documents import tasks
-
-        # Create the split document tasks
-        for new_document in self.separate_pages(separator_pages):
-            copy_file_with_basic_stats(new_document, tmp_dir / new_document.name)
-
-            task = tasks.consume_file.delay(
-                ConsumableDocument(
-                    # Same source, for templates
-                    source=self.input_doc.source,
-                    mailrule_id=self.input_doc.mailrule_id,
-                    # Can't use same folder or the consume might grab it again
-                    original_file=(tmp_dir / new_document.name).resolve(),
+        if (
+            settings.CONSUMER_ENABLE_TAG_BARCODE
+            and (tags := self.tags) is not None
+            and len(tags) > 0
+        ):
+            if self.metadata.tag_ids:
+                self.metadata.tag_ids += tags
+            else:
+                self.metadata.tag_ids = tags
+            logger.info(f"Found tags in barcode: {tags}")
+
+        # Lastly attempt to split documents
+        if settings.CONSUMER_ENABLE_BARCODES:
+
+            separator_pages = self.get_separation_pages()
+            if not separator_pages:
+                return "No pages to split on!"
+
+            # We have pages to split against
+
+            # Note this does NOT use the base_temp_dir, as that will be removed
+            tmp_dir = Path(
+                tempfile.mkdtemp(
+                    dir=settings.SCRATCH_DIR,
+                    prefix="paperless-barcode-split-",
                 ),
-                # All the same metadata
-                self.metadata,
-            )
-            logger.info(f"Created new task {task.id} for {new_document.name}")
+            ).resolve()
+
+            from documents import tasks
+
+            # Create the split document tasks
+            for new_document in self.separate_pages(separator_pages):
+                copy_file_with_basic_stats(new_document, tmp_dir / new_document.name)
+
+                task = tasks.consume_file.delay(
+                    ConsumableDocument(
+                        # Same source, for templates
+                        source=self.input_doc.source,
+                        mailrule_id=self.input_doc.mailrule_id,
+                        # Can't use same folder or the consume might grab it again
+                        original_file=(tmp_dir / new_document.name).resolve(),
+                    ),
+                    # All the same metadata
+                    self.metadata,
+                )
+                logger.info(f"Created new task {task.id} for {new_document.name}")
 
-        # This file is now two or more files
-        self.input_doc.original_file.unlink()
+            # This file is now two or more files
+            self.input_doc.original_file.unlink()
 
-        msg = "Barcode splitting complete!"
+            msg = "Barcode splitting complete!"
 
-        # Update the progress to complete
-        self.status_mgr.send_progress(ProgressStatusOptions.SUCCESS, msg, 100, 100)
+            # Update the progress to complete
+            self.status_mgr.send_progress(ProgressStatusOptions.SUCCESS, msg, 100, 100)
 
-        # Request the consume task stops
-        raise StopConsumeTaskError(msg)
+            # Request the consume task stops
+            raise StopConsumeTaskError(msg)
 
     def cleanup(self) -> None:
         self.temp_dir.cleanup()


Test patch:
diff --git a/src/documents/tests/test_barcodes.py b/src/documents/tests/test_barcodes.py
--- a/src/documents/tests/test_barcodes.py
+++ b/src/documents/tests/test_barcodes.py
@@ -402,6 +402,7 @@ def test_separate_pages_double_code(self):
 
             self.assertEqual(len(documents), 2)
 
+    @override_settings(CONSUMER_ENABLE_BARCODES=True)
     def test_separate_pages_no_list(self):
         """
         GIVEN: