Example #1
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 #2
0
    def test_generate_payments_report_list_historical_case_missing(self):
        now = timezone.now().date()
        start_date = now
        end_date = now + timedelta(days=5)
        case = create_case(self.case_worker, self.municipality, self.district)
        section = create_section()
        appropriation = create_appropriation(sbsys_id="XXX-YYY",
                                             case=case,
                                             section=section)
        granted_activity = create_activity(
            case,
            appropriation,
            start_date=start_date,
            end_date=end_date,
            activity_type=MAIN_ACTIVITY,
            status=STATUS_GRANTED,
        )
        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=granted_activity,
        )
        self.assertEqual(case.effort_step.number, 1)
        self.assertEqual(case.scaling_step, 1)

        # Create a second case history entry.
        effort_step = create_effort_step(name="Trin 2", number=2)
        case.effort_step = effort_step
        case.scaling_step = 2
        case.save()

        # Pay payments in the past.
        past_date = date(2020, 1, 1)
        payment_schedule.payments.update(paid=True)
        payment_schedule.payments.update(paid_date=past_date)

        # Exception is not raised:
        # core.models.Case.DoesNotExist: Case had not yet been created.
        report = generate_payments_report_list_v0(
            payment_schedule.payments.all())

        # Payments should use the earliest historical version of the Case.
        self.assertTrue(
            all([
                payment_dict["effort_step"] ==
                "Trin 1: Tidlig indsats i almenområdet"
                for payment_dict in report
            ]))
        self.assertTrue(
            all([
                payment_dict["scaling_step"] == "1" for payment_dict in report
            ]))
Example #3
0
    def test_generate_payments_report_list_use_historical_case(self):
        # Pay payments on 2020-01-01.
        with freeze_time("2020-01-01"):
            now = timezone.now().date()
            start_date = now
            end_date = now + timedelta(days=5)
            case = create_case(self.case_worker, self.municipality,
                               self.district)
            section = create_section()
            appropriation = create_appropriation(sbsys_id="XXX-YYY",
                                                 case=case,
                                                 section=section)
            granted_activity = create_activity(
                case,
                appropriation,
                start_date=start_date,
                end_date=end_date,
                activity_type=MAIN_ACTIVITY,
                status=STATUS_GRANTED,
            )
            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=granted_activity,
            )
            payment_schedule.payments.update(paid=True)
            payment_schedule.payments.update(paid_date=now)

        self.assertEqual(case.effort_step.number, 1)
        self.assertEqual(case.scaling_step, 1)

        # A day has passed.
        with freeze_time("2020-01-02"):
            effort_step = create_effort_step(name="Trin 2", number=2)
            case.effort_step = effort_step
            case.scaling_step = 2
            case.save()

            report = generate_payments_report_list_v0(
                payment_schedule.payments.all())

            self.assertTrue(
                all([
                    payment_dict["effort_step"] ==
                    "Trin 1: Tidlig indsats i almenområdet"
                    for payment_dict in report
                ]))
            self.assertTrue(
                all([
                    payment_dict["scaling_step"] == "1"
                    for payment_dict in report
                ]))
Example #4
0
    def test_generate_payments_report_list_expected_payments(self):
        now = timezone.now().date()
        # Create a granted activity.
        start_date = now
        end_date = now + timedelta(days=5)

        case = create_case(self.case_worker, self.municipality, self.district)
        section = create_section()
        appropriation = create_appropriation(sbsys_id="XXX-YYY",
                                             case=case,
                                             section=section)
        granted_activity = create_activity(
            case,
            appropriation,
            start_date=start_date,
            end_date=end_date,
            activity_type=MAIN_ACTIVITY,
            status=STATUS_GRANTED,
        )
        create_payment_schedule(
            payment_frequency=PaymentSchedule.DAILY,
            payment_type=PaymentSchedule.RUNNING_PAYMENT,
            recipient_type=PaymentSchedule.PERSON,
            payment_method=CASH,
            payment_amount=Decimal(666),
            activity=granted_activity,
        )
        # Create an expected activity.
        start_date = now + timedelta(days=4)
        end_date = now + timedelta(days=8)

        expected_activity = create_activity(
            case,
            appropriation,
            start_date=start_date,
            end_date=end_date,
            activity_type=MAIN_ACTIVITY,
            status=STATUS_EXPECTED,
            modifies=granted_activity,
        )
        create_payment_schedule(
            payment_frequency=PaymentSchedule.DAILY,
            payment_type=PaymentSchedule.RUNNING_PAYMENT,
            recipient_type=PaymentSchedule.PERSON,
            payment_method=CASH,
            payment_amount=Decimal(800),
            activity=expected_activity,
        )
        payments = Payment.objects.expected_payments_for_report_list()
        report_list = generate_payments_report_list_v0(payments)

        self.assertEqual(len(report_list), 9)
        self.assertEqual(sum([x["amount"] for x in report_list]),
                         Decimal("6664"))
Example #5
0
    def test_account_number(self):
        section = create_section()
        case = create_case(self.case_worker, self.municipality, self.district)
        appropriation = create_appropriation(section=section, case=case)
        activity = create_activity(case=case, appropriation=appropriation)

        site = AdminSite()
        activity_admin = ActivityAdmin(Activity, site)
        self.assertEqual(
            activity_admin.account_number(activity),
            activity.account_number,
        )
Example #6
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 #7
0
class SendAppropriationTestCase(TestCase, BasicTestMixin):
    @classmethod
    def setUpTestData(cls):
        cls.basic_setup()

    @mock.patch("core.utils.HTML")
    @mock.patch("core.utils.EmailMessage")
    @mock.patch("core.utils.get_template")
    def test_send_appropriation(self, get_template_mock, html_mock,
                                message_mock):
        case = create_case(self.case_worker, self.municipality, self.district)
        section = create_section()
        appropriation = create_appropriation(sbsys_id="XXX-YYY",
                                             case=case,
                                             section=section)

        now = timezone.now().date()
        activity = create_activity(
            case,
            appropriation,
            start_date=now - timedelta(days=5),
            end_date=now + timedelta(days=5),
            activity_type=MAIN_ACTIVITY,
            status=STATUS_GRANTED,
        )
        section.main_activities.add(activity.details)

        one_time_activity = create_activity(
            case,
            appropriation,
            start_date=now - timedelta(days=5),
            end_date=now - timedelta(days=5),
            activity_type=SUPPL_ACTIVITY,
            status=STATUS_GRANTED,
        )
        create_payment_schedule(
            payment_type=PaymentSchedule.ONE_TIME_PAYMENT,
            activity=one_time_activity,
        )
        send_appropriation(appropriation,
                           Activity.objects.filter(pk=one_time_activity.pk))
        # Retrieve the mocked template.render call.
        render_call_args = get_template_mock.return_value.render.call_args[1]
        # Assert the activities was part of the call to render.
        self.assertCountEqual([activity],
                              render_call_args["context"]["main_activities"])
        self.assertCountEqual(
            [one_time_activity],
            render_call_args["context"]["supplementary_activities"],
        )
Example #8
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 #9
0
    def test_generate_payments_report_list(self):
        now = timezone.now().date()
        start_date = now
        end_date = now + timedelta(days=5)

        case = create_case(self.case_worker, self.municipality, self.district)
        create_related_person(case, "far test", "far", "1111111111")
        create_related_person(case, "mor test", "mor", "2222222222")
        section = create_section()
        appropriation = create_appropriation(sbsys_id="XXX-YYY",
                                             case=case,
                                             section=section)
        activity = create_activity(
            case,
            appropriation,
            start_date=start_date,
            end_date=end_date,
            activity_type=MAIN_ACTIVITY,
            status=STATUS_GRANTED,
        )
        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,
        )
        payments = payment_schedule.payments.all()
        payments[0].paid_amount = Decimal(666)
        payments[0].paid_date = now - timedelta(days=10)
        report_list = generate_payments_report_list_v0(payments)
        self.assertEqual(len(report_list), 6)
        first_elem = report_list[0]
        # Assert that the following dict is a subset of the first element.
        expected_data = {
            "amount": Decimal("666.00"),
            "paid_amount": None,
            "paid_date": None,
            "account_string": "12345-UKENDT-123",
            "payment_schedule__payment_amount": Decimal("666"),
            "payment_schedule__payment_frequency": "DAILY",
            "recipient_type": "PERSON",
            "recipient_id": "0205891234",
            "recipient_name": "Jens Testersen",
            "payment_method": "CASH",
            "fictive": False,
            "activity__details__name": "Test aktivitet",
            "activity__details__activity_id": "000000",
            "sbsys_id": "XXX-YYY",
            "cpr_number": "0205891234",
            "name": "Jens Jensen",
            "effort_step": "Trin 1: Tidlig indsats i almenområdet",
            "paying_municipality": "København",
            "acting_municipality": "København",
            "residence_municipality": "København",
            "section": "ABL-105-2",
            "scaling_step": "1",
            "case_worker": "Orla Frøsnapper",
            "leader": "Orla Frøsnapper",
            "team": "FCK",
            "target_group": case.target_group,
            "activity_type": "MAIN_ACTIVITY",
            "main_activity_id":
            (appropriation.main_activity.details.activity_id),
            "father_cpr": "1111111111",
            "mother_cpr": "2222222222",
        }
Example #10
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 #11
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)
Example #12
0
        # Assert the activities was part of the call to render.
        self.assertCountEqual([activity],
                              render_call_args["context"]["main_activities"])
        self.assertCountEqual(
            [one_time_activity],
            render_call_args["context"]["supplementary_activities"],
        )

    @mock.patch("core.utils.HTML")
    @mock.patch("core.utils.EmailMessage")
    @mock.patch("core.utils.get_template")
    def test_send_appropriation_no_included(self, get_template_mock, html_mock,
                                            message_mock):
        case = create_case(self.case_worker, self.municipality, self.district)
        section = create_section()
        appropriation = create_appropriation(sbsys_id="XXX-YYY",
                                             case=case,
                                             section=section)

        now = timezone.now().date()
        activity = create_activity(
            case,
            appropriation,
            start_date=now - timedelta(days=5),
            end_date=now + timedelta(days=5),
            activity_type=MAIN_ACTIVITY,
            status=STATUS_GRANTED,
        )
        section.main_activities.add(activity.details)

        suppl_activity = create_activity(
            case,