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_generate_payment_csv_raw_contains_human_readable_status_with_details_when_error(
            self, app):
        # given
        user = users_factories.UserFactory(email="*****@*****.**")
        offerer = create_offerer()
        venue = create_venue(offerer)
        stock = create_stock_with_thing_offer(offerer=offerer,
                                              venue=venue,
                                              price=10)
        booking = create_booking(user=user,
                                 stock=stock,
                                 is_used=True,
                                 token="ABCDEF",
                                 venue=venue)
        payment = create_payment(
            booking,
            offerer,
            transaction_label=
            "pass Culture Pro - remboursement 1ère quinzaine 07-2019",
            status=TransactionStatus.ERROR,
            amount=50,
            detail="Iban non fourni",
        )
        repository.save(payment)

        payments_info = find_all_offerer_payments(offerer.id)

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

        # then
        assert raw_csv[
            13] == "Erreur d'envoi du remboursement : Iban non fourni"
Exemplo n.º 3
0
    def test_reimbursementDetail_as_csv_individual_booking(self, app):
        # given
        payment = PaymentFactory(
            transactionLabel=
            "pass Culture Pro - remboursement 1ère quinzaine 07-2019",
            booking__amount=10.5,
            booking__quantity=2,
        )
        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] == "Doux"
        assert raw_csv[9] == "Jeanne"
        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é"
Exemplo n.º 4
0
def find_all_offerer_reimbursement_details(
        offerer_id: int) -> List[ReimbursementDetails]:
    offerer_payments = find_all_offerer_payments(offerer_id)
    reimbursement_details = [
        ReimbursementDetails(offerer_payment)
        for offerer_payment in offerer_payments
    ]

    return reimbursement_details
Exemplo n.º 5
0
    def test_should_return_one_payment_info_with_sent_status(self, app):
        # Given
        user = users_factories.UserFactory(lastName="User", firstName="Plus")
        offerer = create_offerer(address="7 rue du livre")
        venue = create_venue(offerer)
        stock = create_stock_with_thing_offer(offerer=offerer,
                                              venue=venue,
                                              price=10)
        now = datetime.utcnow()
        booking = create_booking(user=user,
                                 stock=stock,
                                 is_used=True,
                                 date_used=now,
                                 token="ABCDEF",
                                 venue=venue)

        payment = create_payment(
            booking,
            offerer,
            transaction_label=
            "pass Culture Pro - remboursement 1ère quinzaine 07-2019",
            status=TransactionStatus.ERROR,
            amount=50,
            detail="Iban non fourni",
            status_date=now - timedelta(days=2),
        )
        payment_status1 = create_payment_status(payment,
                                                detail="All good",
                                                status=TransactionStatus.RETRY,
                                                date=now - timedelta(days=1))
        payment_status2 = create_payment_status(payment,
                                                detail="All good",
                                                status=TransactionStatus.SENT)
        repository.save(payment, payment_status1, payment_status2)

        # When
        payments = find_all_offerer_payments(offerer.id)

        # Then
        assert len(payments) == 1
        assert payments[0] == (
            "User",
            "Plus",
            "ABCDEF",
            now,
            "Test Book",
            "7 rue du livre",
            "La petite librairie",
            "12345678912345",
            "123 rue de Paris",
            Decimal("50.00"),
            None,
            "pass Culture Pro - remboursement 1ère quinzaine 07-2019",
            TransactionStatus.SENT,
            "All good",
        )
    def test_should_return_payments_from_multiple_venues(self, app):
        # Given
        offerer = OffererFactory()
        payments_factories.PaymentStatusFactory(
            payment__booking__stock__offer__venue__managingOfferer=offerer,
            status=TransactionStatus.SENT)
        payments_factories.PaymentStatusFactory(
            payment__booking__stock__offer__venue__managingOfferer=offerer,
            status=TransactionStatus.SENT)

        # When
        payments = find_all_offerer_payments(offerer.id, reimbursement_period)

        # Then
        assert len(payments) == 2
    def test_should_not_return_payment_info_with_error_status(self, app):
        # Given
        booking = bookings_factories.UsedBookingFactory()
        offerer = booking.offerer
        payment = payments_factories.PaymentFactory(
            booking=booking,
            transactionLabel=
            "pass Culture Pro - remboursement 1ère quinzaine 07-2019")
        payments_factories.PaymentStatusFactory(payment=payment,
                                                status=TransactionStatus.ERROR,
                                                detail="Iban non fourni")

        # When
        payments = find_all_offerer_payments(offerer.id, reimbursement_period)

        # Then
        assert len(payments) == 0
Exemplo n.º 8
0
    def test_reimbursementDetail_with_custom_rule_as_csv(self, app):
        # given
        payment = PaymentWithCustomRuleFactory(
            transactionLabel=
            "pass Culture Pro - remboursement 1ère quinzaine 07-2019",
            booking__amount=10.5,
            booking__quantity=2,
        )
        payments_factories.PaymentStatusFactory(payment=payment,
                                                status=TransactionStatus.SENT)

        payments_info = find_all_offerer_payments(payment.booking.offererId,
                                                  reimbursement_period)

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

        # then
        assert raw_csv[13] == ""
    def test_should_return_payments_filtered_by_venue(self, app):
        # Given
        offerer = OffererFactory()
        venue_1 = VenueFactory(managingOfferer=offerer)
        venue_2 = VenueFactory(managingOfferer=offerer)

        payment_1 = payments_factories.PaymentFactory(
            booking__stock__offer__venue=venue_1)
        payments_factories.PaymentStatusFactory(payment=payment_1,
                                                status=TransactionStatus.SENT)
        payment_2 = payments_factories.PaymentFactory(
            booking__stock__offer__venue=venue_2)
        payments_factories.PaymentStatusFactory(payment=payment_2,
                                                status=TransactionStatus.SENT)

        # When
        payments = find_all_offerer_payments(offerer.id, reimbursement_period,
                                             venue_1.id)

        # Then
        assert len(payments) == 1
        assert payment_1.booking.token in payments[0]
        assert venue_1.name in payments[0]
    def test_should_return_payments_filtered_by_payment_date(self, app):
        # Given
        tomorrow_at_nine = datetime.combine(
            tomorrow, datetime.min.time()) + timedelta(hours=9)
        offerer = OffererFactory()
        venue_1 = VenueFactory(managingOfferer=offerer)
        payment_1 = payments_factories.PaymentFactory(
            booking__stock__offer__venue=venue_1)
        payments_factories.PaymentStatusFactory(date=tomorrow_at_nine,
                                                payment=payment_1,
                                                status=TransactionStatus.SENT)
        payment_2 = payments_factories.PaymentFactory(
            booking__stock__offer__venue=venue_1)
        payments_factories.PaymentStatusFactory(date=in_two_days,
                                                payment=payment_2,
                                                status=TransactionStatus.SENT)

        # When
        payments = find_all_offerer_payments(offerer.id, (today, tomorrow))

        # Then
        assert len(payments) == 1
        assert payment_1.booking.token in payments[0]
        assert venue_1.name in payments[0]
Exemplo n.º 11
0
    def test_should_return_last_matching_status_based_on_date_for_each_payment(
            self, app):
        # Given
        user = users_factories.UserFactory(lastName="User", firstName="Plus")
        offerer = create_offerer(address="7 rue du livre")
        venue = create_venue(offerer)
        stock = create_stock_with_thing_offer(offerer=offerer,
                                              venue=venue,
                                              price=10)
        now = datetime.utcnow()
        booking1 = create_booking(user=user,
                                  stock=stock,
                                  is_used=True,
                                  date_used=now,
                                  token="ABCDEF",
                                  venue=venue)
        booking2 = create_booking(user=user,
                                  stock=stock,
                                  is_used=True,
                                  date_used=now,
                                  token="ABCDFE",
                                  venue=venue)

        payment1 = create_payment(
            booking1,
            offerer,
            transaction_label=
            "pass Culture Pro - remboursement 1ère quinzaine 07-2019",
            status=TransactionStatus.PENDING,
            amount=50,
            status_date=now - timedelta(days=2),
        )
        payment2 = create_payment(
            booking2,
            offerer,
            transaction_label=
            "pass Culture Pro - remboursement 2ème quinzaine 07-2019",
            status=TransactionStatus.PENDING,
            amount=75,
            status_date=now - timedelta(days=4),
        )

        repository.save(payment1, payment2)

        last_status_for_payment1 = create_payment_status(
            payment1,
            detail="All good",
            status=TransactionStatus.SENT,
            date=now)
        last_status_for_payment2 = create_payment_status(
            payment2, detail=None, status=TransactionStatus.SENT, date=now)
        repository.save(last_status_for_payment1, last_status_for_payment2)

        first_status_for_payment1 = create_payment_status(
            payment1,
            detail="Retry",
            status=TransactionStatus.RETRY,
            date=now - timedelta(days=1))
        first_status_for_payment2 = create_payment_status(
            payment2,
            detail="Iban non fournis",
            status=TransactionStatus.ERROR,
            date=now - timedelta(days=3))
        repository.save(first_status_for_payment1, first_status_for_payment2)

        # When
        payments = find_all_offerer_payments(offerer.id)

        # Then
        assert len(payments) == 2
        assert payments[0] == (
            "User",
            "Plus",
            "ABCDFE",
            now,
            "Test Book",
            "7 rue du livre",
            "La petite librairie",
            "12345678912345",
            "123 rue de Paris",
            Decimal("75.00"),
            None,
            "pass Culture Pro - remboursement 2ème quinzaine 07-2019",
            TransactionStatus.SENT,
            None,
        )
        assert payments[1] == (
            "User",
            "Plus",
            "ABCDEF",
            now,
            "Test Book",
            "7 rue du livre",
            "La petite librairie",
            "12345678912345",
            "123 rue de Paris",
            Decimal("50.00"),
            None,
            "pass Culture Pro - remboursement 1ère quinzaine 07-2019",
            TransactionStatus.SENT,
            "All good",
        )
    def test_should_return_one_payment_info_with_sent_status(self, app):
        # Given
        beneficiary = users_factories.BeneficiaryGrant18Factory(
            lastName="User", firstName="Plus")
        stock = offers_factories.ThingStockFactory(
            offer__name="Test Book",
            offer__venue__managingOfferer__address="7 rue du livre",
            offer__venue__name="La petite librairie",
            offer__venue__address="123 rue de Paris",
            offer__venue__siret=12345678912345,
            price=10,
        )
        now = datetime.utcnow()
        booking = bookings_factories.UsedIndividualBookingFactory(
            individualBooking__user=beneficiary,
            stock=stock,
            dateUsed=now,
            token="ABCDEF")

        payment = payments_factories.PaymentFactory(
            amount=50,
            reimbursementRate=0.5,
            booking=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(
            stock.offer.venue.managingOfferer.id, reimbursement_period)

        # Then
        assert len(payments) == 1
        expected_elements = (
            "User",
            "Plus",
            "ABCDEF",
            now,
            1,
            Decimal("10.00"),
            "Test Book",
            "7 rue du livre",
            "La petite librairie",
            "12345678912345",
            "123 rue de Paris",
            Decimal("50.00"),
            Decimal("0.50"),
            "CF13QSDFGH456789",
            "pass Culture Pro - remboursement 1ère quinzaine 07-2019",
            TransactionStatus.SENT,
            "All good",
        )

        assert set(expected_elements).issubset(set(payments[0]))