Coverage for middle_layer/closeout/domain_layer/entities/disposition_letter.py: 95.83%

24 statements  

« prev     ^ index     » next       coverage.py v7.10.5, created at 2026-03-09 06:13 +0000

1# Copyright 2024 Associated Universities, Inc. 

2# 

3# This file is part of Telescope Time Allocation Tools (TTAT). 

4# 

5# TTAT is free software: you can redistribute it and/or modify 

6# it under the terms of the GNU General Public License as published by 

7# the Free Software Foundation, either version 3 of the License, or 

8# any later version. 

9# 

10# TTAT is distributed in the hope that it will be useful, 

11# but WITHOUT ANY WARRANTY; without even the implied warranty of 

12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

13# GNU General Public License for more details. 

14# 

15# You should have received a copy of the GNU General Public License 

16# along with TTAT. If not, see <https://www.gnu.org/licenses/>. 

17# 

18from datetime import date, datetime, timezone 

19 

20from sqlalchemy import ForeignKey 

21from sqlalchemy.orm import Mapped, mapped_column, relationship 

22 

23from common.domain_layer import JSON_OBJECT 

24from common.domain_layer.entities.base import Base 

25from propose.domain_layer.entities.proposal import Proposal 

26 

27 

28class DispositionLetter(Base): 

29 __tablename__ = "disposition_letters" 

30 """ 

31 Represents a disposition letter as a string, along with creation, modified, and sent dates. 

32 For now, one letter per proposal. 

33 """ 

34 disposition_letter_id: Mapped[int] = mapped_column(primary_key=True) 

35 proposal_id: Mapped[int] = mapped_column(ForeignKey("proposals.proposal_id", ondelete="CASCADE")) 

36 proposal: Mapped[Proposal] = relationship( 

37 Proposal, 

38 back_populates="disposition_letter", 

39 uselist=False, 

40 ) 

41 letter_text: Mapped[str] = mapped_column(nullable=False) 

42 created_date: Mapped[date] = mapped_column(default=datetime.now(timezone.utc)) 

43 modified_date: Mapped[date] 

44 sent_date: Mapped[date] 

45 

46 def __init__( 

47 self, 

48 letter_text: str, 

49 proposal: Proposal, # Removed default None 

50 created_date: date = None, 

51 modified_date: date = None, 

52 sent_date: date = None, 

53 ): 

54 """ 

55 Initializes a new DispositionLetter instance. 

56 

57 :param letter_text: The text content of the disposition letter. 

58 :param proposal: The associated Proposal object. 

59 :param created_date: The creation date (optional, defaults to now if None). 

60 :param modified_date: The modification date (optional). 

61 :param sent_date: The date the letter was sent (optional). 

62 """ 

63 super().__init__( 

64 letter_text=letter_text, 

65 proposal=proposal, 

66 created_date=created_date if created_date else datetime.now(timezone.utc), 

67 modified_date=modified_date, 

68 sent_date=sent_date, 

69 ) 

70 

71 @property 

72 def has_been_sent(self): 

73 return self.sent_date is not None 

74 

75 @property 

76 def has_been_modified(self): 

77 return self.modified_date is not None