コード例 #1
0
ファイル: support.py プロジェクト: nubela/unifide-plop
def _update_coupon(order_obj):
    all_dedits = order_obj.debits
    other_debit = filter(lambda x: x["coll_name"] != coupons.Coupon.coll_name(), all_dedits)
    coupon_debit = filter(lambda x: x["coll_name"] == coupons.Coupon.coll_name(), all_dedits)

    coupon_code = request.form.get("coupon_code")
    remove_coupon = request.form.get("remove_coupon")
    coupon_obj = coupons.get_by_attr(coupon_code)

    if remove_coupon == "true":
        order_obj.debits = other_debit
        coupon_debit = []
    elif coupon_obj is not None:
        coupon_debit = [
            {"obj_id": coupon_obj._id, "coll_name": coupons.Coupon.coll_name(), "amount": coupon_obj.coupon_value}
        ]
        order_obj.debits = other_debit + coupon_debit
    return coupon_debit
コード例 #2
0
ファイル: support.py プロジェクト: nubela/unifide-plop
def apply_coupon(order_obj, coupon_code, remove_coupon=False):
    #sane defaults
    if remove_coupon == "true":
        remove_coupon = True
    elif remove_coupon == "false":
        remove_coupon = False

    all_dedits = order_obj.debits
    other_debit = filter(lambda x: x["coll_name"] != coupons.Coupon.coll_name(), all_dedits)
    coupon_debit = filter(lambda x: x["coll_name"] == coupons.Coupon.coll_name(), all_dedits)

    coupon_obj = coupons.get_by_attr(coupon_code)

    if remove_coupon:
        order_obj.debits = other_debit
        coupon_debit = []
    elif coupon_obj is not None:
        coupon_debit = [{
                            "obj_id": coupon_obj._id,
                            "coll_name": coupons.Coupon.coll_name(),
                            "amount": coupon_obj.coupon_value,
                        }]
        order_obj.debits = other_debit + coupon_debit
    return coupon_debit