Coverage for src/paperap/models/document_type/model.py: 95%
19 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-22 16:02 -0400
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-22 16:02 -0400
1"""
2----------------------------------------------------------------------------
4 METADATA:
6 File: document_type.py
7 Project: paperap
8 Created: 2025-03-04
9 Version: 0.0.9
10 Author: Jess Mann
11 Email: jess@jmann.me
12 Copyright (c) 2025 Jess Mann
14----------------------------------------------------------------------------
16 LAST MODIFIED:
18 2025-03-04 By Jess Mann
20"""
22from __future__ import annotations
24from datetime import datetime
25from typing import TYPE_CHECKING, Any
27from paperap.const import MatchingAlgorithmType
28from paperap.models.abstract.model import StandardModel
29from paperap.models.document_type.queryset import DocumentTypeQuerySet
30from paperap.models.mixins.models import MatcherMixin
32if TYPE_CHECKING:
33 from paperap.models.document import Document, DocumentQuerySet
36class DocumentType(StandardModel, MatcherMixin):
37 """
38 Represents a document type in Paperless-NgX.
40 Attributes:
41 name: The name of the document type.
42 slug: A unique identifier for the document type.
43 match: The pattern used for matching documents.
44 matching_algorithm: The algorithm used for matching.
45 is_insensitive: Whether the matching is case insensitive.
46 document_count: The number of documents of this type.
47 owner: The owner of the document type.
48 user_can_change: Whether the user can change the document type.
50 Returns:
51 A new instance of DocumentType.
53 Examples:
54 # Create a new DocumentType instance
55 doc_type = DocumentType(name="Invoice", slug="invoice", match="INV-*")
57 """
59 name: str
60 slug: str | None = None
61 document_count: int = 0
62 owner: int | None = None
63 user_can_change: bool | None = None
65 class Meta(StandardModel.Meta):
66 # Fields that should not be modified
67 read_only_fields = {"slug", "document_count"}
68 queryset = DocumentTypeQuerySet
70 @property
71 def documents(self) -> "DocumentQuerySet":
72 """
73 Get documents with this document type.
75 Returns:
76 A DocumentQuerySet containing documents of this type.
78 Examples:
79 # Get all documents of this type
80 documents = doc_type.documents
81 Get documents with this document type.
83 """
84 return self._client.documents().all().document_type_id(self.id)