def test_should_return_one_payment_info_with_sent_status_when_offer_educational(
            self, app):
        # Given
        now = datetime.utcnow()
        educational_booking = bookings_factories.UsedEducationalBookingFactory(
            educationalBooking__educationalRedactor__firstName="Dominique",
            educationalBooking__educationalRedactor__lastName="Leprof",
            dateUsed=now,
            token="ABCDEF",
            quantity=5,
            amount=50,
            stock__price=10,
        )

        payment = payments_factories.PaymentFactory(
            amount=50,
            reimbursementRate=1,
            booking=educational_booking,
            iban="CF13QSDFGH456789",
            transactionLabel=
            "pass Culture Pro - remboursement 1ère quinzaine 07-2019",
        )
        payments_factories.PaymentStatusFactory(payment=payment,
                                                status=TransactionStatus.ERROR,
                                                detail="Iban non fourni")
        payments_factories.PaymentStatusFactory(payment=payment,
                                                status=TransactionStatus.RETRY,
                                                detail="All good")
        payments_factories.PaymentStatusFactory(payment=payment,
                                                status=TransactionStatus.SENT,
                                                detail="All good")

        # When
        payments = find_all_offerer_payments(
            educational_booking.stock.offer.venue.managingOfferer.id,
            reimbursement_period)

        # Then
        assert len(payments) == 1
        assert payments[0] == (
            None,
            None,
            "Dominique",
            "Leprof",
            "ABCDEF",
            now,
            educational_booking.quantity,
            educational_booking.amount,
            educational_booking.stock.offer.name,
            educational_booking.stock.offer.venue.managingOfferer.address,
            educational_booking.stock.offer.venue.name,
            educational_booking.stock.offer.venue.siret,
            educational_booking.stock.offer.venue.address,
            Decimal("50.00"),
            Decimal("1.00"),
            "CF13QSDFGH456789",
            "pass Culture Pro - remboursement 1ère quinzaine 07-2019",
            TransactionStatus.SENT,
            "All good",
        )
    def test_degressive_reimbursement_above_150000(self):
        user = create_rich_user(150000)
        event1 = create_event_booking(user=user, price=150000)
        event2 = create_event_booking(price=100)
        thing = create_non_digital_thing_booking(price=100)
        digital = create_digital_booking(price=100)
        book = create_book_booking(price=100)
        educational = bookings_factories.UsedEducationalBookingFactory()
        bookings = [event1, event2, thing, digital, book, educational]

        reimbursements = reimbursement.find_all_booking_reimbursements(
            bookings, reimbursement.CustomRuleFinder())

        assert_partial_reimbursement(
            reimbursements[0], event1,
            reimbursement.ReimbursementRateByVenueBetween40000And150000,
            0.92 * 150000)
        assert_partial_reimbursement(
            reimbursements[1], event2,
            reimbursement.ReimbursementRateByVenueAbove150000, 90)
        assert_partial_reimbursement(
            reimbursements[2], thing,
            reimbursement.ReimbursementRateByVenueAbove150000, 90)
        assert_no_reimbursement_for_digital(reimbursements[3], digital)
        assert_partial_reimbursement(
            reimbursements[4], book,
            reimbursement.ReimbursementRateForBookAbove20000, 95)
        assert_total_reimbursement(
            reimbursements[5], reimbursement.EducationalOffersReimbursement,
            educational)
    def test_pre_september_2021_degressive_reimbursement_around_20000(self):
        user = create_rich_user(20000)
        event1 = create_event_booking(user=user, price=20000)
        event2 = create_event_booking(price=100)
        thing = create_non_digital_thing_booking(price=100)
        digital = create_digital_booking(price=100)
        book = create_book_booking(price=100)
        educational = bookings_factories.UsedEducationalBookingFactory()
        bookings = [event1, event2, thing, digital, book, educational]

        reimbursements = reimbursement.find_all_booking_reimbursements(
            bookings, reimbursement.CustomRuleFinder())

        assert_total_reimbursement(reimbursements[0],
                                   reimbursement.PhysicalOffersReimbursement,
                                   event1)
        rule = reimbursement.LegacyPreSeptember2021ReimbursementRateByVenueBetween20000And40000
        assert_partial_reimbursement(reimbursements[1], event2, rule,
                                     Decimal(95))
        assert_partial_reimbursement(reimbursements[2], thing, rule, 95)
        assert_no_reimbursement_for_digital(reimbursements[3], digital)
        assert_partial_reimbursement(
            reimbursements[4], book,
            reimbursement.ReimbursementRateForBookAbove20000, 95)
        assert_total_reimbursement(
            reimbursements[5], reimbursement.EducationalOffersReimbursement,
            educational)
    def test_select_custom_reimbursement_rule_if_applicable(self):
        offer1 = offers_factories.DigitalOfferFactory()
        booking1 = bookings_factories.UsedBookingFactory(stock__offer=offer1)
        offer2 = offers_factories.DigitalOfferFactory()
        booking2 = bookings_factories.UsedBookingFactory(stock__offer=offer2)
        rule1 = payments_factories.CustomReimbursementRuleFactory(offer=offer1,
                                                                  amount=5)
        payments_factories.CustomReimbursementRuleFactory(
            offer=offer2,
            timespan=[booking2.dateCreated + timedelta(days=2), None])
        educational = bookings_factories.UsedEducationalBookingFactory()
        bookings = [booking1, booking2, educational]
        reimbursements = reimbursement.find_all_booking_reimbursements(
            bookings, reimbursement.CustomRuleFinder())

        assert reimbursements[0].booking == booking1
        assert reimbursements[0].rule == rule1
        assert reimbursements[0].reimbursed_amount == 5
        assert_no_reimbursement_for_digital(reimbursements[1], booking2)
        assert_total_reimbursement(
            reimbursements[2], reimbursement.EducationalOffersReimbursement,
            educational)
    def test_degressive_reimbursement_around_20000(self):
        user = create_rich_user(20000)
        reimbursed_digital1 = create_digital_booking(
            product_subcategory_id=subcategories.MUSEE_VENTE_DISTANCE.id,
            user=user,
            price=20000,
        )
        reimbursed_digital2 = create_digital_booking(
            product_subcategory_id=subcategories.MUSEE_VENTE_DISTANCE.id,
            price=100,
        )
        thing = create_non_digital_thing_booking(price=100)
        digital = create_digital_booking(price=100)
        book = create_book_booking(price=100)
        educational = bookings_factories.UsedEducationalBookingFactory()
        bookings = [
            reimbursed_digital1, reimbursed_digital2, thing, digital, book,
            educational
        ]

        reimbursements = reimbursement.find_all_booking_reimbursements(
            bookings, reimbursement.CustomRuleFinder())

        assert_total_reimbursement(
            reimbursements[0],
            reimbursement.PhysicalOffersReimbursement,
            reimbursed_digital1,
        )
        rule = reimbursement.ReimbursementRateByVenueBetween20000And40000
        assert_partial_reimbursement(reimbursements[1], reimbursed_digital2,
                                     rule, 95)
        assert_partial_reimbursement(reimbursements[2], thing, rule, 95)
        assert_no_reimbursement_for_digital(reimbursements[3], digital)
        assert_partial_reimbursement(
            reimbursements[4], book,
            reimbursement.ReimbursementRateForBookAbove20000, 95)
        assert_total_reimbursement(
            reimbursements[5], reimbursement.EducationalOffersReimbursement,
            educational)
    def test_full_reimbursement_for_all_bookings_for_new_civil_year(self):
        user = create_rich_user(30000)
        booking1 = create_event_booking(user=user,
                                        price=20000,
                                        date_used=datetime(2018, 1, 1))
        booking2 = create_event_booking(user=user,
                                        price=100,
                                        date_used=datetime(2019, 1, 1))
        educational = bookings_factories.UsedEducationalBookingFactory()
        bookings = [booking1, booking2, educational]

        reimbursements = reimbursement.find_all_booking_reimbursements(
            bookings, reimbursement.CustomRuleFinder())

        assert_total_reimbursement(reimbursements[0],
                                   reimbursement.PhysicalOffersReimbursement,
                                   booking1)
        assert_total_reimbursement(reimbursements[1],
                                   reimbursement.PhysicalOffersReimbursement,
                                   booking2)
        assert_total_reimbursement(
            reimbursements[2], reimbursement.EducationalOffersReimbursement,
            educational)
Esempio n. 7
0
    def test_reimbursementDetail_as_csv_educational_booking(self, app):
        # given
        booking = booking_factories.UsedEducationalBookingFactory(amount=10.5,
                                                                  quantity=2)
        payment = PaymentFactory(
            booking=booking,
            transactionLabel=
            "pass Culture Pro - remboursement 1ère quinzaine 07-2019",
        )
        payments_factories.PaymentStatusFactory(payment=payment,
                                                status=TransactionStatus.SENT)

        payments_info = find_all_offerer_payments(payment.booking.offerer.id,
                                                  reimbursement_period)

        # when
        raw_csv = ReimbursementDetails(payments_info[0]).as_csv_row()

        # then
        assert raw_csv[0] == "2019"
        assert raw_csv[1] == "Juillet : remboursement 1ère quinzaine"
        assert raw_csv[2] == payment.booking.venue.name
        assert raw_csv[3] == payment.booking.venue.siret
        assert raw_csv[4] == payment.booking.venue.address
        assert raw_csv[5] == payment.iban
        assert raw_csv[6] == payment.booking.venue.name
        assert raw_csv[7] == payment.booking.stock.offer.name
        assert raw_csv[
            8] == payment.booking.educationalBooking.educationalRedactor.lastName
        assert raw_csv[
            9] == payment.booking.educationalBooking.educationalRedactor.firstName
        assert raw_csv[10] == payment.booking.token
        assert raw_csv[11] == payment.booking.dateUsed
        assert raw_csv[12] == "21,00"
        assert raw_csv[13] == f"{int(payment.reimbursementRate * 100)}%"
        assert raw_csv[14] == "21,00"
        assert raw_csv[15] == "Remboursement envoyé"
Esempio n. 8
0
def test_generate_reimbursement_details_csv_educational_booking():
    # given
    educational_booking = booking_factories.UsedEducationalBookingFactory(
        stock__offer__name='Mon titre ; un peu "spécial"',
        stock__offer__venue__name='Mon lieu ; un peu "spécial"',
        stock__offer__venue__siret="siret-1234",
        token="0E2722",
        amount=10.5,
        quantity=2,
        dateUsed=datetime(2021, 1, 1, 12, 0),
    )

    payment = PaymentFactory(
        booking=educational_booking,
        iban="iban-1234",
        transactionLabel=
        "pass Culture Pro - remboursement 1ère quinzaine 07-2019",
    )
    payments_factories.PaymentStatusFactory(payment=payment,
                                            status=TransactionStatus.SENT)
    offerer = payment.booking.offerer
    reimbursement_details = find_all_offerer_reimbursement_details(
        offerer.id, reimbursement_period)

    # when
    csv = generate_reimbursement_details_csv(reimbursement_details)

    # then
    rows = csv.splitlines()
    assert (
        rows[0] ==
        '"Année";"Virement";"Créditeur";"SIRET créditeur";"Adresse créditeur";"IBAN";"Raison sociale du lieu";"Nom de l\'offre";"Nom utilisateur";"Prénom utilisateur";"Contremarque";"Date de validation de la réservation";"Montant de la réservation";"Barème";"Montant remboursé";"Statut du remboursement"'
    )
    assert (
        rows[1] ==
        '"2019";"Juillet : remboursement 1ère quinzaine";"Mon lieu ; un peu ""spécial""";"siret-1234";"1 boulevard Poissonnière";"iban-1234";"Mon lieu ; un peu ""spécial""";"Mon titre ; un peu ""spécial""";"Khteur";"Reda";"0E2722";"2021-01-01 12:00:00";"21,00";"100%";"21,00";"Remboursement envoyé"'
    )
Esempio n. 9
0
def test_find_all_offerer_reimbursement_details():
    offerer = offers_factories.OffererFactory()
    venue1 = offers_factories.VenueFactory(managingOfferer=offerer)
    venue2 = offers_factories.VenueFactory(managingOfferer=offerer)
    educational_booking = booking_factories.UsedEducationalBookingFactory(
        stock__offer__venue=venue2)
    label = ("pass Culture Pro - remboursement 1ère quinzaine 07-2019", )
    payment_1 = payments_factories.PaymentFactory(
        booking__stock__offer__venue=venue1, transactionLabel=label)
    payment_2 = payments_factories.PaymentFactory(
        booking__stock__offer__venue=venue2, transactionLabel=label)
    payment_3 = payments_factories.PaymentFactory(booking=educational_booking,
                                                  transactionLabel=label)
    payments_factories.PaymentStatusFactory(payment=payment_1,
                                            status=TransactionStatus.SENT)
    payments_factories.PaymentStatusFactory(payment=payment_2,
                                            status=TransactionStatus.SENT)
    payments_factories.PaymentStatusFactory(payment=payment_3,
                                            status=TransactionStatus.SENT)

    reimbursement_details = find_all_offerer_reimbursement_details(
        offerer.id, reimbursement_period)

    assert len(reimbursement_details) == 3
    def test_reimbursement_under_20000(self):
        event = create_event_booking()
        thing = create_non_digital_thing_booking()
        digital = create_digital_booking()
        book = create_book_booking()
        educational = bookings_factories.UsedEducationalBookingFactory()
        bookings = [event, thing, digital, book, educational]

        reimbursements = reimbursement.find_all_booking_reimbursements(
            bookings, reimbursement.CustomRuleFinder())

        assert_total_reimbursement(reimbursements[0],
                                   reimbursement.PhysicalOffersReimbursement,
                                   event)
        assert_total_reimbursement(reimbursements[1],
                                   reimbursement.PhysicalOffersReimbursement,
                                   thing)
        assert_no_reimbursement_for_digital(reimbursements[2], digital)
        assert_total_reimbursement(
            reimbursements[3],
            reimbursement.ReimbursementRateForBookBelow20000, book)
        assert_total_reimbursement(
            reimbursements[4], reimbursement.EducationalOffersReimbursement,
            educational)