-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat: Single endpoint for creating creating an order #6635
Changes from 14 commits
a20ac00
748b796
6acd3d3
b984817
a18ad86
6174428
a2652e1
f7f017f
c2daa41
cdaf783
3968527
f791455
09e7cb8
cc220fe
98108a2
5559090
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import logging | ||
from datetime import timedelta, datetime, timezone | ||
|
||
from flask import render_template | ||
from flask import render_template, jsonify | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'flask.jsonify' imported but unused |
||
|
||
from app.settings import get_settings | ||
from app.api.helpers import ticketing | ||
from app.api.helpers.db import save_to_db, safe_query_without_soft_deleted_entries, get_count | ||
from app.api.helpers.db import save_to_db, safe_query_without_soft_deleted_entries, get_count, safe_query | ||
from app.api.helpers.exceptions import UnprocessableEntity, ConflictException | ||
from app.api.helpers.errors import UnprocessableEntityError | ||
from app.api.helpers.files import create_save_pdf | ||
from app.api.helpers.storage import UPLOAD_PATHS | ||
from app.models import db | ||
from app.models.ticket import Ticket | ||
from app.models.discount_code import DiscountCode | ||
from app.models.ticket_fee import TicketFees | ||
from app.models.ticket_holder import TicketHolder | ||
from app.models.order import OrderTicket | ||
|
@@ -134,7 +135,16 @@ def create_onsite_attendees_for_order(data): | |
del data['on_site_tickets'] | ||
|
||
|
||
def calculate_order_amount(tickets, discount_code): | ||
def calculate_order_amount(data): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't change the function signature, it was fine. This should take tickets and discount code only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create a wrapper function if you want to |
||
from app.api.helpers.ticketing import TicketingManager | ||
tickets = data['tickets'] | ||
discount_code = None | ||
if 'discount-code' in data: | ||
discount_code_id = data['discount-code'] | ||
discount_code = safe_query(db, DiscountCode, 'id', discount_code_id, 'id') | ||
if not TicketingManager.match_discount_quantity(discount_code, tickets, None): | ||
return UnprocessableEntityError({'source': 'discount-code'}, 'Discount Usage Exceeded').respond() | ||
|
||
event = tax = tax_included = fees = None | ||
total_amount = total_tax = total_discount = 0.0 | ||
ticket_list = [] | ||
|
@@ -214,4 +224,4 @@ def calculate_order_amount(tickets, discount_code): | |
'sub_total': round(sub_total, 2) | ||
}) | ||
return dict(tax_included=tax_included, total_amount=round(total_amount, 2), total_tax=round(total_tax, 2), | ||
total_discount=round(total_discount, 2), tickets=ticket_list) | ||
total_discount=round(total_discount, 2), tickets=ticket_list) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. continuation line over-indented for visual indent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'json' imported but unused