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

Commit

Permalink
(PC-11057): model offer: use subcategory in is_offline_only property
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliochka committed Sep 28, 2021
1 parent 11100a9 commit 949e302
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/pcapi/core/offers/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class ThingProductFactory(ProductFactory):


class DigitalProductFactory(ThingProductFactory):
subcategoryId = subcategories.VOD.id
name = factory.Sequence("Digital product {}".format)
url = factory.Sequence("http://example.com/product/{}".format)
isNational = True
Expand Down
15 changes: 2 additions & 13 deletions src/pcapi/core/offers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from sqlalchemy.orm import relationship

import pcapi.core.bookings.conf as bookings_conf
from pcapi.core.categories import subcategories
from pcapi.core.categories.subcategories import ALL_SUBCATEGORIES_DICT
from pcapi.core.categories.subcategories import Subcategory
from pcapi.models.db import Model
Expand Down Expand Up @@ -528,19 +529,7 @@ def thumbUrl(self) -> str:

@property
def is_offline_only(self) -> bool:
offline_thing = [
thing_type
for thing_type in ThingType
if self._is_same_type(thing_type) and self._is_offline_type_only(thing_type)
]

return len(list(offline_thing)) == 1

def _is_same_type(self, thing_type) -> bool:
return str(thing_type) == self.type

def _is_offline_type_only(self, thing_type):
return thing_type.value["offlineOnly"]
return self.subcategory.online_offline_platform == subcategories.OnlineOfflinePlatformChoices.OFFLINE.value

def get_label_from_type_string(self):
matching_type_thing = next(filter(lambda thing_type: str(thing_type) == self.type, ThingType))
Expand Down

0 comments on commit 949e302

Please sign in to comment.