Coverage for src/paperap/models/correspondent/model.py: 95%

1"""

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

3

4 METADATA:

5

6 File: correspondent.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

22 from __future__ import annotations

23

24 from datetime import datetime

25 from typing import TYPE_CHECKING, Any, Optional

26

27 from pydantic import Field

28

29 from paperap.models.abstract.model import StandardModel

30 from paperap.models.correspondent.queryset import CorrespondentQuerySet

31 from paperap.models.mixins.models import MatcherMixin

32

33 if TYPE_CHECKING:

34 from paperap.models.document import Document, DocumentQuerySet

35

36

37 class Correspondent(StandardModel, MatcherMixin):

38 """

39 Represents a correspondent in Paperless-NgX.

40 """

41

42 slug: str | None = None

43 name: str | None = None

44 document_count: int = 0

45 owner: int | None = None

46 user_can_change: bool | None = None

47

48 class Meta(StandardModel.Meta):

49 # Fields that should not be modified

50 read_only_fields = {

51 "slug",

52 "document_count",

53 }

54 queryset = CorrespondentQuerySet

55

56 @property

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

58 """

59 Get documents for this correspondent.

60 """

61 return self._client.documents().all().correspondent_id(self.id)