|
6 | 6 | import cachetools |
7 | 7 |
|
8 | 8 | from viur import toolkit |
9 | | -from viur.core import current, db, tasks |
| 9 | +from viur.core import db, tasks |
10 | 10 | from viur.core.prototypes import List |
11 | 11 | from viur.core.skeleton import SkeletonInstance |
12 | 12 | from .abstract import ShopModuleAbstract |
|
15 | 15 | from ..types import CodeType, SkeletonInstance_T |
16 | 16 |
|
17 | 17 | if t.TYPE_CHECKING: |
18 | | - from ..skeletons import DiscountConditionSkel |
| 18 | + from ..skeletons import DiscountConditionSkel, OrderSkel |
19 | 19 |
|
20 | 20 | logger = SHOP_LOGGER.getChild(__name__) |
21 | 21 |
|
@@ -180,18 +180,19 @@ def get_by_code(self, code: str = None) -> t.Iterator[SkeletonInstance]: |
180 | 180 | yield cond_skel |
181 | 181 |
|
182 | 182 | def get_discounts_from_cart(self, cart_key: db.Key) -> list[db.Key]: |
183 | | - nodes = self.shop.cart.viewSkel("node").all().filter("parentrepo =", cart_key).fetch(MAX_FETCH_LIMIT) |
184 | 183 | discounts = [] |
| 184 | + nodes = self.shop.cart.viewSkel("node").all().filter("parentrepo =", cart_key).fetch(MAX_FETCH_LIMIT) |
| 185 | + nodes.append(self.shop.cart.skel(skelType="node").read(cart_key)) # the root node itself |
185 | 186 | for node in nodes: |
186 | | - # logger.debug(f"{node = }") |
| 187 | + # logger.debug(f"Collecting discount (if exist) of {node=}") |
187 | 188 | if node["discount"]: |
188 | 189 | discounts.append(node["discount"]["dest"]["key"]) |
189 | 190 | # TODO: collect used from price and automatically as well |
190 | 191 | return discounts |
191 | 192 |
|
192 | 193 | @on_event(Event.ORDER_ORDERED) |
193 | 194 | @staticmethod |
194 | | - def mark_discount_used(order_skel, payment): |
| 195 | + def mark_discount_used(order_skel: SkeletonInstance_T["OrderSkel"], payment, *args, **kwargs) -> None: |
195 | 196 | """Increase quantity_used on discount of an ordered cart""" |
196 | 197 | logger.info(f"Calling mark_discount_used with {order_skel=} {payment=}") |
197 | 198 | self = SHOP_INSTANCE.get().discount_condition |
|
0 commit comments