mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-02-01 23:19:00 -06:00
Refactor to separate AsnCheckPlugin
This commit is contained in:
@@ -13,7 +13,6 @@ from pikepdf import Page
|
|||||||
from pikepdf import PasswordError
|
from pikepdf import PasswordError
|
||||||
from pikepdf import Pdf
|
from pikepdf import Pdf
|
||||||
|
|
||||||
from documents.consumer import ConsumerPreflightPlugin
|
|
||||||
from documents.converters import convert_from_tiff_to_pdf
|
from documents.converters import convert_from_tiff_to_pdf
|
||||||
from documents.data_models import ConsumableDocument
|
from documents.data_models import ConsumableDocument
|
||||||
from documents.data_models import DocumentMetadataOverrides
|
from documents.data_models import DocumentMetadataOverrides
|
||||||
@@ -214,15 +213,6 @@ class BarcodePlugin(ConsumeTaskPlugin):
|
|||||||
):
|
):
|
||||||
logger.info(f"Found ASN in barcode: {located_asn}")
|
logger.info(f"Found ASN in barcode: {located_asn}")
|
||||||
self.metadata.asn = located_asn
|
self.metadata.asn = located_asn
|
||||||
# (Re-)run the preflight ASN check
|
|
||||||
preflight_plugin = ConsumerPreflightPlugin(
|
|
||||||
input_doc=self.input_doc,
|
|
||||||
metadata=self.metadata,
|
|
||||||
status_mgr=self.status_mgr,
|
|
||||||
base_tmp_dir=self.base_tmp_dir,
|
|
||||||
task_id=self.task_id,
|
|
||||||
)
|
|
||||||
preflight_plugin.pre_check_asn_value()
|
|
||||||
|
|
||||||
def cleanup(self) -> None:
|
def cleanup(self) -> None:
|
||||||
self.temp_dir.cleanup()
|
self.temp_dir.cleanup()
|
||||||
|
|||||||
@@ -828,6 +828,32 @@ class ConsumerPreflightPlugin(
|
|||||||
settings.ORIGINALS_DIR.mkdir(parents=True, exist_ok=True)
|
settings.ORIGINALS_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
settings.ARCHIVE_DIR.mkdir(parents=True, exist_ok=True)
|
settings.ARCHIVE_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
def run(self) -> None:
|
||||||
|
self._send_progress(
|
||||||
|
0,
|
||||||
|
100,
|
||||||
|
ProgressStatusOptions.STARTED,
|
||||||
|
ConsumerStatusShortMessage.NEW_FILE,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Make sure that preconditions for consuming the file are met.
|
||||||
|
|
||||||
|
self.pre_check_file_exists()
|
||||||
|
self.pre_check_duplicate()
|
||||||
|
self.pre_check_directories()
|
||||||
|
|
||||||
|
|
||||||
|
class AsnCheckPlugin(
|
||||||
|
NoCleanupPluginMixin,
|
||||||
|
NoSetupPluginMixin,
|
||||||
|
AlwaysRunPluginMixin,
|
||||||
|
LoggingMixin,
|
||||||
|
ConsumerPluginMixin,
|
||||||
|
ConsumeTaskPlugin,
|
||||||
|
):
|
||||||
|
NAME: str = "AsnCheckPlugin"
|
||||||
|
logging_name = "paperless.consumer"
|
||||||
|
|
||||||
def pre_check_asn_value(self):
|
def pre_check_asn_value(self):
|
||||||
"""
|
"""
|
||||||
Check that if override_asn is given, it is unique and within a valid range
|
Check that if override_asn is given, it is unique and within a valid range
|
||||||
@@ -865,16 +891,4 @@ class ConsumerPreflightPlugin(
|
|||||||
)
|
)
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
self._send_progress(
|
|
||||||
0,
|
|
||||||
100,
|
|
||||||
ProgressStatusOptions.STARTED,
|
|
||||||
ConsumerStatusShortMessage.NEW_FILE,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Make sure that preconditions for consuming the file are met.
|
|
||||||
|
|
||||||
self.pre_check_file_exists()
|
|
||||||
self.pre_check_duplicate()
|
|
||||||
self.pre_check_directories()
|
|
||||||
self.pre_check_asn_value()
|
self.pre_check_asn_value()
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ from documents.bulk_download import OriginalsOnlyStrategy
|
|||||||
from documents.caching import clear_document_caches
|
from documents.caching import clear_document_caches
|
||||||
from documents.classifier import DocumentClassifier
|
from documents.classifier import DocumentClassifier
|
||||||
from documents.classifier import load_classifier
|
from documents.classifier import load_classifier
|
||||||
|
from documents.consumer import AsnCheckPlugin
|
||||||
from documents.consumer import ConsumerPlugin
|
from documents.consumer import ConsumerPlugin
|
||||||
from documents.consumer import ConsumerPreflightPlugin
|
from documents.consumer import ConsumerPreflightPlugin
|
||||||
from documents.consumer import WorkflowTriggerPlugin
|
from documents.consumer import WorkflowTriggerPlugin
|
||||||
@@ -157,8 +158,10 @@ def consume_file(
|
|||||||
|
|
||||||
plugins: list[type[ConsumeTaskPlugin]] = [
|
plugins: list[type[ConsumeTaskPlugin]] = [
|
||||||
ConsumerPreflightPlugin,
|
ConsumerPreflightPlugin,
|
||||||
|
AsnCheckPlugin,
|
||||||
CollatePlugin,
|
CollatePlugin,
|
||||||
BarcodePlugin,
|
BarcodePlugin,
|
||||||
|
AsnCheckPlugin, # Re-run ASN check after barcode reading
|
||||||
WorkflowTriggerPlugin,
|
WorkflowTriggerPlugin,
|
||||||
ConsumerPlugin,
|
ConsumerPlugin,
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user