Example #1
0
    def test_activity_details_get(self):
        reverse_url = reverse("graphql-api")
        self.client.login(username=self.username, password=self.password)

        activity_details = create_activity_details()
        json = {
            "query":
            """
            query {
                activityDetails {
                    edges {
                        node {
                            id,
                            name
                        }
                    }
                }
            }
            """
        }
        response = self.client.get(reverse_url, json)

        self.assertEqual(response.status_code, 200)
        node = response.json()["data"]["activityDetails"]["edges"][0]["node"]
        self.assertEqual(
            node["id"],
            b64encode(
                f"ActivityDetails:{activity_details.pk}".encode()).decode(),
        )
        self.assertEqual(node["name"], activity_details.name)
Example #2
0
    def test_export_prism_payments_with_exclusions_easter_2020(self):
        now = timezone.now().date()
        start_date = now
        end_date = now + timedelta(days=14)
        # Create an activity etc which is required.
        case = create_case(self.case_worker, self.municipality, self.district)
        section = create_section()
        appropriation = create_appropriation(sbsys_id="XXX-YYY",
                                             case=case,
                                             section=section)
        main_activity_details = create_activity_details()
        create_section_info(
            main_activity_details,
            section,
            main_activity_main_account_number="1234",
        )
        activity = create_activity(
            case,
            appropriation,
            start_date=start_date,
            end_date=end_date,
            activity_type=MAIN_ACTIVITY,
            status=STATUS_GRANTED,
            details=main_activity_details,
        )
        payment_schedule = create_payment_schedule(
            payment_frequency=PaymentSchedule.DAILY,
            payment_type=PaymentSchedule.RUNNING_PAYMENT,
            recipient_type=PaymentSchedule.PERSON,
            payment_method=CASH,
            payment_amount=Decimal(666),
            activity=activity,
        )
        # Generate payment exclusion dates and export.
        exclusion_dates = generate_payment_date_exclusion_dates(years=[2020])
        for exclusion_date in exclusion_dates:
            create_payment_date_exclusion(date=exclusion_date)

        export_prism_payments_for_date(date=None)

        # Assert 2020-04-07 includes weekend + easter days.
        self.assertCountEqual(
            payment_schedule.payments.filter(paid=True).values_list("date",
                                                                    flat=True),
            [
                date(2020, 4, 8),  # "Normal" day
                date(2020, 4, 9),  # Maundy Thursday - holiday
                date(2020, 4, 10),  # Good Friday - holiday
                date(2020, 4, 11),  # Saturday - weekend
                date(2020, 4,
                     12),  # Easter Sunday - holiday / Sunday - weekend
                date(2020, 4, 13),  # Easter Monday
                date(2020, 4, 14),  # Should be paid 2 "normal" days prior
            ],
        )
Example #3
0
    def test_activity_details_section_proxy_str(self):
        activity_details = create_activity_details()
        section = create_section()
        activity_details.supplementary_activity_for.add(section)

        activity_details_section_proxy = (
            ActivityDetailsSectionProxy.objects.first())
        self.assertEqual(
            str(activity_details_section_proxy),
            "000000 - Test aktivitet - ABL-105-2",
        )
Example #4
0
    def test_export_prism_payments_for_date(self):
        # Create a payment that is due today
        now = timezone.now().date()
        start_date = now - timedelta(days=1)
        end_date = now + timedelta(days=1)
        # Create an activity etc which is required.
        case = create_case(self.case_worker, self.municipality, self.district)
        section = create_section()
        appropriation = create_appropriation(sbsys_id="XXX-YYY",
                                             case=case,
                                             section=section)
        main_activity_details = create_activity_details(
            name="Betaling til andre kommuner/region for specialtandpleje",
            activity_id="010001",
        )
        create_section_info(
            main_activity_details,
            section,
            main_activity_main_account_number="1234",
        )
        activity = create_activity(
            case,
            appropriation,
            start_date=start_date,
            end_date=end_date,
            activity_type=MAIN_ACTIVITY,
            status=STATUS_GRANTED,
            details=main_activity_details,
        )
        create_payment_schedule(
            payment_frequency=PaymentSchedule.DAILY,
            payment_type=PaymentSchedule.RUNNING_PAYMENT,
            recipient_type=PaymentSchedule.PERSON,
            payment_method=CASH,
            payment_amount=Decimal(666),
            activity=activity,
        )
        # Check that there's unpaid payments for today.
        due_payments = due_payments_for_prism(start_date)
        self.assertEqual(due_payments.count(), 1)

        export_prism_payments_for_date(date=start_date)

        # Check that there's NO unpaid payments for that date.
        due_payments = due_payments_for_prism(start_date)
        self.assertEqual(due_payments.count(), 0)

        # Also process for today
        export_prism_payments_for_date()

        # Repeat the previous processing to have an example with no due
        # payments.
        export_prism_payments_for_date()
Example #5
0
    def test_export_prism_payments_with_exclusions_wednesday(self):
        now = timezone.now().date()
        start_date = now
        end_date = now + timedelta(days=14)
        # Create an activity etc which is required.
        case = create_case(self.case_worker, self.municipality, self.district)
        section = create_section()
        appropriation = create_appropriation(sbsys_id="XXX-YYY",
                                             case=case,
                                             section=section)
        main_activity_details = create_activity_details()
        create_section_info(
            main_activity_details,
            section,
            main_activity_main_account_number="1234",
        )
        activity = create_activity(
            case,
            appropriation,
            start_date=start_date,
            end_date=end_date,
            activity_type=MAIN_ACTIVITY,
            status=STATUS_GRANTED,
            details=main_activity_details,
        )
        payment_schedule = create_payment_schedule(
            payment_frequency=PaymentSchedule.DAILY,
            payment_type=PaymentSchedule.RUNNING_PAYMENT,
            recipient_type=PaymentSchedule.PERSON,
            payment_method=CASH,
            payment_amount=Decimal(666),
            activity=activity,
        )

        # Generate payment exclusion dates and export.
        exclusion_dates = generate_payment_date_exclusion_dates(years=[2020])
        for exclusion_date in exclusion_dates:
            create_payment_date_exclusion(date=exclusion_date)

        export_prism_payments_for_date(date=None)

        # Assert Wednesday only includes Thursday.
        self.assertCountEqual(
            payment_schedule.payments.filter(paid=True).values_list("date",
                                                                    flat=True),
            [date(2020, 5, 14)],  # Thursday
        )
Example #6
0
    def test_list_supplementary_activity_for(self):
        section = create_section()
        supplementary_activity_details = create_activity_details(
            name="Betaling til andre kommuner/region for specialtandpleje",
            activity_id="010001",
        )
        supplementary_activity_details.supplementary_activity_for.add(section)

        site = AdminSite()
        section_admin = SectionAdmin(Section, site)

        self.assertEqual(
            section_admin.list_supplementary_activity_for(section),
            f'<div><a href="/api/admin/core/activitydetails'
            f'/{supplementary_activity_details.id}/change/">'
            f"010001 - Betaling til andre kommuner/region for specialtandpleje"
            f"</a></div>",
        )
Example #7
0
    def test_export_prism_payments_with_exclusions_christmas_2024(self):
        now = timezone.now().date()
        start_date = now
        end_date = now + timedelta(days=14)
        # Create an activity etc which is required.
        case = create_case(self.case_worker, self.municipality, self.district)
        section = create_section()
        appropriation = create_appropriation(sbsys_id="XXX-YYY",
                                             case=case,
                                             section=section)
        main_activity_details = create_activity_details()
        create_section_info(
            main_activity_details,
            section,
            main_activity_main_account_number="1234",
        )
        activity = create_activity(
            case,
            appropriation,
            start_date=start_date,
            end_date=end_date,
            activity_type=MAIN_ACTIVITY,
            status=STATUS_GRANTED,
            details=main_activity_details,
        )
        payment_schedule = create_payment_schedule(
            payment_frequency=PaymentSchedule.DAILY,
            payment_type=PaymentSchedule.RUNNING_PAYMENT,
            recipient_type=PaymentSchedule.PERSON,
            payment_method=CASH,
            payment_amount=Decimal(666),
            activity=activity,
        )

        # Generate payment exclusion dates and export.
        exclusion_dates = generate_payment_date_exclusion_dates(
            years=[2024, 2025])
        for exclusion_date in exclusion_dates:
            create_payment_date_exclusion(date=exclusion_date)
        # Create Christmas Eve and New Years Eve as well.
        create_payment_date_exclusion(date=date(2024, 12, 24))
        create_payment_date_exclusion(date=date(2024, 12, 31))

        export_prism_payments_for_date(date=None)

        # Assert Thursday includes Friday + weekend + Monday.
        self.assertCountEqual(
            payment_schedule.payments.filter(paid=True).values_list("date",
                                                                    flat=True),
            [
                date(2024, 12, 20),  # Friday
                date(2024, 12, 21),  # Saturday
                date(2024, 12, 22),  # Sunday
                date(2024, 12, 23),  # Monday
                date(2024, 12, 24),  # Christmas Eve
                date(2024, 12, 25),  # Christmas Day
                date(2024, 12, 26),  # 2nd Christmas Day
                date(2024, 12, 27),  # Friday
                date(2024, 12, 28),  # Saturday
                date(2024, 12, 29),  # Sunday
                date(2024, 12, 30),  # Monday
                date(2024, 12, 31),  # New Years Eve
                date(2025, 1, 1),  # New Years Day
                date(2025, 1, 2),  # First day after exclusion dates.
            ],
        )
Example #8
0
    def test_format_prism_financial_record(self):
        # Create a payment that is due today
        now = timezone.now().date()
        start_date = now - timedelta(days=1)
        end_date = now + timedelta(days=1)

        # Create an activity etc which is required.

        case_cpr_number = "1234567890"
        case = create_case(
            self.case_worker,
            self.municipality,
            self.district,
            cpr_number=case_cpr_number,
        )
        section = create_section()
        appropriation = create_appropriation(sbsys_id="XXX-YYY",
                                             case=case,
                                             section=section)
        main_activity_details = create_activity_details(
            name="Betaling til andre kommuner/region for specialtandpleje",
            activity_id="010001",
        )
        create_section_info(
            details=main_activity_details,
            section=section,
            main_activity_main_account_number="12345",
        )
        activity = create_activity(
            case,
            appropriation,
            start_date=start_date,
            end_date=end_date,
            activity_type=MAIN_ACTIVITY,
            status=STATUS_GRANTED,
            details=main_activity_details,
        )
        payment_schedule = create_payment_schedule(
            payment_frequency=PaymentSchedule.DAILY,
            payment_type=PaymentSchedule.RUNNING_PAYMENT,
            recipient_type=PaymentSchedule.PERSON,
            payment_method=CASH,
            payment_amount=Decimal(666),
            activity=activity,
        )
        # This will generate three payments on the payment plan, and one
        # of them will be for today.
        due_payments = due_payments_for_prism(now)
        records = generate_records_for_prism(due_payments)
        self.assertEqual(len(records), 2)
        due_payments = due_payments_for_prism(end_date)
        records = generate_records_for_prism(due_payments)
        self.assertEqual(len(records), 2)
        finance_reference = records[0].split("&117")[1][:20]
        payment_reference = records[1].split("&16")[1][:20]
        # These references is what links the two records.
        # This is a simple sanity check.
        self.assertEqual(payment_reference, finance_reference)
        # Check that the CPR number on G69 is the one from the case.
        finance_cpr = records[0].split("&133")[1][:10]
        payment_cpr = records[1].split("&11")[1][:10]
        self.assertEqual(finance_cpr, case_cpr_number)
        self.assertEqual(payment_cpr, payment_schedule.recipient_id)
        self.assertNotEqual(finance_cpr, payment_cpr)