Specify clin sorting in TO <> CLIN relationship
This also removes the sorted_clins property on the task_order model
This commit is contained in:
parent
612e254104
commit
d46ed2b5b4
@ -202,7 +202,7 @@ class Portfolio(
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
initial_task_order: TaskOrder = self.task_orders[0]
|
initial_task_order: TaskOrder = self.task_orders[0]
|
||||||
initial_clin = initial_task_order.sorted_clins[0]
|
initial_clin = initial_task_order.clins[0]
|
||||||
portfolio_data.update(
|
portfolio_data.update(
|
||||||
{
|
{
|
||||||
"initial_clin_amount": initial_clin.obligated_amount,
|
"initial_clin_amount": initial_clin.obligated_amount,
|
||||||
|
@ -3,12 +3,13 @@ from enum import Enum
|
|||||||
from sqlalchemy import Column, DateTime, ForeignKey, String
|
from sqlalchemy import Column, DateTime, ForeignKey, String
|
||||||
from sqlalchemy.ext.hybrid import hybrid_property
|
from sqlalchemy.ext.hybrid import hybrid_property
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
from atst.models.clin import CLIN
|
||||||
from atst.models.base import Base
|
from atst.models.base import Base
|
||||||
import atst.models.types as types
|
import atst.models.types as types
|
||||||
import atst.models.mixins as mixins
|
import atst.models.mixins as mixins
|
||||||
from atst.models.attachment import Attachment
|
from atst.models.attachment import Attachment
|
||||||
from pendulum import today
|
from pendulum import today
|
||||||
|
from sqlalchemy import func
|
||||||
|
|
||||||
|
|
||||||
class Status(Enum):
|
class Status(Enum):
|
||||||
@ -41,15 +42,13 @@ class TaskOrder(Base, mixins.TimestampsMixin):
|
|||||||
number = Column(String, unique=True,) # Task Order Number
|
number = Column(String, unique=True,) # Task Order Number
|
||||||
signer_dod_id = Column(String)
|
signer_dod_id = Column(String)
|
||||||
signed_at = Column(DateTime)
|
signed_at = Column(DateTime)
|
||||||
|
|
||||||
clins = relationship(
|
clins = relationship(
|
||||||
"CLIN", back_populates="task_order", cascade="all, delete-orphan"
|
"CLIN",
|
||||||
|
back_populates="task_order",
|
||||||
|
cascade="all, delete-orphan",
|
||||||
|
order_by=lambda: [func.substr(CLIN.number, 2), func.substr(CLIN.number, 1, 2)],
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def sorted_clins(self):
|
|
||||||
return sorted(self.clins, key=lambda clin: (clin.number[1:], clin.number[0]))
|
|
||||||
|
|
||||||
@hybrid_property
|
@hybrid_property
|
||||||
def pdf(self):
|
def pdf(self):
|
||||||
return self._pdf
|
return self._pdf
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for clin in task_order.sorted_clins %}
|
{% for clin in task_order.clins %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ clin.number }}</td>
|
<td>{{ clin.number }}</td>
|
||||||
<td>{{ clin.type }}</td>
|
<td>{{ clin.type }}</td>
|
||||||
|
@ -62,7 +62,7 @@ def test_clin_sorting():
|
|||||||
CLINFactory.create(number="2001"),
|
CLINFactory.create(number="2001"),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
assert [clin.number for clin in task_order.sorted_clins] == [
|
assert [clin.number for clin in task_order.clins] == [
|
||||||
"0001",
|
"0001",
|
||||||
"1001",
|
"1001",
|
||||||
"2001",
|
"2001",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user