@@ -676,6 +676,88 @@ def test_appropriation_grant_on_already_granted_daily(self):
676676 [start_date + timedelta (days = x ) for x in range (25 )],
677677 )
678678
679+ def test_appropriation_grant_on_already_granted_daily_no_end_date (self ):
680+ approval_level = ApprovalLevel .objects .create (name = "egenkompetence" )
681+
682+ case = create_case (self .case_worker , self .municipality , self .district )
683+ section = create_section ()
684+ appropriation = create_appropriation (case = case , section = section )
685+ now = timezone .now ().date ()
686+ start_date = now - timedelta (days = 6 )
687+ # create an already granted activity with no end_date.
688+ activity = create_activity (
689+ case = case ,
690+ appropriation = appropriation ,
691+ activity_type = MAIN_ACTIVITY ,
692+ status = STATUS_GRANTED ,
693+ start_date = start_date ,
694+ end_date = None ,
695+ )
696+ create_payment_schedule (
697+ payment_amount = Decimal ("500.0" ),
698+ payment_frequency = PaymentSchedule .DAILY ,
699+ activity = activity ,
700+ )
701+ activity .details .main_activity_for .add (section )
702+
703+ modified_start_date = now + timedelta (days = 3 )
704+ modified_end_date = now + timedelta (days = 6 )
705+ # let the granted activity be modified by another expected activity.
706+ modifies_activity = create_activity (
707+ case = case ,
708+ appropriation = appropriation ,
709+ activity_type = MAIN_ACTIVITY ,
710+ start_date = modified_start_date ,
711+ status = STATUS_EXPECTED ,
712+ end_date = modified_end_date ,
713+ modifies = activity ,
714+ )
715+ create_payment_schedule (
716+ payment_amount = Decimal ("600.0" ),
717+ payment_frequency = PaymentSchedule .DAILY ,
718+ activity = modifies_activity ,
719+ )
720+ user = get_user_model ().objects .create (username = "Anders And" )
721+ appropriation .grant (
722+ Activity .objects .filter (pk = modifies_activity .pk ),
723+ approval_level .id ,
724+ "note til bevillingsgodkendelse" ,
725+ user ,
726+ )
727+ activity .refresh_from_db ()
728+ modifies_activity .refresh_from_db ()
729+ # the old activity with no end_date should expire the day before
730+ # the start_date of the new one.
731+ self .assertEqual (
732+ activity .end_date , modified_start_date - timedelta (days = 1 )
733+ )
734+ # expected status should be granted with the
735+ # start_date of the new activity.
736+ self .assertEqual (modifies_activity .status , STATUS_GRANTED )
737+ self .assertEqual (modifies_activity .start_date , modified_start_date )
738+ # the payments of the old activity should expire
739+ # before the new end_date.
740+ activity_payments = activity .payment_plan .payments
741+ self .assertTrue (
742+ activity_payments .order_by ("date" ).first ().date
743+ < modified_start_date
744+ )
745+ # the payments of the new activity should start after today.
746+ modifies_payments = modifies_activity .payment_plan .payments
747+
748+ self .assertTrue (
749+ modifies_payments .order_by ("date" ).first ().date
750+ >= modified_start_date
751+ )
752+ # assert payments are generated correctly.
753+ self .assertCountEqual (
754+ [
755+ x .date
756+ for x in (activity_payments .all () | modifies_payments .all ())
757+ ],
758+ [start_date + timedelta (days = x ) for x in range (13 )],
759+ )
760+
679761 def test_appropriation_grant_on_already_granted_weekly (self ):
680762 approval_level = ApprovalLevel .objects .create (name = "egenkompetence" )
681763
0 commit comments