-
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: Implementation of event invoice generation & calculation #6121
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import datetime | ||
|
||
from app.models.event_invoice import EventInvoice | ||
|
||
|
||
def fetch_event_invoices(invoice_status): | ||
""" | ||
Helper function to fetch event invoices based on status | ||
""" | ||
|
||
if invoice_status == 'due': | ||
event_invoices = EventInvoice.query.filter(EventInvoice.created_at + datetime.timedelta(days=30) <= | ||
datetime.datetime.now(), | ||
EventInvoice.paid_via is None).all() | ||
elif invoice_status == 'paid': | ||
event_invoices = EventInvoice.query.filter(EventInvoice.paid_via is not None).all() | ||
elif invoice_status == 'upcoming': | ||
event_invoices = EventInvoice.query.filter(EventInvoice.created_at + datetime.timedelta(days=30) > | ||
datetime.datetime.now(), | ||
EventInvoice.paid_via is None).all() | ||
return event_invoices |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import pytz | ||
from dateutil.relativedelta import relativedelta | ||
from flask import render_template | ||
|
||
from app.api.helpers.db import safe_query, save_to_db | ||
from app.api.helpers.mail import send_email_after_event, send_email_for_monthly_fee_payment, \ | ||
|
@@ -10,14 +11,17 @@ | |
send_notif_after_event | ||
from app.api.helpers.query import get_upcoming_events, get_user_event_roles_by_role_name | ||
from app.api.helpers.utilities import monthdelta | ||
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.event import Event | ||
from app.models.event_invoice import EventInvoice | ||
from app.models.order import Order | ||
from app.models.speaker import Speaker | ||
from app.models.session import Session | ||
from app.models.ticket import Ticket | ||
from app.models.ticket_fee import get_fee | ||
from app.models.ticket_fee import TicketFees, get_fee | ||
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. redefinition of unused 'TicketFees' from line 22 |
||
|
||
from app.settings import get_settings | ||
|
||
|
||
|
@@ -154,3 +158,30 @@ def expire_pending_tickets(): | |
(Order.created_at + datetime.timedelta(minutes=30)) <= datetime.datetime.now()).\ | ||
update({'status': 'expired'}) | ||
db.session.commit() | ||
|
||
|
||
def send_monthly_event_invoice(): | ||
from app import current_app as app | ||
with app.app_context(): | ||
events = Event.query.all() | ||
for event in events: | ||
# calculate net & gross revenues | ||
currency = event.payment_currency | ||
ticket_fee_object = db.session.query(TicketFees).filter_by(currency=currency).one() | ||
ticket_fee_percentage = ticket_fee_object.service_fee | ||
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. local variable 'ticket_fee_percentage' is assigned to but never used |
||
ticket_fee_maximum = ticket_fee_object.maximum_fee | ||
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. local variable 'ticket_fee_maximum' is assigned to but never used |
||
orders = Order.query.filter_by(event=event).all() | ||
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. local variable 'orders' is assigned to but never used |
||
gross_revenue = event.calc_monthly_revenue() | ||
ticket_fees = event.tickets_sold * ticket_fee_percentage | ||
if ticket_fees > ticket_fee_maximum: | ||
ticket_fees = ticket_fee_maximum | ||
net_revenue = gross_revenue - ticket_fees | ||
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. local variable 'net_revenue' is assigned to but never used |
||
# save invoice as pdf | ||
pdf = create_save_pdf(render_template('pdf/event_invoice.html', orders=orders, | ||
ticket_fee_object=ticket_fee_object, gross_revenue=gross_revenue, | ||
net_revenue=net_revenue), UPLOAD_PATHS['pdf']['event_invoice'], | ||
dir_path='/static/uploads/pdf/event_invoices/', identifier=event.identifier) | ||
# save event_invoice info to DB | ||
|
||
event_invoice = EventInvoice(amount=net_revenue, invoice_pdf_url=pdf, event_id=event.id) | ||
save_to_db(event_invoice) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,8 @@ | |
'pdf': { | ||
'ticket_attendee': 'attendees/tickets/pdf/{identifier}', | ||
'order': 'orders/invoices/pdf/{identifier}', | ||
'tickets_all': 'orders/tickets/pdf/{identifier}' | ||
'tickets_all': 'orders/tickets/pdf/{identifier}', | ||
'event_invoice': 'events/organizer/invoices/pdf/{identifier}' | ||
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. SyntaxError: invalid syntax |
||
} | ||
} | ||
|
||
|
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.
redefinition of unused 'TicketFees' from line 19