Skip to content

Commit 7c12e1f

Browse files
committed
cleanup
1 parent afda02c commit 7c12e1f

File tree

3 files changed

+46
-20
lines changed

3 files changed

+46
-20
lines changed

src/viur/shop/modules/order.py

Lines changed: 2 additions & 5 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,9 +477,6 @@ 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=}")
483480
order_skel = toolkit.set_status(
484481
key=order_skel["key"],
485482
skel=order_skel,

src/viur/shop/skeletons/cart.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@
22
import typing as t # noqa
33

44
from viur import toolkit
5-
from viur.core import current, db, utils
5+
from viur.core import conf, current, db, utils
66
from viur.core.bones import *
77
from viur.core.prototypes.tree import TreeSkel
88
from viur.core.skeleton import SkeletonInstance
99
from viur.shop.types import *
10+
1011
from .vat import VatIncludedSkel
1112
from ..globals import SHOP_INSTANCE, SHOP_LOGGER
1213
from ..skeletons.article import ArticleAbstractSkel
1314
from ..types.response import make_json_dumpable
1415

1516
logger = SHOP_LOGGER.getChild(__name__)
1617

18+
if conf.version >= (3, 8, 15): # TODO: 3,8,16
19+
from viur.core.skeleton.utils import without_render_preparation
20+
else:
21+
from viur.toolkit import without_render_preparation
22+
1723
Addition = t.Callable[["TotalFactory", float, SkeletonInstance_T["CartNodeSkel"], BaseBone], float]
1824

1925

@@ -43,7 +49,7 @@ def _get_children(self, parent_cart_key: db.Key) -> list[SkeletonInstance]:
4349
return SHOP_INSTANCE.get().cart.get_children(parent_cart_key)
4450

4551
def __call__(self, skel: SkeletonInstance_T["CartNodeSkel"], bone: NumericBone):
46-
# skel = toolkit.without_render_preparation(skel)
52+
skel = without_render_preparation(skel)
4753
children = self._get_children(skel["key"])
4854
total = 0
4955
for child in children:
@@ -89,16 +95,16 @@ def add_shipping(factory: TotalFactory, total: float, skel: "SkeletonInstance",
8995
total += shipping["dest"]["shipping_cost"] or 0.0
9096
return total
9197

92-
@toolkit.debug
98+
99+
# @toolkit.debug
93100
def get_vat_for_node(skel: "CartNodeSkel", bone: RecordBone) -> list[dict]:
94-
# skel = toolkit.without_render_preparation(skel)
101+
skel = without_render_preparation(skel)
95102
children = SHOP_INSTANCE.get().cart.get_children_from_cache(skel["key"])
96103
cat2value = collections.defaultdict(lambda: 0)
97104
cat2rate = {}
98105
# logger.debug(f"{skel=}")
99106
for child in children:
100-
logger.debug(f"{child=}")
101-
logger.debug(f"{child.renderPreparation=}")
107+
# logger.debug(f"{child=}")
102108
if issubclass(child.skeletonCls, CartNodeSkel):
103109
for entry in child["vat"] or []:
104110
# logger.debug(f'{child["shop_vat_rate_category"]} | {entry=}')
@@ -441,7 +447,7 @@ def article_skel_full(self) -> SkeletonInstance_T[ArticleAbstractSkel]:
441447
# logger.debug(f'Read article_skel_full {self.article_skel["key"]=}')
442448
skel = SHOP_INSTANCE.get().article_skel()
443449
res = skel.read(self.article_skel["key"])
444-
print(f"skel.read {res=}")
450+
logger.info(f"skel.read {res=}")
445451
assert res
446452
CartItemSkel.get_article_cache()[self.article_skel["key"]] = skel
447453
return skel

src/viur/shop/types/price.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,47 @@
2020
import typing as t # noqa
2121

2222
from viur import toolkit
23-
from viur.core import current, db, utils
24-
from viur.core.skeleton import RefSkel, RelSkel, SkeletonInstance
23+
from viur.core import conf, current, db, utils
24+
from viur.core.skeleton import SkeletonInstance
25+
2526
from .enums import ApplicationDomain, ConditionOperator, DiscountType
2627
from .exceptions import InvalidStateError
2728
from ..globals import SHOP_INSTANCE, SHOP_LOGGER
2829
from ..types import ConfigurationError, DiscountValidationContext
29-
from viur.core.skeleton.utils import is_skeletoninstance_of
3030

3131
if t.TYPE_CHECKING:
3232
from ..modules import Discount
3333

3434
logger = SHOP_LOGGER.getChild(__name__)
3535

36+
if conf.version >= (3, 8, 15): # TODO: 3,8,16
37+
from viur.core.skeleton.utils import is_skeletoninstance_of
38+
else:
39+
def is_skeletoninstance_of(
40+
obj: t.Any,
41+
skel_cls: type["Skeleton"],
42+
*,
43+
accept_ref_skel: bool = True,
44+
) -> bool:
45+
"""
46+
Checks whether an object is an SkeletonInstance that belongs to a specific Skeleton class.
47+
48+
:param obj: The object to check.
49+
:param skel_cls: The skeleton class that will be checked against ``obj``.
50+
:param accept_ref_skel: If True, ``obj`` can also be just a RefSkelFor``skel_cls``.
51+
If False, no ``RefSkel`` is accepted.
52+
"""
53+
from . import RefSkel, Skeleton, SkeletonInstance
54+
55+
if not issubclass(skel_cls, Skeleton):
56+
raise TypeError(f"{skel_cls=} is not a Skeleton.")
57+
58+
if not isinstance(obj, SkeletonInstance):
59+
return False
60+
if issubclass(obj.skeletonCls, skel_cls):
61+
return True
62+
return False
63+
3664
# TODO: Use decimal package instead of floats?
3765
# -> decimal mode in NumericBone?
3866

@@ -72,8 +100,6 @@ def __init__(self, src_object: SkeletonInstance):
72100
# logger.debug(f"Creating new price object based on {src_object=}")
73101
shop = SHOP_INSTANCE.get()
74102
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)):
77103
self.is_in_cart = True
78104
self.cart_leaf = src_object
79105
self.article_skel = toolkit.without_render_preparation(src_object.article_skel_full)
@@ -84,13 +110,10 @@ def __init__(self, src_object: SkeletonInstance):
84110
self.cart_discounts = []
85111
self.cart_discounts = [toolkit.get_full_skel_from_ref_skel(d) for d in self.cart_discounts]
86112
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)):
89113
self.is_in_cart = False
90114
self.article_skel = toolkit.without_render_preparation(src_object)
91115
else:
92116
logger.error(f"Unsupported type {type(src_object)=} | {src_object.skeletonCls=}")
93-
logger.error(f"Unsupported type {type(src_object)=} | {type(src_object.skeletonCls)=}")
94117
raise TypeError(f"Unsupported type {type(src_object)}")
95118

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

0 commit comments

Comments
 (0)