ob-dj-store 0.0.21.3__py3-none-any.whl → 0.0.21.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -967,22 +967,22 @@ class ProductSearchSerializer(
967
967
  )
968
968
 
969
969
  def get_store_id(self):
970
- return self.context["request"].query_params.get("store")
970
+ return self.context["view"].kwargs["store_pk"]
971
971
 
972
- def get_inventory_for_store(self, store_id):
973
- if hasattr(self, "get_inventory"):
974
- return self.get_inventory(store_id)
972
+ def get_inventory_for_store(self, product, store_id):
973
+ if store_id:
974
+ return product.get_inventory(store_id)
975
975
  return None
976
976
 
977
977
  def get_is_snoozed(self, obj):
978
978
  store_id = self.get_store_id()
979
- inventory = self.get_inventory_for_store(store_id)
979
+ inventory = self.get_inventory_for_store(obj, store_id)
980
980
  return obj.is_snoozed(store_id=store_id) if inventory else False
981
981
 
982
982
  def get_is_available(self, obj):
983
983
  store_id = self.get_store_id()
984
- inventory = self.get_inventory_for_store(store_id)
985
- return bool(inventory and inventory.quantity)
984
+ inventory = self.get_inventory_for_store(obj, store_id)
985
+ return bool(inventory and (inventory.quantity or inventory.is_uncountable))
986
986
 
987
987
 
988
988
  class ProductListSerializer(ArabicFieldsMixin, serializers.ModelSerializer):
@@ -250,13 +250,20 @@ class Product(DjangoModelCleanMixin, models.Model):
250
250
 
251
251
  def get_inventory(self, store_id):
252
252
  try:
253
- inventory = self.product_variants.inventories.get(store=store_id)
253
+ # Prefer the primary variant if available
254
+ product_variant = (
255
+ self.product_variants.filter(inventories__is_primary=True).first()
256
+ or self.product_variants.first()
257
+ )
258
+ if not product_variant:
259
+ return None
260
+ return product_variant.inventories.get(store_id=store_id)
254
261
  except ObjectDoesNotExist:
255
262
  return None
256
263
 
257
264
  def is_snoozed(self, store_id):
258
265
  try:
259
- inventory = self.product_variants.inventories.get(store=store_id)
266
+ inventory = self.product_variants.first().inventories.get(store=store_id)
260
267
  except ObjectDoesNotExist:
261
268
  return False
262
269
  return inventory.is_snoozed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ob-dj-store
3
- Version: 0.0.21.3
3
+ Version: 0.0.21.5
4
4
  Summary: OBytes django application for managing ecommerce stores.
5
5
  Home-page: https://www.obytes.com/
6
6
  Author: OBytes
@@ -3,7 +3,7 @@ ob_dj_store/apis/stores/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
3
3
  ob_dj_store/apis/stores/filters.py,sha256=JeUtcicJ3cFnZc71aUMEwn2jaVj1oNQsZOCZfdxGDu8,10338
4
4
  ob_dj_store/apis/stores/urls.py,sha256=W9sNJ7ST9pGnfVCf7GmduDO-_zK9MGTI6ybV8n-lzSc,2111
5
5
  ob_dj_store/apis/stores/views.py,sha256=cwDFNY2rtTfjl_F9PpR5zOJy2DPmGidOjIlJ9fsgSYI,42744
6
- ob_dj_store/apis/stores/rest/serializers/serializers.py,sha256=GUsUTN4MTXq92Uriv6Ql9MzjZJsSbmFDC3lZhSmB7vE,68219
6
+ ob_dj_store/apis/stores/rest/serializers/serializers.py,sha256=R_FGdD98iLWsb0dsI-kdq9_60yPkwahT_kMpfNPUzmQ,68239
7
7
  ob_dj_store/apis/tap/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  ob_dj_store/apis/tap/serializers.py,sha256=KPrBK4h2-fWvEVf6vOj2ww5-USV9WqpyYicIqoHIiXI,1065
9
9
  ob_dj_store/apis/tap/urls.py,sha256=bnOTv6an11kxpo_FdqlhsizlGPLVpNxBjCyKcf3_C9M,367
@@ -153,14 +153,14 @@ ob_dj_store/core/stores/models/_inventory.py,sha256=_rGlVL5HjOlHQVB8CI0776CPcE5r
153
153
  ob_dj_store/core/stores/models/_order.py,sha256=_08lqX5p4brCdUilqfbT--6Ao2TMsqnzXaWoV_7IYL8,9758
154
154
  ob_dj_store/core/stores/models/_partner.py,sha256=OuYvevUWn1sYHs9PcFf51EUUC1uqytQss8Bx91aMOH8,4732
155
155
  ob_dj_store/core/stores/models/_payment.py,sha256=FTV-NmvQjxwwR5C5X7qYWV-ZUIZfqMMEjkBNaS-drLs,6421
156
- ob_dj_store/core/stores/models/_product.py,sha256=iBSXZcZdtCXFINiOFqbnaZot9rWPkFdzySXwKJO5h6I,18239
156
+ ob_dj_store/core/stores/models/_product.py,sha256=KUi2hkA4VNCrWwWp3AM_tkubFptpOdiFt0Twzi2wW14,18535
157
157
  ob_dj_store/core/stores/models/_store.py,sha256=0K-CNJWuXNqeyULL1J0M9hiNcVla0UNNjdCdN_nzNEE,9833
158
158
  ob_dj_store/core/stores/models/_wallet.py,sha256=YvT-rvED-jrYjePLJpvdLXXoBudR6TGPu5cNE0m2fWo,5643
159
159
  ob_dj_store/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
160
160
  ob_dj_store/utils/helpers.py,sha256=o7wgypM7mI2vZqZKkhxnTcnHJC8GMQDOuYMnRwXr6tY,2058
161
161
  ob_dj_store/utils/model.py,sha256=DV7hOhTaZL3gh9sptts2jTUFlTArKG3i7oPioq9HLFE,303
162
162
  ob_dj_store/utils/utils.py,sha256=8UVAFB56qUSjJJ5f9vnermtw638gdFy4CFRCuMbns_M,1342
163
- ob_dj_store-0.0.21.3.dist-info/METADATA,sha256=-i8CuO0fLzxvE5HZ-Vjd9gItuWICNyeg2QLrNZChBK4,2850
164
- ob_dj_store-0.0.21.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
165
- ob_dj_store-0.0.21.3.dist-info/top_level.txt,sha256=CZG3G0ptTkzGnc0dFYN-ZD7YKdJBmm47bsmGwofD_lk,12
166
- ob_dj_store-0.0.21.3.dist-info/RECORD,,
163
+ ob_dj_store-0.0.21.5.dist-info/METADATA,sha256=K_XMw3wkfDg8n81xaZl2MErFWttOueqlGJqzuf_7pfQ,2850
164
+ ob_dj_store-0.0.21.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
165
+ ob_dj_store-0.0.21.5.dist-info/top_level.txt,sha256=CZG3G0ptTkzGnc0dFYN-ZD7YKdJBmm47bsmGwofD_lk,12
166
+ ob_dj_store-0.0.21.5.dist-info/RECORD,,