Apply suggestions from code review
This commit is contained in:
parent
f3d5f835db
commit
dd3ed7f2fa
@ -858,9 +858,9 @@ def parse_doc_title_w_placeholders(
|
||||
created: Optional[datetime.datetime] = None,
|
||||
) -> str:
|
||||
"""
|
||||
Title placeholders for Workflows using Consumption triggers can only include
|
||||
items that are assigned as part of this template (since auto-matching hasnt
|
||||
happened yet)
|
||||
Available title placeholders for Workflows depend on what has already been assigned,
|
||||
e.g. for pre-consumption triggers created will not have been parsed yet, but it will
|
||||
for added / updated triggers
|
||||
"""
|
||||
formatting = {
|
||||
"correspondent": correspondent_name,
|
||||
|
@ -19,12 +19,14 @@ from documents.permissions import get_objects_for_user_owner_aware
|
||||
logger = logging.getLogger("paperless.matching")
|
||||
|
||||
|
||||
def log_reason(matching_model: MatchingModel, document: Document, reason: str):
|
||||
def log_reason(
|
||||
matching_model: Union[MatchingModel, WorkflowTrigger],
|
||||
document: Document,
|
||||
reason: str,
|
||||
):
|
||||
class_name = type(matching_model).__name__
|
||||
name = (
|
||||
matching_model.name
|
||||
if hasattr(matching_model, "name")
|
||||
else matching_model.__str__()
|
||||
matching_model.name if hasattr(matching_model, "name") else str(matching_model)
|
||||
)
|
||||
logger.debug(
|
||||
f"{class_name} {name} matched on document {document} because {reason}",
|
||||
@ -258,13 +260,13 @@ def document_matches_workflow(
|
||||
logger.debug(reason)
|
||||
|
||||
trigger_matched = True
|
||||
triggers = workflow.triggers.filter(type=trigger_type)
|
||||
if len(triggers) == 0:
|
||||
if workflow.triggers.filter(type=trigger_type).count() == 0:
|
||||
trigger_matched = False
|
||||
log_match_failure(
|
||||
f"No matching triggers with type {trigger_type} found",
|
||||
)
|
||||
else:
|
||||
triggers = workflow.triggers.filter(type=trigger_type)
|
||||
for trigger in triggers:
|
||||
if trigger_type is WorkflowTrigger.WorkflowTriggerType.CONSUMPTION:
|
||||
# document is type ConsumableDocument
|
||||
@ -381,6 +383,10 @@ def document_matches_workflow(
|
||||
)
|
||||
trigger_matched = False
|
||||
|
||||
else:
|
||||
# New trigger types need to be checked above
|
||||
raise Exception(f"Trigger type {trigger_type} not yet supported")
|
||||
|
||||
if trigger_matched:
|
||||
logger.info(f"Document matched {trigger} from {workflow}")
|
||||
return True
|
||||
|
Loading…
x
Reference in New Issue
Block a user