@@ -570,11 +570,19 @@ def _filter_collective_offers_by_statuses(query: BaseQuery, statuses: list[str]
570
570
)
571
571
)
572
572
573
+ if DisplayedStatus .INACTIVE .value in statuses and not FeatureToggle .ENABLE_COLLECTIVE_NEW_STATUSES .is_active ():
574
+ on_collective_offer_filters .append (
575
+ and_ (
576
+ educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
577
+ educational_models .CollectiveOffer .isActive == False ,
578
+ )
579
+ )
580
+
573
581
if DisplayedStatus .ACTIVE .value in statuses :
574
582
on_booking_status_filter .append (
575
583
and_ (
576
- educational_models .CollectiveOffer .isArchived == False ,
577
584
educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
585
+ educational_models .CollectiveOffer .isActive == True ,
578
586
offer_id_with_booking_status_subquery .c .status == None ,
579
587
educational_models .CollectiveOffer .hasBookingLimitDatetimesPassed == False ,
580
588
)
@@ -583,8 +591,8 @@ def _filter_collective_offers_by_statuses(query: BaseQuery, statuses: list[str]
583
591
# With the FF activated, those offers will be CANCELLED
584
592
on_booking_status_filter .append (
585
593
and_ (
586
- educational_models .CollectiveOffer .isArchived == False ,
587
594
educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
595
+ educational_models .CollectiveOffer .isActive == True ,
588
596
offer_id_with_booking_status_subquery .c .status
589
597
== educational_models .CollectiveBookingStatus .CANCELLED ,
590
598
educational_models .CollectiveOffer .hasBookingLimitDatetimesPassed == False ,
@@ -594,8 +602,8 @@ def _filter_collective_offers_by_statuses(query: BaseQuery, statuses: list[str]
594
602
if DisplayedStatus .PREBOOKED .value in statuses :
595
603
on_booking_status_filter .append (
596
604
and_ (
597
- educational_models .CollectiveOffer .isArchived == False ,
598
605
educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
606
+ educational_models .CollectiveOffer .isActive == True ,
599
607
offer_id_with_booking_status_subquery .c .status == educational_models .CollectiveBookingStatus .PENDING ,
600
608
educational_models .CollectiveOffer .hasBookingLimitDatetimesPassed == False ,
601
609
)
@@ -604,8 +612,8 @@ def _filter_collective_offers_by_statuses(query: BaseQuery, statuses: list[str]
604
612
if DisplayedStatus .BOOKED .value in statuses :
605
613
on_booking_status_filter .append (
606
614
and_ (
607
- educational_models .CollectiveOffer .isArchived == False ,
608
615
educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
616
+ educational_models .CollectiveOffer .isActive == True ,
609
617
offer_id_with_booking_status_subquery .c .status == educational_models .CollectiveBookingStatus .CONFIRMED ,
610
618
educational_models .CollectiveOffer .hasEndDatetimePassed == False ,
611
619
)
@@ -614,24 +622,21 @@ def _filter_collective_offers_by_statuses(query: BaseQuery, statuses: list[str]
614
622
if DisplayedStatus .ENDED .value in statuses :
615
623
on_booking_status_filter .append (
616
624
and_ (
617
- educational_models .CollectiveOffer .isArchived == False ,
618
625
educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
619
- offer_id_with_booking_status_subquery .c .status == educational_models .CollectiveBookingStatus .CONFIRMED ,
626
+ educational_models .CollectiveOffer .isActive == True ,
627
+ or_ (
628
+ offer_id_with_booking_status_subquery .c .status == educational_models .CollectiveBookingStatus .USED ,
629
+ offer_id_with_booking_status_subquery .c .status
630
+ == educational_models .CollectiveBookingStatus .CONFIRMED ,
631
+ ),
620
632
educational_models .CollectiveOffer .hasEndDatetimePassed == True ,
621
633
)
622
634
)
623
- on_booking_status_filter .append (
624
- and_ (
625
- educational_models .CollectiveOffer .isArchived == False ,
626
- educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
627
- offer_id_with_booking_status_subquery .c .status == educational_models .CollectiveBookingStatus .USED ,
628
- )
629
- )
630
635
if not FeatureToggle .ENABLE_COLLECTIVE_NEW_STATUSES .is_active ():
631
636
on_booking_status_filter .append (
632
637
and_ (
633
- educational_models .CollectiveOffer .isArchived == False ,
634
638
educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
639
+ educational_models .CollectiveOffer .isActive == True ,
635
640
offer_id_with_booking_status_subquery .c .status
636
641
== educational_models .CollectiveBookingStatus .REIMBURSED ,
637
642
)
@@ -640,93 +645,89 @@ def _filter_collective_offers_by_statuses(query: BaseQuery, statuses: list[str]
640
645
if DisplayedStatus .REIMBURSED .value in statuses and FeatureToggle .ENABLE_COLLECTIVE_NEW_STATUSES .is_active ():
641
646
on_booking_status_filter .append (
642
647
and_ (
643
- educational_models .CollectiveOffer .isArchived == False ,
644
648
educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
649
+ educational_models .CollectiveOffer .isActive == True ,
645
650
offer_id_with_booking_status_subquery .c .status == educational_models .CollectiveBookingStatus .REIMBURSED ,
646
651
)
647
652
)
648
653
649
654
if DisplayedStatus .EXPIRED .value in statuses :
650
- on_booking_status_filter .append (
651
- and_ (
652
- educational_models .CollectiveOffer .isArchived == False ,
653
- educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
654
- educational_models .CollectiveOffer .hasBookingLimitDatetimesPassed == True ,
655
- or_ (
656
- offer_id_with_booking_status_subquery .c .status
657
- == educational_models .CollectiveBookingStatus .PENDING ,
658
- offer_id_with_booking_status_subquery .c .status == None ,
659
- ),
660
- educational_models .CollectiveOffer .hasStartDatetimePassed == False ,
661
- ),
662
- )
663
-
664
655
if FeatureToggle .ENABLE_COLLECTIVE_NEW_STATUSES .is_active ():
665
656
on_booking_status_filter .append (
666
657
and_ (
667
- educational_models .CollectiveOffer .isArchived == False ,
668
658
educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
669
- offer_id_with_booking_status_subquery .c .status
670
- == educational_models .CollectiveBookingStatus .CANCELLED ,
671
- offer_id_with_booking_status_subquery .c .cancellationReason
672
- == educational_models .CollectiveBookingCancellationReasons .EXPIRED ,
659
+ educational_models .CollectiveOffer .isActive == True ,
660
+ educational_models .CollectiveOffer .hasBookingLimitDatetimesPassed == True ,
673
661
educational_models .CollectiveOffer .hasStartDatetimePassed == False ,
662
+ or_ (
663
+ offer_id_with_booking_status_subquery .c .status
664
+ == educational_models .CollectiveBookingStatus .PENDING ,
665
+ offer_id_with_booking_status_subquery .c .status == None ,
666
+ ),
674
667
)
675
668
)
676
- else :
677
669
on_booking_status_filter .append (
678
670
and_ (
679
- educational_models .CollectiveOffer .isArchived == False ,
680
671
educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
672
+ educational_models .CollectiveOffer .isActive == True ,
673
+ educational_models .CollectiveOffer .hasBookingLimitDatetimesPassed == True ,
674
+ educational_models .CollectiveOffer .hasStartDatetimePassed == False ,
681
675
offer_id_with_booking_status_subquery .c .status
682
676
== educational_models .CollectiveBookingStatus .CANCELLED ,
683
- educational_models .CollectiveOffer .hasBookingLimitDatetimesPassed == True ,
684
- ),
677
+ offer_id_with_booking_status_subquery .c .cancellationReason
678
+ == educational_models .CollectiveBookingCancellationReasons .EXPIRED ,
679
+ )
685
680
)
681
+ else :
686
682
on_booking_status_filter .append (
687
683
and_ (
688
- educational_models .CollectiveOffer .isArchived == False ,
689
684
educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
690
- offer_id_with_booking_status_subquery .c .status == None ,
691
- educational_models .CollectiveOffer .hasStartDatetimePassed == True ,
685
+ educational_models .CollectiveOffer .isActive == True ,
686
+ educational_models .CollectiveOffer .hasBookingLimitDatetimesPassed == True ,
687
+ or_ (
688
+ offer_id_with_booking_status_subquery .c .status
689
+ == educational_models .CollectiveBookingStatus .CANCELLED ,
690
+ offer_id_with_booking_status_subquery .c .status
691
+ == educational_models .CollectiveBookingStatus .PENDING ,
692
+ offer_id_with_booking_status_subquery .c .status == None ,
693
+ ),
692
694
),
693
695
)
694
696
695
697
if DisplayedStatus .CANCELLED .value in statuses and FeatureToggle .ENABLE_COLLECTIVE_NEW_STATUSES .is_active ():
698
+ # Cancelled due to expired booking
696
699
on_booking_status_filter .append (
697
700
and_ (
698
- educational_models .CollectiveOffer .isArchived == False ,
699
701
educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
702
+ educational_models .CollectiveOffer .isActive == True ,
700
703
offer_id_with_booking_status_subquery .c .status == educational_models .CollectiveBookingStatus .CANCELLED ,
701
704
offer_id_with_booking_status_subquery .c .cancellationReason
702
705
== educational_models .CollectiveBookingCancellationReasons .EXPIRED ,
703
706
educational_models .CollectiveOffer .hasStartDatetimePassed == True ,
704
707
)
705
708
)
706
709
710
+ # Cancelled by admin / CA or on ADAGE
707
711
on_booking_status_filter .append (
708
712
and_ (
709
- educational_models .CollectiveOffer .isArchived == False ,
710
713
educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
714
+ educational_models .CollectiveOffer .isActive == True ,
711
715
offer_id_with_booking_status_subquery .c .status == educational_models .CollectiveBookingStatus .CANCELLED ,
712
716
offer_id_with_booking_status_subquery .c .cancellationReason
713
717
!= educational_models .CollectiveBookingCancellationReasons .EXPIRED ,
714
718
),
715
719
)
716
720
721
+ # Cancelled due to no booking when the event has started
717
722
on_booking_status_filter .append (
718
723
and_ (
719
- educational_models .CollectiveOffer .isArchived == False ,
720
724
educational_models .CollectiveOffer .validation == offer_mixin .OfferValidationStatus .APPROVED ,
725
+ educational_models .CollectiveOffer .isActive == True ,
721
726
offer_id_with_booking_status_subquery .c .status == None ,
722
727
educational_models .CollectiveOffer .hasStartDatetimePassed == True ,
723
728
),
724
729
)
725
730
726
- if DisplayedStatus .INACTIVE .value in statuses :
727
- # This case is irrelevant for collective offers
728
- on_collective_offer_filters .append (sa .false ())
729
-
730
731
# Add filters on `CollectiveBooking.Status`
731
732
if on_booking_status_filter :
732
733
substmt = query_with_booking .filter (or_ (* on_booking_status_filter )).subquery ()
0 commit comments