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)
class PaymentFactory(BaseFactory): class Meta: model = models.Payment author = "batch" booking = factory.SubFactory( bookings_factories.UsedIndividualBookingFactory) amount = factory.LazyAttribute(lambda payment: payment.booking.total_amount * Decimal(payment.reimbursementRate)) recipientSiren = factory.SelfAttribute( "booking.stock.offer.venue.managingOfferer.siren") reimbursementRule = factory.Iterator(REIMBURSEMENT_RULE_DESCRIPTIONS) reimbursementRate = factory.LazyAttribute( lambda payment: reimbursement.get_reimbursement_rule( payment.booking, reimbursement.CustomRuleFinder(), Decimal(0) ).rate) recipientName = "Récipiendaire" iban = "CF13QSDFGH456789" bic = "QSDFGH8Z555" transactionLabel = None @factory.post_generation def statuses(obj, create, extracted, **kwargs): # pylint: disable=no-self-argument if not create: return None if extracted is not None: return extracted status = PaymentStatusFactory( payment=obj, status=payment_status.TransactionStatus.PENDING) return [status]
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_offerer_without_category_rule(self): yesterday = datetime.now() - timedelta(days=1) far_in_the_past = datetime.now() - timedelta(days=800) booking1 = bookings_factories.UsedBookingFactory() offerer = booking1.offerer booking2 = bookings_factories.UsedBookingFactory( offerer=offerer, dateUsed=far_in_the_past) booking3 = bookings_factories.UsedBookingFactory() rule = payments_factories.CustomReimbursementRuleFactory( offerer=offerer, timespan=(yesterday, None)) finder = reimbursement.CustomRuleFinder() assert finder.get_rule(booking1) == rule assert finder.get_rule(booking2) is None # outside `rule.timespan` assert finder.get_rule(booking3) is None # no rule for this offerer
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)
def test_offerer_with_category_rule(self): yesterday = datetime.now() - timedelta(days=1) far_in_the_past = datetime.now() - timedelta(days=800) booking1 = bookings_factories.UsedBookingFactory( stock__offer__subcategoryId=subcategories.FESTIVAL_CINE.id) offerer = booking1.offerer booking2 = bookings_factories.UsedBookingFactory( stock__offer__subcategoryId=subcategories.LIVRE_PAPIER.id, stock__offer__venue__managingOfferer=offerer) booking3 = bookings_factories.UsedBookingFactory( offerer=offerer, stock__offer__subcategoryId=subcategories.FESTIVAL_CINE.id, dateUsed=far_in_the_past) booking4 = bookings_factories.UsedBookingFactory() rule = payments_factories.CustomReimbursementRuleFactory( offerer=offerer, subcategories=[subcategories.FESTIVAL_CINE.id], timespan=(yesterday, None)) finder = reimbursement.CustomRuleFinder() assert finder.get_rule(booking1) == rule assert finder.get_rule(booking2) is None # wrong category assert finder.get_rule(booking3) is None # outside `rule.timespan` assert finder.get_rule(booking4) is None # no rule for this offerer
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)