add a sorted_clins property for clin sorting logic

CLINS have a special ordering:
 - First, they are sorted by the last three digits
 - Then, they are sorted by the first digit

Trying to add CLIN sorting logic to the relationship field in the task
order proved to be more challenging than expected. So, a separate
property was defined in order to access the clins in sorted order.
This commit is contained in:
graham-dds
2019-09-03 11:10:12 -04:00
parent e2bd6bd823
commit 41bbbe8a39
4 changed files with 25 additions and 2 deletions

View File

@@ -52,6 +52,25 @@ def test_task_order_clins_are_completed():
assert not TaskOrderFactory.create(clins=[]).clins_are_completed
def test_clin_sorting():
task_order = TaskOrderFactory.create(
clins=[
CLINFactory.create(number="0002"),
CLINFactory.create(number="0001"),
CLINFactory.create(number="1001"),
CLINFactory.create(number="1002"),
CLINFactory.create(number="2001"),
]
)
assert [clin.number for clin in task_order.sorted_clins] == [
"0001",
"1001",
"2001",
"0002",
"1002",
]
class TestTaskOrderStatus:
@patch("atst.models.TaskOrder.is_completed", new_callable=PropertyMock)
@patch("atst.models.TaskOrder.is_signed", new_callable=PropertyMock)