Пример #1
0
    def is_voucher_exhausted_for_this_user(self, user_id, voucher_id, order_id, db=None):
        if not db:
            db = CouponsAlchemyDB()
        session_id = request.headers.get('X-ASKME-SESSIONID', None)
        user_uuid = request.headers.get('X-ASKME-USERID', None)
        if session_id:
            is_logged_in, phone_no = fetch_phone_no_from_session_id(session_id)
        elif user_uuid:
            is_logged_in, phone_no = fetch_phone_no(user_uuid)
        else:
            is_logged_in, phone_no = fetch_phone_no(user_id)

        if not phone_no:
            return True

        if u'{}'.format(request.url_rule) == u'/vouchers/grocery/v1/apply':
            if not is_logged_in:
                return True
        else:
            # check api case
            pass

        setattr(request, 'phone_no', phone_no)
        total_per_user_allowed_uses = self.usage['no_of_uses_allowed_per_user']
        count = db.count("voucher_use_tracker", **{'voucher_id': voucher_id, 'user_id': phone_no, 'not_args': {'order_id': order_id}})
        if count >= total_per_user_allowed_uses:
            return True
        return False
Пример #2
0
 def is_voucher_exhausted(self, voucher_id, db=None):
     if not db:
         db = CouponsAlchemyDB()
     total_allowed_uses = self.usage['no_of_total_uses_allowed']
     count = db.count("voucher_use_tracker", **{'voucher_id': voucher_id})
     if count >= total_allowed_uses:
         return True
     return False