Coverage for middle_layer/allocate/domain_layer/entities/proposal_disposition_group.py: 92.31%

26 statements  

« prev     ^ index     » next       coverage.py v7.10.5, created at 2026-04-13 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# 

18 

19import typing 

20from datetime import datetime, timezone 

21 

22from sqlalchemy import ForeignKey 

23from sqlalchemy.orm import Mapped, mapped_column, relationship 

24 

25from common.domain_layer import JSON_OBJECT 

26from common.domain_layer.entities.base import Base 

27from solicit.domain_layer.entities.solicitation import Solicitation 

28 

29if typing.TYPE_CHECKING: 

30 from allocate.domain_layer.entities.allocation_version import AllocationVersion 

31 from allocate.domain_layer.entities.proposal_disposition import ProposalDisposition 

32 

33 

34class ProposalDispositionGroup(Base): 

35 """ 

36 A grouping of ProposalDispositions to be processed together. 

37 """ 

38 

39 __tablename__ = "proposal_disposition_groups" 

40 proposal_disposition_group_id: Mapped[int] = mapped_column(primary_key=True) 

41 solicitation_id: Mapped[int] = mapped_column(ForeignKey("solicitations.solicitation_id", ondelete="CASCADE")) 

42 solicitation: Mapped[Solicitation] = relationship(Solicitation, back_populates="proposal_disposition_groups") 

43 name: Mapped[str] 

44 created_at: Mapped[datetime] = mapped_column(default=datetime.now(timezone.utc)) 

45 

46 proposal_dispositions: Mapped[list["ProposalDisposition"]] = relationship( 

47 "ProposalDisposition", 

48 back_populates="proposal_disposition_group", 

49 cascade="all, delete-orphan", 

50 passive_deletes=True, 

51 order_by="ProposalDisposition.proposal_id", 

52 ) 

53 allocation_versions: Mapped[list["AllocationVersion"]] = relationship( 

54 "AllocationVersion", back_populates="proposal_disposition_group", cascade="all, delete-orphan" 

55 ) 

56 time_allocation_review_instructions: Mapped[str] = mapped_column(nullable=False, server_default="") 

57 

58 def __init__( 

59 self, 

60 solicitation: Solicitation, 

61 name: str, 

62 proposal_dispositions: list["ProposalDisposition"], 

63 time_allocation_review_instructions: str = "", 

64 ): 

65 solicitation.proposal_disposition_groups.append(self) 

66 self.solicitation = solicitation 

67 self.solicitation_id = solicitation.solicitation_id 

68 self.name = name 

69 self.proposal_dispositions = proposal_dispositions 

70 self.time_allocation_review_instructions = time_allocation_review_instructions