Skip to content

Commit

Permalink
[CHG] shopinvader_api_sale_loyalty: cart_router: rename path param ca…
Browse files Browse the repository at this point in the history
…rt_uuid -> uuid
  • Loading branch information
marielejeune committed Jan 18, 2024
1 parent 8d6fc1e commit 7ca5781
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions shopinvader_api_sale_loyalty/routers/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@


@cart_router.post("/apply_coupon", deprecated=True)
@cart_router.post("/apply_coupon/{cart_uuid}", deprecated=True)
@cart_router.post("/apply_coupon/{uuid}", deprecated=True)
@cart_router.post("/coupon")
@cart_router.post("/{cart_uuid}/coupon")
@cart_router.post("/{uuid}/coupon")
def apply_coupon(
data: LoyaltyCardInput,
env: Annotated[api.Environment, Depends(authenticated_partner_env)],
partner: Annotated[ResPartner, Depends(authenticated_partner)],
cart_uuid: UUID | None = None,
uuid: UUID | None = None,
) -> Sale | None:
"""
Apply a coupon on a specific cart.
Expand All @@ -38,33 +38,29 @@ def apply_coupon(
If some info is missing to uniquely determine which reward to apply,
raise an error.
"""
cart = env["sale.order"]._find_open_cart(
partner.id, str(cart_uuid) if cart_uuid else None
)
cart = env["sale.order"]._find_open_cart(partner.id, str(uuid) if uuid else None)
if cart:
env["shopinvader_api_cart.cart_router.helper"]._apply_coupon(cart, data)
return Sale.from_sale_order(cart) if cart else None


@cart_router.post("/apply_reward", deprecated=True)
@cart_router.post("/apply_reward/{cart_uuid}", deprecated=True)
@cart_router.post("/apply_reward/{uuid}", deprecated=True)
@cart_router.post("/reward")
@cart_router.post("/{cart_uuid}/reward")
@cart_router.post("/{uuid}/reward")
def apply_reward(
data: LoyaltyRewardInput,
env: Annotated[api.Environment, Depends(authenticated_partner_env)],
partner: Annotated[ResPartner, Depends(authenticated_partner)],
cart_uuid: UUID | None = None,
uuid: UUID | None = None,
) -> Sale | None:
"""
Apply claimable rewards on a specific cart.
One can specify in LoyaltyReardInput which free product to choose.
If this piece of info is needed and missing, raise an error.
"""
cart = env["sale.order"]._find_open_cart(
partner.id, str(cart_uuid) if cart_uuid else None
)
cart = env["sale.order"]._find_open_cart(partner.id, str(uuid) if uuid else None)
if cart:
env["shopinvader_api_cart.cart_router.helper"]._apply_reward(cart, data)
return Sale.from_sale_order(cart) if cart else None
Expand Down

0 comments on commit 7ca5781

Please sign in to comment.