Skip to content

Commit afda02c

Browse files
committed
fix: Adjustments for viur-core>=3.8 due to breaking changes
1 parent 2a55ef1 commit afda02c

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

src/viur/shop/modules/cart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from viur.core.prototypes import Tree
88
from viur.core.prototypes.tree import SkelType
99
from viur.core.session import Session
10-
from viur.core.skeleton import Skeleton, SkeletonInstance
10+
from viur.core.skeleton import Skeleton, SkeletonInstance, without_render_preparation
1111
from viur.shop.modules.abstract import ShopModuleAbstract
1212
from viur.shop.types import *
1313
from viur.shop.types.exceptions import InvalidStateError
@@ -206,7 +206,7 @@ def get_children_from_cache(
206206
) -> list[SkeletonInstance]:
207207
cache = current.request_data.get().setdefault("shop_cache_cart_children", {})
208208
try:
209-
return [toolkit.without_render_preparation(s) for s in cache[parent_cart_key]]
209+
return [without_render_preparation(s) for s in cache[parent_cart_key]]
210210
except KeyError:
211211
pass
212212
children = list(self.get_children(parent_cart_key))

src/viur/shop/modules/order.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,8 @@ def can_order(
414414
order_skel: "SkeletonInstance",
415415
) -> list[ClientError]:
416416
errors = []
417-
if order_skel["is_ordered"]:
418-
errors.append(ClientError("already is_ordered"))
417+
# if order_skel["is_ordered"]:
418+
# errors.append(ClientError("already is_ordered"))
419419
if not order_skel["cart"]:
420420
errors.append(ClientError("cart is missing"))
421421
if not order_skel["cart"] or not order_skel["cart"]["dest"]["shipping_address"]:
@@ -477,6 +477,9 @@ def set_paid(self, order_skel: "SkeletonInstance") -> "SkeletonInstance":
477477

478478
def set_rts(self, order_skel: "SkeletonInstance") -> "SkeletonInstance":
479479
"""Set an order to the state *Ready to ship*"""
480+
logger.debug(f"{order_skel.skeletonCls=}")
481+
logger.debug(f"{order_skel.renderPreparation=}")
482+
logger.debug(f"{order_skel=}")
480483
order_skel = toolkit.set_status(
481484
key=order_skel["key"],
482485
skel=order_skel,

src/viur/shop/skeletons/cart.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def _get_children(self, parent_cart_key: db.Key) -> list[SkeletonInstance]:
4343
return SHOP_INSTANCE.get().cart.get_children(parent_cart_key)
4444

4545
def __call__(self, skel: SkeletonInstance_T["CartNodeSkel"], bone: NumericBone):
46+
# skel = toolkit.without_render_preparation(skel)
4647
children = self._get_children(skel["key"])
4748
total = 0
4849
for child in children:
@@ -88,14 +89,16 @@ def add_shipping(factory: TotalFactory, total: float, skel: "SkeletonInstance",
8889
total += shipping["dest"]["shipping_cost"] or 0.0
8990
return total
9091

91-
92+
@toolkit.debug
9293
def get_vat_for_node(skel: "CartNodeSkel", bone: RecordBone) -> list[dict]:
94+
# skel = toolkit.without_render_preparation(skel)
9395
children = SHOP_INSTANCE.get().cart.get_children_from_cache(skel["key"])
9496
cat2value = collections.defaultdict(lambda: 0)
9597
cat2rate = {}
9698
# logger.debug(f"{skel=}")
9799
for child in children:
98-
# logger.debug(f"{child=}")
100+
logger.debug(f"{child=}")
101+
logger.debug(f"{child.renderPreparation=}")
99102
if issubclass(child.skeletonCls, CartNodeSkel):
100103
for entry in child["vat"] or []:
101104
# logger.debug(f'{child["shop_vat_rate_category"]} | {entry=}')
@@ -107,6 +110,8 @@ def get_vat_for_node(skel: "CartNodeSkel", bone: RecordBone) -> list[dict]:
107110
cat2rate[child["shop_vat_rate_category"]] = child.price_.vat_rate_percentage
108111
except TypeError as e:
109112
logger.warning(e)
113+
else:
114+
raise TypeError(f"Unknown child type: {child.skeletonCls=}")
110115

111116
if shipping := skel["shipping"]:
112117
try:
@@ -435,7 +440,9 @@ def article_skel_full(self) -> SkeletonInstance_T[ArticleAbstractSkel]:
435440
except KeyError:
436441
# logger.debug(f'Read article_skel_full {self.article_skel["key"]=}')
437442
skel = SHOP_INSTANCE.get().article_skel()
438-
assert skel.read(self.article_skel["key"])
443+
res = skel.read(self.article_skel["key"])
444+
print(f"skel.read {res=}")
445+
assert res
439446
CartItemSkel.get_article_cache()[self.article_skel["key"]] = skel
440447
return skel
441448

src/viur/shop/types/price.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121

2222
from viur import toolkit
2323
from viur.core import current, db, utils
24-
from viur.core.skeleton import SkeletonInstance
24+
from viur.core.skeleton import RefSkel, RelSkel, SkeletonInstance
2525
from .enums import ApplicationDomain, ConditionOperator, DiscountType
2626
from .exceptions import InvalidStateError
2727
from ..globals import SHOP_INSTANCE, SHOP_LOGGER
2828
from ..types import ConfigurationError, DiscountValidationContext
29+
from viur.core.skeleton.utils import is_skeletoninstance_of
2930

3031
if t.TYPE_CHECKING:
3132
from ..modules import Discount
@@ -70,7 +71,9 @@ def __init__(self, src_object: SkeletonInstance):
7071
super().__init__()
7172
# logger.debug(f"Creating new price object based on {src_object=}")
7273
shop = SHOP_INSTANCE.get()
73-
if isinstance(src_object, SkeletonInstance) and issubclass(src_object.skeletonCls, shop.cart.leafSkelCls):
74+
if is_skeletoninstance_of(src_object, shop.cart.leafSkelCls):
75+
# if isinstance(src_object, SkeletonInstance) and (issubclass(src_object.skeletonCls, shop.cart.leafSkelCls)
76+
# or issubclass(src_object.skeletonCls, RefSkel) and issubclass( src_object.skeletonCls.skeletonCls,shop.cart.leafSkelCls)):
7477
self.is_in_cart = True
7578
self.cart_leaf = src_object
7679
self.article_skel = toolkit.without_render_preparation(src_object.article_skel_full)
@@ -80,10 +83,14 @@ def __init__(self, src_object: SkeletonInstance):
8083
logger.exception(exc)
8184
self.cart_discounts = []
8285
self.cart_discounts = [toolkit.get_full_skel_from_ref_skel(d) for d in self.cart_discounts]
83-
elif isinstance(src_object, SkeletonInstance) and issubclass(src_object.skeletonCls, shop.article_skel):
86+
elif is_skeletoninstance_of(src_object, shop.article_skel):
87+
# elif isinstance(src_object, SkeletonInstance) and (issubclass(src_object.skeletonCls, shop.article_skel)
88+
# or issubclass(src_object.skeletonCls, RefSkel) and issubclass( src_object.skeletonCls.skeletonCls,shop.article_skel)):
8489
self.is_in_cart = False
8590
self.article_skel = toolkit.without_render_preparation(src_object)
8691
else:
92+
logger.error(f"Unsupported type {type(src_object)=} | {src_object.skeletonCls=}")
93+
logger.error(f"Unsupported type {type(src_object)=} | {type(src_object.skeletonCls)=}")
8794
raise TypeError(f"Unsupported type {type(src_object)}")
8895

8996
# logger.debug(f"{self.article_skel = }")

0 commit comments

Comments
 (0)