Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
[PC-7746] Stock.dnBookedQuantity for get_active_bookings_quantity_for…
Browse files Browse the repository at this point in the history
…_venue

  This property isn't usable for this function.
A comment has been added.
Also, fixing the BookingFactory to générate the right amount of
dnBookedQuantity.
  • Loading branch information
rlecellier committed May 4, 2021
1 parent 72acb98 commit 64465d3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/pcapi/core/bookings/factories.py
Expand Up @@ -15,13 +15,7 @@ class Meta:
model = models.Booking

quantity = 1
stock = factory.Maybe(
"isCancelled",
yes_declaration=factory.SubFactory(offers_factories.StockFactory),
no_declaration=factory.SubFactory(
offers_factories.StockFactory, dnBookedQuantity=factory.SelfAttribute("..quantity")
),
)
stock = factory.SubFactory(offers_factories.StockFactory)
token = factory.LazyFunction(random_token)
user = factory.SubFactory(users_factories.UserFactory)
amount = factory.SelfAttribute("stock.price")
Expand All @@ -45,7 +39,7 @@ def cancellation_date(self, create, extracted, **kwargs):

@classmethod
def _create(cls, model_class, *args, **kwargs):
if kwargs.get("stock") and not kwargs.get("isCancelled", False):
if not kwargs.get("isCancelled", False):
stock = kwargs.get("stock")
stock.dnBookedQuantity = stock.dnBookedQuantity + kwargs.get("quantity", 1)
kwargs["stock"] = stock
Expand Down
1 change: 1 addition & 0 deletions src/pcapi/core/bookings/repository.py
Expand Up @@ -190,6 +190,7 @@ def find_expired_bookings_ordered_by_offerer(expired_on: date = None) -> Query:


def get_active_bookings_quantity_for_venue(venue_id: int) -> int:
# Stock.dnBookedQuantity cannot be used here cause it's only count "not cancelled" bookings.
return (
Booking.query.join(Stock)
.join(Offer)
Expand Down

0 comments on commit 64465d3

Please sign in to comment.