Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/api/schema/tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def validate_quantity(self, data):
raise UnprocessableEntity({'pointer': '/data/attributes/quantity'},
"quantity should be greater than or equal to min-order")

if 'min_price' in data and 'max_price' in data and data['type'] == 'donation':
if data['min_price'] > data['max_price']:
raise UnprocessableEntity({'pointer': '/data/attributes/min-price'},
"minimum price should be lesser than or equal to maximum price")

if 'quantity' in data and 'max_order' in data:
if data['quantity'] < data['max_order']:
raise UnprocessableEntity({'pointer': '/data/attributes/quantity'},
Expand All @@ -78,6 +83,8 @@ def validate_discount_code(self, data, original_data):
description = fields.Str(allow_none=True)
type = fields.Str(required=True)
price = fields.Float(validate=lambda n: n >= 0, allow_none=True)
min_price = fields.Float(validate=lambda n: n >= 0)
max_price = fields.Float(validate=lambda n: n >= 0, allow_none=True)
quantity = fields.Integer(validate=lambda n: n >= 0, allow_none=True)
is_description_visible = fields.Boolean(default=False)
position = fields.Integer(allow_none=True)
Expand Down
6 changes: 6 additions & 0 deletions app/models/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Ticket(SoftDeletionModel):
quantity = db.Column(db.Integer)
position = db.Column(db.Integer)
price = db.Column(db.Float)
min_price = db.Column(db.Float, default=0, nullable=False)
max_price = db.Column(db.Float)
is_fee_absorbed = db.Column(db.Boolean)
sales_starts_at = db.Column(db.DateTime(timezone=True), nullable=False)
sales_ends_at = db.Column(db.DateTime(timezone=True), nullable=False)
Expand Down Expand Up @@ -67,6 +69,8 @@ def __init__(self,
price=0,
min_order=1,
max_order=10,
min_price=0,
max_price=0,
is_fee_absorbed=False,
tags=[],
access_codes=[],
Expand All @@ -82,6 +86,8 @@ def __init__(self,
self.is_checkin_restricted = is_checkin_restricted
self.auto_checkin_enabled = auto_checkin_enabled
self.price = price
self.min_price = min_price
self.max_price = max_price
self.sales_starts_at = sales_starts_at
self.sales_ends_at = sales_ends_at
self.is_hidden = is_hidden
Expand Down
30 changes: 30 additions & 0 deletions migrations/versions/43e8c59337ae_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""empty message

Revision ID: 43e8c59337ae
Revises: 232b13d4e86a
Create Date: 2019-06-18 10:13:37.254265

"""

from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils


# revision identifiers, used by Alembic.
revision = '43e8c59337ae'
down_revision = '232b13d4e86a'


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('tickets', sa.Column('max_price', sa.Float(), nullable=True))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here it's nullable false, I don't see any specification in the model file.

op.add_column('tickets', sa.Column('min_price', sa.Float(), server_default=0, nullable=False))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('tickets', 'min_price')
op.drop_column('tickets', 'max_price')
# ### end Alembic commands ###