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