Skip to content

Commit

Permalink
(PC-31638)[PRO] fix: soften rules to edit legacy offers
Browse files Browse the repository at this point in the history
As of today, all offers do not have their OffererAddress.
In order for the users to modify older offers, we need to let
them update physical offers that do not have OffererAddress
associated.
  • Loading branch information
xordoquy committed Sep 3, 2024
1 parent 2d856ca commit 88623de
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion api/src/pcapi/core/offers/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from pcapi.domain import music_types
from pcapi.domain import show_types
from pcapi.models import api_errors
from pcapi.models.feature import FeatureToggle
from pcapi.models.offer_mixin import OfferValidationStatus
from pcapi.routes.public.books_stocks import serialization
from pcapi.utils import date
Expand Down Expand Up @@ -404,7 +405,7 @@ def check_digital_offer_fields(offer: models.Offer) -> None:

if offer.subcategory.is_online_only:
errors.add_error("url", f'Une offre de catégorie {offer.subcategory.id} doit contenir un champ "url"')
if offer.offererAddress is None:
if offer.offererAddress is None and FeatureToggle.WIP_ENABLE_OFFER_ADDRESS.is_active():
errors.add_error("offererAddress", "Une offre physique doit avoir une adresse")

if errors.errors:
Expand Down
23 changes: 23 additions & 0 deletions api/tests/routes/public/individual_offers/v1/post_product_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pcapi.core.offerers import factories as offerers_factories
from pcapi.core.offers import factories as offers_factories
from pcapi.core.offers import models as offers_models
from pcapi.core.testing import override_features
from pcapi.models import offer_mixin
from pcapi.utils import date as date_utils
from pcapi.utils import human_ids
Expand All @@ -24,6 +25,7 @@

class PostProductTest(PublicAPIVenueEndpointHelper):
endpoint_url = "/public/offers/v1/products"
endpoint_method = "post"

@staticmethod
def _get_base_payload(venue_id: int) -> dict:
Expand Down Expand Up @@ -384,6 +386,7 @@ def test_extra_data_deserialization(self, client):
}

@pytest.mark.usefixtures("db_session")
@override_features(WIP_ENABLE_OFFER_ADDRESS=True)
def test_physical_product_attached_to_digital_venue(self, client):
venue, _ = utils.create_offerer_provider_linked_to_venue(is_virtual=True)

Expand All @@ -407,6 +410,26 @@ def test_physical_product_attached_to_digital_venue(self, client):
}
assert offers_models.Offer.query.first() is None

@pytest.mark.usefixtures("db_session")
@override_features(WIP_ENABLE_OFFER_ADDRESS=False)
def test_physical_product_without_offerer_address_legacy(self, client):
venue, _ = utils.create_offerer_provider_linked_to_venue(is_virtual=False)

response = client.with_explicit_token(offerers_factories.DEFAULT_CLEAR_API_KEY).post(
"/public/offers/v1/products",
json={
"location": {"type": "physical", "venueId": venue.id},
"categoryRelatedFields": {
"category": "SUPPORT_PHYSIQUE_FILM",
"ean": "1234567891234",
},
"accessibility": utils.ACCESSIBILITY_FIELDS,
"name": "Le champ des possibles",
},
)

assert response.status_code == 200

@pytest.mark.usefixtures("db_session")
def test_event_category_not_accepted(self, client):
venue, _ = utils.create_offerer_provider_linked_to_venue()
Expand Down

0 comments on commit 88623de

Please sign in to comment.