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

1""" 

2---------------------------------------------------------------------------- 

3 

4 METADATA: 

5 

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 

13 

14---------------------------------------------------------------------------- 

15 

16 LAST MODIFIED: 

17 

18 2025-03-04 By Jess Mann 

19 

20""" 

21 

22from __future__ import annotations 

23 

24from datetime import datetime 

25from typing import TYPE_CHECKING, Any 

26 

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 

31 

32if TYPE_CHECKING: 

33 from paperap.models.document import Document, DocumentQuerySet 

34 

35 

36class DocumentType(StandardModel, MatcherMixin): 

37 """ 

38 Represents a document type in Paperless-NgX. 

39 

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. 

49 

50 Returns: 

51 A new instance of DocumentType. 

52 

53 Examples: 

54 # Create a new DocumentType instance 

55 doc_type = DocumentType(name="Invoice", slug="invoice", match="INV-*") 

56 

57 """ 

58 

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 

64 

65 class Meta(StandardModel.Meta): 

66 # Fields that should not be modified 

67 read_only_fields = {"slug", "document_count"} 

68 queryset = DocumentTypeQuerySet 

69 

70 @property 

71 def documents(self) -> "DocumentQuerySet": 

72 """ 

73 Get documents with this document type. 

74 

75 Returns: 

76 A DocumentQuerySet containing documents of this type. 

77 

78 Examples: 

79 # Get all documents of this type 

80 documents = doc_type.documents 

81 Get documents with this document type. 

82 

83 """ 

84 return self._client.documents().all().document_type_id(self.id)