Skip to content

Commit 9f49d4f

Browse files
committed
fix: Mark disocunt on cart root node as used too
1 parent 3a324c5 commit 9f49d4f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/viur/shop/modules/discount_condition.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import cachetools
77

88
from viur import toolkit
9-
from viur.core import current, db, tasks
9+
from viur.core import db, tasks
1010
from viur.core.prototypes import List
1111
from viur.core.skeleton import SkeletonInstance
1212
from .abstract import ShopModuleAbstract
@@ -15,7 +15,7 @@
1515
from ..types import CodeType, SkeletonInstance_T
1616

1717
if t.TYPE_CHECKING:
18-
from ..skeletons import DiscountConditionSkel
18+
from ..skeletons import DiscountConditionSkel, OrderSkel
1919

2020
logger = SHOP_LOGGER.getChild(__name__)
2121

@@ -180,18 +180,19 @@ def get_by_code(self, code: str = None) -> t.Iterator[SkeletonInstance]:
180180
yield cond_skel
181181

182182
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)
184183
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
185186
for node in nodes:
186-
# logger.debug(f"{node = }")
187+
# logger.debug(f"Collecting discount (if exist) of {node=}")
187188
if node["discount"]:
188189
discounts.append(node["discount"]["dest"]["key"])
189190
# TODO: collect used from price and automatically as well
190191
return discounts
191192

192193
@on_event(Event.ORDER_ORDERED)
193194
@staticmethod
194-
def mark_discount_used(order_skel, payment):
195+
def mark_discount_used(order_skel: SkeletonInstance_T["OrderSkel"], payment, *args, **kwargs) -> None:
195196
"""Increase quantity_used on discount of an ordered cart"""
196197
logger.info(f"Calling mark_discount_used with {order_skel=} {payment=}")
197198
self = SHOP_INSTANCE.get().discount_condition

0 commit comments

Comments
 (0)