Coverage for src/paperap/models/document_type/model.py: 94%

18 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-11 21:37 -0400

1""" 

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

3 

4 METADATA: 

5 

6 File: document_type.py 

7 Project: paperap 

8 Created: 2025-03-04 

9 Version: 0.0.5 

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, Optional 

26 

27from paperap.models.abstract.model import StandardModel 

28from paperap.models.document_type.queryset import DocumentTypeQuerySet 

29from paperap.models.mixins.models import MatcherMixin 

30 

31if TYPE_CHECKING: 

32 from paperap.models.document import Document, DocumentQuerySet 

33 

34 

35class DocumentType(StandardModel, MatcherMixin): 

36 """ 

37 Represents a document type in Paperless-NgX. 

38 

39 Attributes: 

40 name: The name of the document type. 

41 slug: A unique identifier for the document type. 

42 match: The pattern used for matching documents. 

43 matching_algorithm: The algorithm used for matching. 

44 is_insensitive: Whether the matching is case insensitive. 

45 document_count: The number of documents of this type. 

46 owner: The owner of the document type. 

47 user_can_change: Whether the user can change the document type. 

48 

49 Returns: 

50 A new instance of DocumentType. 

51 

52 Examples: 

53 # Create a new DocumentType instance 

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

55 

56 """ 

57 

58 name: str 

59 slug: str | None = None 

60 document_count: int = 0 

61 owner: int | None = None 

62 user_can_change: bool | None = None 

63 

64 class Meta(StandardModel.Meta): 

65 # Fields that should not be modified 

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

67 queryset = DocumentTypeQuerySet 

68 

69 @property 

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

71 """ 

72 Get documents with this document type. 

73 

74 Returns: 

75 A DocumentQuerySet containing documents of this type. 

76 

77 Examples: 

78 # Get all documents of this type 

79 documents = doc_type.documents 

80 Get documents with this document type. 

81 

82 """ 

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