@@ -391,60 +391,77 @@ def get_total_usage(
391
391
@db_select
392
392
def get_allocations (sub_id : UUID ) -> Select :
393
393
"""Get all allocations for a subscription."""
394
- return select (
395
- [
396
- allocations .c .ticket ,
397
- allocations .c .amount ,
398
- allocations .c .currency ,
399
- allocations .c .time_created ,
400
- ]
401
- ).where (allocations .c .subscription_id == sub_id )
394
+ return (
395
+ select (
396
+ [
397
+ allocations .c .ticket ,
398
+ allocations .c .amount ,
399
+ allocations .c .currency ,
400
+ allocations .c .time_created ,
401
+ ]
402
+ )
403
+ .where (allocations .c .subscription_id == sub_id )
404
+ .order_by (desc (allocations .c .time_created ))
405
+ )
402
406
403
407
404
408
@db_select
405
409
def get_approvals (sub_id : UUID ) -> Select :
406
410
"""Get all approvals for a subscription."""
407
- return select (
408
- [
409
- approvals .c .ticket ,
410
- approvals .c .amount ,
411
- approvals .c .currency ,
412
- approvals .c .date_from ,
413
- approvals .c .date_to ,
414
- approvals .c .time_created ,
415
- ]
416
- ).where (approvals .c .subscription_id == sub_id )
411
+ return (
412
+ select (
413
+ [
414
+ approvals .c .ticket ,
415
+ approvals .c .amount ,
416
+ approvals .c .currency ,
417
+ approvals .c .date_from ,
418
+ approvals .c .date_to ,
419
+ approvals .c .time_created ,
420
+ ]
421
+ )
422
+ .where (approvals .c .subscription_id == sub_id )
423
+ .order_by (desc (approvals .c .date_to ))
424
+ )
417
425
418
426
419
427
@db_select
420
428
def get_finance (sub_id : UUID ) -> Select :
421
429
"""Get all finance items."""
422
- return select (
423
- [
424
- finance .c .ticket ,
425
- finance .c .amount ,
426
- finance .c .priority ,
427
- finance .c .finance_code ,
428
- finance .c .date_from ,
429
- finance .c .date_to ,
430
- finance .c .time_created ,
431
- ]
432
- ).where (finance .c .subscription_id == sub_id )
430
+ return (
431
+ select (
432
+ [
433
+ finance .c .ticket ,
434
+ finance .c .amount ,
435
+ finance .c .priority ,
436
+ finance .c .finance_code ,
437
+ finance .c .date_from ,
438
+ finance .c .date_to ,
439
+ finance .c .time_created ,
440
+ ]
441
+ )
442
+ .where (finance .c .subscription_id == sub_id )
443
+ .order_by (desc (finance .c .date_to ))
444
+ )
433
445
434
446
435
447
@db_select
436
448
def get_costrecovery (sub_id : UUID ) -> Select :
437
- """Get all cost recovery items for a subscription."""
438
- return select (
439
- [
440
- cost_recovery .c .subscription_id ,
441
- cost_recovery .c .finance_id ,
442
- cost_recovery .c .month ,
443
- cost_recovery .c .finance_code ,
444
- cost_recovery .c .amount ,
445
- cost_recovery .c .date_recovered ,
446
- ]
447
- ).where (cost_recovery .c .subscription_id == sub_id )
449
+ """Get all cost recovery items for a subscription in asc date order."""
450
+ # order by month asc
451
+ return (
452
+ select (
453
+ [
454
+ cost_recovery .c .subscription_id ,
455
+ cost_recovery .c .finance_id ,
456
+ cost_recovery .c .month ,
457
+ cost_recovery .c .finance_code ,
458
+ cost_recovery .c .amount ,
459
+ cost_recovery .c .date_recovered ,
460
+ ]
461
+ )
462
+ .where (cost_recovery .c .subscription_id == sub_id )
463
+ .order_by (desc (cost_recovery .c .month ))
464
+ )
448
465
449
466
450
467
@db_select
0 commit comments