Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update scheduler time constraint for pending tickets #5926

Merged
merged 4 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions app/api/helpers/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def delete_related_attendees_for_order(order):

def set_expiry_for_order(order, override=False):
"""
Expire the order after the time slot(10 minutes) if the order is pending.
Expire the order after the time slot(10 minutes) if the order is initializing.
Also expires the order if we want to expire an order regardless of the state and time.
:param order: Order to be expired.
:param override: flag to force expiry.
:return:
"""
if order and not order.paid_via and (override or (order.status == 'pending' and (
if order and not order.paid_via and (override or (order.status == 'initializing' and (
order.created_at +
timedelta(minutes=order.event.order_expiry_time)) < datetime.now(timezone.utc))):
order.status = 'expired'
Expand Down
2 changes: 1 addition & 1 deletion app/api/helpers/scheduled_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,6 @@ def expire_pending_tickets_after_one_day():
from app import current_app as app
with app.app_context():
db.session.query(Order).filter(Order.status == 'pending',
(datetime.datetime.today() - Order.created_at).days > 1).\
(datetime.datetime.today() - Order.created_at).days > 3).\
update({'status': 'expired'})
db.session.commit()
4 changes: 2 additions & 2 deletions app/api/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def after_create_object(self, order, data, view_kwargs):
# TicketingManager.calculate_update_amount(order)

# send e-mail and notifications if the order status is completed
if order.status == 'completed':
if order.status == 'completed' or order.status == 'placed':
Copy link
Contributor

@abhinavk96 abhinavk96 May 19, 2019

Choose a reason for hiding this comment

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

@shreyanshdwivedi Your logic on FE and here don't agree, over there, after setting the status of order as placed, you are asking for user to fill payment details, where as this would actually send the tickets to him.
https://github.com/fossasia/open-event-frontend/pull/2955/files#r285388216

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll be updating front-end logic and display a different success message.

# fetch tickets attachment
order_identifier = order.identifier

Expand Down Expand Up @@ -322,7 +322,7 @@ def after_update_object(self, order, data, view_kwargs):
# delete the attendees so that the tickets are unlocked.
delete_related_attendees_for_order(order)

elif order.status == 'completed':
elif order.status == 'completed' or order.status == 'placed':

# Send email to attendees with invoices and tickets attached
order_identifier = order.identifier
Expand Down
5 changes: 4 additions & 1 deletion app/api/schema/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ def initial_values(self, data):
exp_month = fields.Str(dump_only=True)
exp_year = fields.Str(dump_only=True)
last4 = fields.Str(dump_only=True)
status = fields.Str(validate=validate.OneOf(choices=["pending", "cancelled", "completed", "placed", "expired"]))
status = fields.Str(
validate=validate.OneOf(
choices=["initializing", "pending", "cancelled", "completed", "placed", "expired"]
))
discount_code_id = fields.Str(allow_none=True)
payment_url = fields.Str(dump_only=True)
cancel_note = fields.Str(allow_none=True)
Expand Down
2 changes: 1 addition & 1 deletion app/factories/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ class Meta:
event = factory.RelatedFactory(EventFactoryBasic)
event_id = 1
payment_mode = 'free'
status = 'pending'
status = 'initializing'
2 changes: 1 addition & 1 deletion tests/all/integration/api/helpers/test_csv_jobs_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_export_orders_csv(self):
test_order = OrderFactory()
test_order.amount = 2
field_data = export_orders_csv([test_order])
self.assertEqual(field_data[1][2], 'pending')
self.assertEqual(field_data[1][2], 'initializing')
self.assertEqual(field_data[1][4], '2')

def test_export_attendees_csv(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/all/integration/api/helpers/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_should_not_expire_valid_orders(self):
event = EventFactoryBasic()
obj.event = event
set_expiry_for_order(obj)
self.assertEqual(obj.status, 'pending')
self.assertEqual(obj.status, 'initializing')

def test_should_delete_related_attendees(self):
"""Method to test to delete related attendees of an event"""
Expand Down