From 2298c5135e3d5585b8ff09a04908bcb4132d86dc Mon Sep 17 00:00:00 2001 From: Patrick Smith Date: Mon, 21 Jan 2019 15:55:00 -0500 Subject: [PATCH] Add csp_estimate property to task order model --- atst/models/task_order.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/atst/models/task_order.py b/atst/models/task_order.py index 04260b7b..61bd4b60 100644 --- a/atst/models/task_order.py +++ b/atst/models/task_order.py @@ -2,10 +2,11 @@ from enum import Enum import pendulum from sqlalchemy import Column, Numeric, String, ForeignKey, Date, Integer +from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.types import ARRAY from sqlalchemy.orm import relationship -from atst.models import Base, types, mixins +from atst.models import Attachment, Base, types, mixins class Status(Enum): @@ -49,7 +50,7 @@ class TaskOrder(Base, mixins.TimestampsMixin): end_date = Column(Date) performance_length = Column(Integer) attachment_id = Column(ForeignKey("attachments.id")) - pdf = relationship("Attachment") + _csp_estimate = relationship("Attachment") clin_01 = Column(Numeric(scale=2)) clin_02 = Column(Numeric(scale=2)) clin_03 = Column(Numeric(scale=2)) @@ -72,6 +73,19 @@ class TaskOrder(Base, mixins.TimestampsMixin): number = Column(String, unique=True) # Task Order Number loa = Column(ARRAY(String)) # Line of Accounting (LOA) + @hybrid_property + def csp_estimate(self): + return self._csp_estimate + + @csp_estimate.setter + def csp_estimate(self, new_csp_estimate): + if isinstance(new_csp_estimate, Attachment): + self._csp_estimate = new_csp_estimate + else: + self._csp_estimate = Attachment.attach( + new_csp_estimate, "task_order", self.id + ) + @property def is_submitted(self): return self.number is not None