Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PC-31907)[API] fix: Export bookings csv/xlsx #14217

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions api/src/pcapi/core/bookings/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,19 @@ def _create_export_query(offer_id: int, event_beginning_date: date) -> BaseQuery
.join(Booking.venue)
.join(Booking.stock)
.join(Stock.offer)
.outerjoin(Offer.offererAddress)
.join(OffererAddress.address)
.outerjoin(VenueOffererAddress, Venue.offererAddressId == VenueOffererAddress.id)
.join(VenueAddress, VenueOffererAddress.addressId == VenueAddress.id)
.filter(Stock.offerId == offer_id, field_to_venue_timezone(Stock.beginningDatetime) == event_beginning_date)
)
if FeatureToggle.WIP_USE_OFFERER_ADDRESS_AS_DATA_SOURCE.is_active():
query = (
query.join(Offer.offererAddress)
.join(OffererAddress.address)
.join(VenueOffererAddress, Venue.offererAddressId == VenueOffererAddress.id)
.join(VenueAddress, VenueOffererAddress.addressId == VenueAddress.id)
)

query = (
query.filter(
Stock.offerId == offer_id, field_to_venue_timezone(Stock.beginningDatetime) == event_beginning_date
)
.order_by(Booking.id)
.with_entities(*with_entities)
)
Expand Down
1 change: 1 addition & 0 deletions api/src/pcapi/routes/serialization/address_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def retrieve_address_info_from_oa(offerer_address: OffererAddress) -> dict:
inseeCode=offerer_address.address.inseeCode,
postalCode=offerer_address.address.postalCode,
street=offerer_address.address.street,
departmentCode=offerer_address.address.departmentCode,
city=offerer_address.address.city,
longitude=offerer_address.address.longitude,
latitude=offerer_address.address.latitude,
Expand Down
58 changes: 33 additions & 25 deletions api/tests/core/bookings/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ def should_return_validated_bookings_for_offer(self):

venue = offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.OfferFactory(venue=venue)
offer = offers_factories.OfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.EventStockFactory(
offer=offer, beginningDatetime=datetime.utcnow() + timedelta(days=10)
)
Expand Down Expand Up @@ -1256,7 +1256,7 @@ def should_return_validated_bookings_for_offer_with_old_cancelled_booking(self):

venue = offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.OfferFactory(venue=venue)
offer = offers_factories.OfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.EventStockFactory(
offer=offer, beginningDatetime=datetime.utcnow() + timedelta(days=10)
)
Expand Down Expand Up @@ -1372,7 +1372,7 @@ def should_return_validated_bookings_for_offer_with_duo(self):

venue = offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.OfferFactory(venue=venue)
offer = offers_factories.OfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.EventStockFactory(offer=offer, beginningDatetime=datetime.utcnow() + timedelta(days=5))
validated_booking = bookings_factories.UsedBookingFactory(stock=stock, user=beneficiary, quantity=2)
validated_booking_2 = bookings_factories.BookingFactory(
Expand Down Expand Up @@ -1476,7 +1476,7 @@ def should_return_all_bookings_for_offer(self):

venue = offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.OfferFactory(venue=venue)
offer = offers_factories.OfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.EventStockFactory(
offer=offer, beginningDatetime=datetime.utcnow() + timedelta(days=10)
)
Expand Down Expand Up @@ -1576,7 +1576,7 @@ def should_return_all_bookings_for_offer_with_duo(self):

venue = offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.OfferFactory(venue=venue)
offer = offers_factories.OfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.EventStockFactory(offer=offer, beginningDatetime=datetime.utcnow() + timedelta(days=5))
validated_booking = bookings_factories.UsedBookingFactory(stock=stock, user=beneficiary, quantity=2)
validated_booking_2 = bookings_factories.BookingFactory(
Expand Down Expand Up @@ -2119,7 +2119,7 @@ def should_return_validated_bookings_for_offer(self):

venue = offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.OfferFactory(venue=venue)
offer = offers_factories.OfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.EventStockFactory(offer=offer, beginningDatetime=datetime.utcnow() + timedelta(days=3))
validated_booking = bookings_factories.UsedBookingFactory(stock=stock, user=beneficiary)
validated_booking_2 = bookings_factories.BookingFactory(
Expand Down Expand Up @@ -2225,7 +2225,7 @@ def should_return_validated_bookings_for_offer_with_duo(self):

venue = offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.OfferFactory(venue=venue)
offer = offers_factories.OfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.EventStockFactory(offer=offer, beginningDatetime=datetime.utcnow() + timedelta(days=3))
validated_booking = bookings_factories.UsedBookingFactory(stock=stock, user=beneficiary, quantity=2)
validated_booking_2 = bookings_factories.BookingFactory(
Expand Down Expand Up @@ -2331,7 +2331,7 @@ def should_return_all_bookings_for_offer(self):

venue = offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.OfferFactory(venue=venue)
offer = offers_factories.OfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.EventStockFactory(
offer=offer, beginningDatetime=datetime.utcnow() + timedelta(days=30)
)
Expand Down Expand Up @@ -2448,7 +2448,7 @@ def should_return_validated_bookings_for_offer_with_duo_offerer_with_mutiple_use
venue = offerers_factories.VenueFactory(managingOfferer=offerer)
offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.OfferFactory(venue=venue)
offer = offers_factories.OfferFactory(venue=venue, offererAddress=None)
offers_factories.OfferFactory(venue=venue)
stock = offers_factories.EventStockFactory(offer=offer, beginningDatetime=datetime.utcnow() + timedelta(days=3))
validated_booking = bookings_factories.UsedBookingFactory(stock=stock, user=beneficiary, quantity=2)
Expand Down Expand Up @@ -2555,7 +2555,7 @@ def should_return_all_bookings_for_offer_with_duo(self):

venue = offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.OfferFactory(venue=venue)
offer = offers_factories.OfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.EventStockFactory(
offer=offer, beginningDatetime=datetime.utcnow() + timedelta(days=30)
)
Expand Down Expand Up @@ -2676,7 +2676,7 @@ def test_should_return_only_expected_booking_attributes(self, app: fixture):
offerers_factories.UserOffererFactory(user=pro, offerer=offerer)

venue = offerers_factories.VenueFactory(managingOfferer=offerer)
offer = offers_factories.ThingOfferFactory(venue=venue)
offer = offers_factories.ThingOfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.ThingStockFactory(offer=offer, price=0)
booking_date = datetime(2020, 1, 1, 10, 0, 0) - timedelta(days=1)
booking = bookings_factories.UsedBookingFactory(
Expand Down Expand Up @@ -2779,7 +2779,7 @@ def test_should_not_return_token_for_non_used_goods(self, app: fixture):

venue = offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.ThingOfferFactory(venue=venue)
offer = offers_factories.ThingOfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.ThingStockFactory(offer=offer, price=0)
booking_date = datetime(2020, 1, 1, 10, 0, 0) - timedelta(days=1)
booking = bookings_factories.BookingFactory(
Expand Down Expand Up @@ -2966,7 +2966,7 @@ def test_should_return_booking_as_duo_when_quantity_is_two(self, app: fixture):

venue = offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.ThingOfferFactory(venue=venue)
offer = offers_factories.ThingOfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.ThingStockFactory(offer=offer, price=0)
bookings_factories.BookingFactory(user=beneficiary, stock=stock, quantity=2)

Expand Down Expand Up @@ -3055,7 +3055,7 @@ def test_should_return_event_booking_when_booking_is_on_an_event(self, app: fixt
offerers_factories.UserOffererFactory(user=pro, offerer=offerer)

venue = offerers_factories.VenueFactory(managingOfferer=offerer)
offer = offers_factories.EventOfferFactory(venue=venue)
offer = offers_factories.EventOfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.EventStockFactory(
offer=offer, price=0, beginningDatetime=datetime.utcnow() + timedelta(hours=98)
)
Expand Down Expand Up @@ -3156,7 +3156,7 @@ def test_should_return_event_confirmed_booking_when_booking_is_on_an_event_in_co

venue = offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.ThingOfferFactory(venue=venue)
offer = offers_factories.ThingOfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.ThingStockFactory(
offer=offer, price=0, beginningDatetime=datetime.utcnow() + timedelta(hours=98)
)
Expand Down Expand Up @@ -3218,7 +3218,7 @@ def test_should_return_cancelled_status_when_booking_has_been_cancelled(self, ap

venue = offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.ThingOfferFactory(venue=venue)
offer = offers_factories.ThingOfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.ThingStockFactory(offer=offer, price=5)
yesterday = datetime.utcnow() - timedelta(days=1)
bookings_factories.CancelledBookingFactory(
Expand Down Expand Up @@ -3288,7 +3288,7 @@ def test_should_return_validation_date_when_booking_has_been_used_and_not_cancel

venue = offerers_factories.VenueFactory(managingOfferer=offerer)
product = offers_factories.EventProductFactory()
offer = offers_factories.EventOfferFactory(venue=venue, product=product)
offer = offers_factories.EventOfferFactory(venue=venue, product=product, offererAddress=None)
stock = offers_factories.EventStockFactory(offer=offer, price=5)
yesterday = datetime.utcnow() - timedelta(days=1)
booking = bookings_factories.UsedBookingFactory(
Expand Down Expand Up @@ -3354,7 +3354,7 @@ def test_should_return_correct_number_of_matching_offerers_bookings_linked_to_us

venue = offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.ThingOfferFactory(venue=venue)
offer = offers_factories.ThingOfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.ThingStockFactory(offer=offer, price=0)
today = datetime.utcnow()
bookings_factories.BookingFactory(user=beneficiary, stock=stock, dateCreated=today, token="ABCD")
Expand Down Expand Up @@ -3438,7 +3438,7 @@ def test_should_return_booking_date_with_offerer_timezone_when_venue_is_digital(

venue = offerers_factories.VirtualVenueFactory(managingOfferer=offerer)

offer = offers_factories.ThingOfferFactory(venue=venue)
offer = offers_factories.ThingOfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.ThingStockFactory(offer=offer, price=0)
booking_date = datetime(2020, 1, 1, 10, 0, 0) - timedelta(days=1)
bookings_factories.UsedBookingFactory(
Expand Down Expand Up @@ -3498,7 +3498,9 @@ def test_should_return_booking_ean_when_information_is_available(self, app: fixt

venue = offerers_factories.VirtualVenueFactory(managingOfferer=offerer)

offer = offers_factories.ThingOfferFactory(venue=venue, extraData=dict({"ean": "9876543234"}))
offer = offers_factories.ThingOfferFactory(
venue=venue, extraData=dict({"ean": "9876543234"}), offererAddress=None
)
stock = offers_factories.ThingStockFactory(offer=offer, price=0)
booking_date = datetime(2020, 1, 1, 10, 0, 0) - timedelta(days=1)
bookings_factories.UsedBookingFactory(
Expand Down Expand Up @@ -3560,7 +3562,9 @@ def test_should_return_booking_with_venue_name_when_public_name_is_not_provided(
managingOfferer=offerer, name="Lieu pour un évènement", siret="11816909600069"
)
product = offers_factories.EventProductFactory(name="Shutter Island")
offer_for_event = offers_factories.EventOfferFactory(venue=venue_for_event, product=product)
offer_for_event = offers_factories.EventOfferFactory(
venue=venue_for_event, product=product, offererAddress=None
)
stock_for_event = offers_factories.EventStockFactory(offer=offer_for_event, price=0)
bookings_factories.UsedBookingFactory(
user=beneficiary,
Expand Down Expand Up @@ -3682,7 +3686,9 @@ def test_should_return_booking_with_venue_public_name_when_public_name_is_provid
managingOfferer=offerer, name="Opéra paris", publicName="Super Opéra de Paris", siret="11816909600069"
)
product = offers_factories.EventProductFactory(name="Shutter Island")
offer_for_event = offers_factories.EventOfferFactory(venue=venue_for_event, product=product)
offer_for_event = offers_factories.EventOfferFactory(
venue=venue_for_event, product=product, offererAddress=None
)
stock_for_event = offers_factories.EventStockFactory(offer=offer_for_event, price=0)
bookings_factories.UsedBookingFactory(
user=beneficiary,
Expand Down Expand Up @@ -3903,7 +3909,7 @@ def should_consider_venue_locale_datetime_when_filtering_by_event_date(self, app
event_datetime = datetime(2020, 4, 21, 20, 00)

offer_in_cayenne = offers_factories.OfferFactory(
venue__postalCode="97300", venue__managingOfferer=user_offerer.offerer
venue__postalCode="97300", venue__managingOfferer=user_offerer.offerer, offererAddress=None
)
cayenne_event_datetime = datetime(2020, 4, 22, 2, 0)
stock_in_cayenne = offers_factories.EventStockFactory(
Expand Down Expand Up @@ -4042,7 +4048,9 @@ def test_should_consider_venue_locale_datetime_when_filtering_by_booking_period(
requested_booking_period_ending = datetime(2020, 4, 22, 20, 00).date()

offer_in_cayenne = offers_factories.OfferFactory(
venue__postalCode="97300", venue__managingOfferer=user_offerer.offerer
venue__postalCode="97300",
venue__managingOfferer=user_offerer.offerer,
offererAddress=None,
)
cayenne_booking_datetime = datetime(2020, 4, 22, 2, 0)
stock_in_cayenne = offers_factories.EventStockFactory(
Expand Down Expand Up @@ -4485,7 +4493,7 @@ def test_should_return_excel_export_according_to_booking_attributes(self):

venue = offerers_factories.VenueFactory(managingOfferer=offerer)

offer = offers_factories.ThingOfferFactory(venue=venue)
offer = offers_factories.ThingOfferFactory(venue=venue, offererAddress=None)
stock = offers_factories.ThingStockFactory(offer=offer, price=0)
booking_date = datetime(2020, 1, 1, 10, 0, 0) - timedelta(days=1)
booking = bookings_factories.UsedBookingFactory(
Expand Down
1 change: 1 addition & 0 deletions api/tests/routes/pro/get_venue_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def when_user_has_rights_on_managing_offerer(self, client, db_session):
"postalCode": "75000",
"inseeCode": "75102",
"city": "Paris",
"departmentCode": "75",
"latitude": 48.87004,
"longitude": 2.3785,
"banId": "75102_7560_00001",
Expand Down
Loading