def test_appropriations_get(self): reverse_url = reverse("graphql-api") self.client.login(username=self.username, password=self.password) case = create_case(self.case_worker, self.municipality, self.district) appropriation = create_appropriation(case) json = { "query": """ query { appropriations { edges { node { id, sbsysId } } } } """ } response = self.client.get(reverse_url, json) self.assertEqual(response.status_code, 200) node = response.json()["data"]["appropriations"]["edges"][0]["node"] self.assertEqual( node["id"], b64encode(f"Appropriation:{appropriation.pk}".encode()).decode(), ) self.assertEqual(node["sbsysId"], appropriation.sbsys_id)
def test_activity_service_providers_no_company_info(self, logger_mock): section = create_section() case = create_case(self.case_worker, self.municipality, self.district) appropriation = create_appropriation(case=case, section=section) today = timezone.now().date() activity = create_activity( case=case, appropriation=appropriation, activity_type=MAIN_ACTIVITY, status=STATUS_GRANTED, start_date=today, end_date=today + timedelta(days=7), ) create_payment_schedule( payment_frequency=PaymentSchedule.MONTHLY, payment_type=PaymentSchedule.RUNNING_PAYMENT, recipient_type=PaymentSchedule.COMPANY, payment_method=INVOICE, recipient_id="25052943", activity=activity, ) self.assertIsNone(activity.service_provider) call_command("update_activity_service_providers") activity.refresh_from_db() self.assertIsNone(activity.service_provider) logger_mock.info.assert_called_with( "Could not retrieve company info for CVR number: 25052943" )
def test_extended_connection_cases_get(self): """the Case model has ExtendedConnection as connection class.""" reverse_url = reverse("graphql-api") self.client.login(username=self.username, password=self.password) create_case(self.case_worker, self.municipality, self.district) json = { "query": """ query { cases { totalCount, edgeCount, edges { node { id, } } } }""" } response = self.client.get(reverse_url, json) self.assertEqual(response.status_code, 200) cases = response.json()["data"]["cases"] self.assertEqual(cases["totalCount"], 1) self.assertEqual(cases["edgeCount"], 1)
def test_cases_get(self): reverse_url = reverse("graphql-api") self.client.login(username=self.username, password=self.password) case = create_case(self.case_worker, self.municipality, self.district) json = { "query": """ query { cases { edges { node { id, name } } } }""" } response = self.client.get(reverse_url, json) self.assertEqual(response.status_code, 200) node = response.json()["data"]["cases"]["edges"][0]["node"] self.assertEqual(node["id"], b64encode(f"Case:{case.pk}".encode()).decode()) self.assertEqual(node["name"], case.name)
def test_send_expired_emails_success(self): today = timezone.now().date() case = create_case(self.case_worker, self.municipality, self.district) appropriation = create_appropriation(case=case) activity = create_activity( case=case, appropriation=appropriation, activity_type=MAIN_ACTIVITY, status=STATUS_GRANTED, start_date=today - timedelta(days=30), end_date=today - timedelta(days=1), ) create_payment_schedule( payment_frequency=PaymentSchedule.DAILY, payment_type=PaymentSchedule.RUNNING_PAYMENT, activity=activity, ) # Only created email should be sent initially. self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox[0].subject, "Aktivitet oprettet - 0205891234" ) call_command("send_expired_emails") # Then expired email. self.assertEqual(len(mail.outbox), 2) self.assertEqual( mail.outbox[1].subject, "Aktivitet udgået - 0205891234" )
def test_activity_service_providers_updated(self): section = create_section() case = create_case(self.case_worker, self.municipality, self.district) appropriation = create_appropriation(case=case, section=section) today = timezone.now().date() activity = create_activity( case=case, appropriation=appropriation, activity_type=MAIN_ACTIVITY, status=STATUS_GRANTED, start_date=today, end_date=today + timedelta(days=7), ) create_payment_schedule( payment_frequency=PaymentSchedule.MONTHLY, payment_type=PaymentSchedule.RUNNING_PAYMENT, recipient_type=PaymentSchedule.COMPANY, payment_method=INVOICE, recipient_id="25052943", activity=activity, ) self.assertIsNone(activity.service_provider) call_command("update_activity_service_providers") activity.refresh_from_db() service_provider = ServiceProvider.objects.get(cvr_number="25052943") self.assertEqual(activity.service_provider, service_provider)
def test_mark_payments_paid_exception_raised( self, payment_mock, logger_mock ): payment_schedule = create_payment_schedule(fictive=True) case = create_case(self.case_worker, self.municipality, self.district) appropriation = create_appropriation(case=case) create_activity( case=case, appropriation=appropriation, activity_type=MAIN_ACTIVITY, status=STATUS_GRANTED, payment_plan=payment_schedule, ) today = timezone.now().date() payment = create_payment(payment_schedule, date=today) payment_mock.objects.filter.side_effect = IntegrityError call_command( "mark_payments_paid", "--date=" + today.strftime("%Y%m%d") ) payment.refresh_from_db() self.assertFalse(payment.paid) self.assertIsNone(payment.paid_date, today) self.assertIsNone(payment.paid_amount, payment.amount) self.assertTrue(logger_mock.exception.called)
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 ]))
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 ], )
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 ]))
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"))
def test_activities_get(self): reverse_url = reverse("graphql-api") self.client.login(username=self.username, password=self.password) payment_schedule = create_payment_schedule( payment_frequency=PaymentSchedule.DAILY, payment_type=PaymentSchedule.RUNNING_PAYMENT, ) case = create_case(self.case_worker, self.municipality, self.district) appropriation = create_appropriation(case=case) # create a main activity with an expired end_date. activity = create_activity( case=case, appropriation=appropriation, payment_plan=payment_schedule, ) json = { "query": """ query { activities { edges { node { id, status, totalGrantedThisYear, totalExpectedThisYear, totalGrantedPreviousYear, totalExpectedPreviousYear, totalGrantedNextYear, totalExpectedNextYear, } } } } """ } response = self.client.get(reverse_url, json) self.assertEqual(response.status_code, 200) node = response.json()["data"]["activities"]["edges"][0]["node"] self.assertEqual( node["id"], b64encode(f"Activity:{activity.pk}".encode()).decode()) self.assertEqual(node["status"], activity.status) self.assertEqual(node["totalGrantedThisYear"], 0.0) self.assertEqual(node["totalExpectedThisYear"], 0.0) self.assertEqual(node["totalGrantedPreviousYear"], 0.0) self.assertEqual(node["totalExpectedPreviousYear"], 0.0) self.assertEqual(node["totalGrantedNextYear"], 0.0) self.assertEqual(node["totalExpectedNextYear"], 0.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()
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, )
def test_generate_payments_report_success(self, logger_mock): section = create_section() case = create_case(self.case_worker, self.municipality, self.district) appropriation = create_appropriation(case=case, section=section) activity = create_activity( case=case, appropriation=appropriation, activity_type=MAIN_ACTIVITY, status=STATUS_GRANTED, start_date=date(year=2020, month=1, day=1), end_date=date(year=2020, month=2, day=1), ) create_payment_schedule( payment_frequency=PaymentSchedule.MONTHLY, payment_type=PaymentSchedule.RUNNING_PAYMENT, activity=activity, ) another_activity = create_activity( case=case, appropriation=appropriation, activity_type=SUPPL_ACTIVITY, status=STATUS_EXPECTED, start_date=date(year=2020, month=1, day=1), end_date=date(year=2020, month=2, day=1), ) create_payment_schedule( payment_frequency=PaymentSchedule.MONTHLY, payment_type=PaymentSchedule.RUNNING_PAYMENT, activity=another_activity, ) call_command("generate_payments_report") logger_mock.info.assert_has_calls( [ mock.call( "Created payments reports: " "['/tmp/expected_payments_0.csv', " "'/tmp/expected_payments_1.csv', " "'/tmp/expected_payments_2.csv', " "'/tmp/expected_payments_3.csv', " "'/tmp/granted_payments_3.csv']" ), ] )
class TestMarkPaymentsPaid(TestCase, BasicTestMixin): @classmethod def setUpTestData(cls): cls.basic_setup() def test_mark_payments_paid(self): case = create_case(self.case_worker, self.municipality, self.district) appropriation = create_appropriation(case=case) activity = create_activity( case=case, appropriation=appropriation, activity_type=MAIN_ACTIVITY, status=STATUS_GRANTED, ) payment_schedule = create_payment_schedule( activity=activity, fictive=True ) today = timezone.now().date() payment = create_payment(payment_schedule, date=today) call_command( "mark_payments_paid", "--date=" + today.strftime("%Y%m%d") ) payment.refresh_from_db() self.assertTrue(payment.paid) self.assertEqual(payment.paid_date, today) self.assertEqual(payment.paid_amount, payment.amount)
class GenerateCasesReportTestCase(TestCase, BasicTestMixin): @classmethod def setUpTestData(cls): cls.basic_setup() def test_generate_cases_report_list(self): 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") report_list = generate_cases_report_list_v0(Case.objects.all()) self.assertEqual(len(report_list), 1) first_elem = report_list[0] # Assert that the following dict is a subset of the first element. expected_data = { "id": "1", "history_id": "1", "cpr_number": "0205891234", "case_sbsys_id": "27.24.00-G01-99-21", "name": "Jens Jensen", "target_group": case.target_group, "case_worker": "Orla Frøsnapper", "team": "FCK", "leader": "Orla Frøsnapper", "efforts": "", "effort_step": "Trin 1: Tidlig indsats i almenområdet", "scaling_step": "1", "paying_municipality": "København", "acting_municipality": "København", "residence_municipality": "København", "father_cpr": "1111111111", "mother_cpr": "2222222222", }
class TestRenewPayments(TestCase, BasicTestMixin): @classmethod def setUpTestData(cls): cls.basic_setup() def test_renew_payments_renewed(self): case = create_case(self.case_worker, self.municipality, self.district) appropriation = create_appropriation(case=case) # Should generate payments to 2019-12-01. with freeze_time("2018-01-01"): activity = create_activity( case=case, appropriation=appropriation, activity_type=MAIN_ACTIVITY, status=STATUS_GRANTED, start_date=date(year=2018, month=1, day=1), end_date=None, ) payment_schedule = create_payment_schedule( payment_frequency=PaymentSchedule.MONTHLY, payment_type=PaymentSchedule.RUNNING_PAYMENT, activity=activity, ) self.assertEqual(payment_schedule.payments.count(), 24) # Generated payments are not 6 months ahead. # So we generate new payments from next payment date: # 2020-01-01 till end of next year (2020-12-01). with freeze_time("2019-12-01"): call_command("renew_payments") self.assertEqual(payment_schedule.payments.count(), 36)
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 )
def test_send_expired_emails_doesnt_trigger_email(self): today = timezone.now().date() case = create_case(self.case_worker, self.municipality, self.district) appropriation = create_appropriation(case=case) create_activity( case=case, appropriation=appropriation, activity_type=MAIN_ACTIVITY, status=STATUS_GRANTED, start_date=today - timedelta(days=30), end_date=today - timedelta(days=1), ) call_command("send_expired_emails") # No emails should be sent. self.assertEqual(len(mail.outbox), 0)
def test_generate_cases_report_exception_raised(self, logger_mock): section = create_section() case = create_case(self.case_worker, self.municipality, self.district) appropriation = create_appropriation(case=case, section=section) # We need granted and/or expected activities also. activity = create_activity( case=case, appropriation=appropriation, activity_type=MAIN_ACTIVITY, status=STATUS_GRANTED, start_date=date(year=2020, month=1, day=1), end_date=date(year=2020, month=2, day=1), ) create_payment_schedule( payment_frequency=PaymentSchedule.MONTHLY, payment_type=PaymentSchedule.RUNNING_PAYMENT, activity=activity, ) another_activity = create_activity( case=case, appropriation=appropriation, activity_type=SUPPL_ACTIVITY, status=STATUS_EXPECTED, start_date=date(year=2020, month=1, day=1), end_date=date(year=2020, month=2, day=1), ) create_payment_schedule( payment_frequency=PaymentSchedule.MONTHLY, payment_type=PaymentSchedule.RUNNING_PAYMENT, activity=another_activity, ) call_command("generate_cases_report") logger_mock.exception.assert_called_with( "An error occurred during generation of the cases report" )
def test_mark_payments_paid_wrong_date(self, logger_mock): payment_schedule = create_payment_schedule(fictive=True) case = create_case(self.case_worker, self.municipality, self.district) appropriation = create_appropriation(case=case) create_activity( case=case, appropriation=appropriation, activity_type=MAIN_ACTIVITY, status=STATUS_GRANTED, payment_plan=payment_schedule, ) today = timezone.now().date() payment = create_payment(payment_schedule, date=today) with self.assertRaises(SystemExit): call_command("mark_payments_paid", "--date=wrong_date") payment.refresh_from_db() self.assertFalse(payment.paid) self.assertIsNone(payment.paid_date, today) self.assertIsNone(payment.paid_amount, payment.amount) self.assertTrue(logger_mock.error.called)
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"], )
class TestRecalculateOnChangedRate(TestCase, BasicTestMixin): @classmethod def setUpTestData(cls): cls.basic_setup() def test_recalculate_on_changed(self): case = create_case(self.case_worker, self.municipality, self.district) appropriation = create_appropriation(case=case) rate = create_rate() rate.set_rate_amount(10) # Should generate payments to 2020-12-01. start_date = date(year=2020, month=1, day=1) end_date = start_date + timedelta(days=91) with freeze_time("2020-01-01"): activity = create_activity( case=case, appropriation=appropriation, activity_type=MAIN_ACTIVITY, status=STATUS_GRANTED, start_date=start_date, end_date=end_date, ) payment_schedule = create_payment_schedule( payment_frequency=PaymentSchedule.MONTHLY, payment_type=PaymentSchedule.RUNNING_PAYMENT, payment_units=1, payment_amount=None, activity=activity, payment_cost_type=PaymentSchedule.GLOBAL_RATE_PRICE, payment_rate=rate, ) self.assertEqual(payment_schedule.payments.count(), 4) payment = payment_schedule.payments.all()[0] self.assertEqual(payment.amount, 10) rate.set_rate_amount(15) call_command("recalculate_on_changed_rate") payment.refresh_from_db() self.assertEqual(payment.amount, 15)
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", }
# 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"], ) @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)
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. ], )
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)