Repository: fossasia/open-event-server

Issue:
Handle the maxQuantity being negative
**Describe the bug**

Presently maxQuantity for discount codes is 100000.
Handle the maxQuantity being negative, i.e. -1
If it is negative, server should not limit the discount code count.



Discussion:
@daretobedifferent18 i would like to work on this issue 
you mean that if -1 is the quantity it should not limit the discount count but now it is limiting

> @daretobedifferent18 i would like to work on this issue
> you mean that if -1 is the quantity it should not limit the discount count but now it is limiting

Pls refer [fossaisa/open-event-frontend](https://github.com/fossasia/open-event-frontend/pull/5758)
I want to work on this issue, Could you please assign me 
We don't assign external contributors, please send a PR
Hello @iamareebjamal I have made one pull request. Could you please review it. Please correct me / suggest me if I am wrong 

Resolving patch:
diff --git a/app/api/helpers/ticketing.py b/app/api/helpers/ticketing.py
--- a/app/api/helpers/ticketing.py
+++ b/app/api/helpers/ticketing.py
@@ -167,9 +167,12 @@ def is_discount_available(discount_code, tickets=None, ticket_holders=None):
         for ticket in tickets:
             if int(ticket['id']) in ticket_ids:
                 qty += ticket.get('quantity', 1)
+
+    max_quantity = qty if discount_code.max_quantity < 0 else discount_code.max_quantity
+
     available = (
         (qty + old_holders) <= discount_code.tickets_number
-        and discount_code.min_quantity <= qty <= discount_code.max_quantity
+        and discount_code.min_quantity <= qty <= max_quantity
     )
     if not available:
         logger.warning(
diff --git a/app/api/schema/discount_codes.py b/app/api/schema/discount_codes.py
--- a/app/api/schema/discount_codes.py
+++ b/app/api/schema/discount_codes.py
@@ -33,7 +33,7 @@ class Meta:
     is_active = fields.Boolean()
     tickets_number = fields.Integer(validate=lambda n: n >= 0, allow_none=True)
     min_quantity = fields.Integer(validate=lambda n: n >= 0, allow_none=True)
-    max_quantity = fields.Integer(validate=lambda n: n >= 0, allow_none=True)
+    max_quantity = fields.Integer(allow_none=True)
     valid_from = fields.DateTime(allow_none=True)
     valid_till = fields.DateTime(allow_none=True)
     used_for = fields.Str(
@@ -94,7 +94,10 @@ def validate_quantity(self, data, original_data):
         DiscountCodeSchemaEvent.quantity_validation_helper(data)
 
         if data.get('tickets_number') and data.get('max_quantity'):
-            if data['tickets_number'] < data['max_quantity']:
+            if (
+                data['max_quantity'] >= 0
+                and data['tickets_number'] < data['max_quantity']
+            ):
                 raise UnprocessableEntityError(
                     {'pointer': '/data/attributes/tickets-number'},
                     "tickets-number should be greater than max-quantity",
@@ -166,7 +169,10 @@ def validate_quantity(self, data, original_data):
         DiscountCodeSchemaTicket.quantity_validation_helper(data)
 
         if data.get('tickets_number') and data.get('max_quantity'):
-            if data['tickets_number'] < data['max_quantity']:
+            if (
+                data['max_quantity'] >= 0
+                and data['tickets_number'] < data['max_quantity']
+            ):
                 raise UnprocessableEntityError(
                     {'pointer': '/data/attributes/tickets-number'},
                     "tickets-number should be greater than max-quantity",


Test patch: