Repository: fossasia/open-event-server

Issue:
Add Foreign keys to Invoice model
**Is your feature request related to a problem? Please describe.**
Currently, Event Invoice does not link to an order. This should be linked as it would  help in the integration of invoice payments with the order workflow


**Additional context**
Working on it.


Discussion:
Issue-Label Bot is automatically applying the label `feature` to this issue, with a confidence of 0.93. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback! 

 Links: [app homepage](https://github.com/marketplace/issue-label-bot), [dashboard](https://mlbot.net/data/fossasia/open-event-server) and [code](https://github.com/hamelsmu/MLapp) for this bot.

Resolving patch:
diff --git a/app/api/schema/orders.py b/app/api/schema/orders.py
--- a/app/api/schema/orders.py
+++ b/app/api/schema/orders.py
@@ -78,6 +78,8 @@ def initial_values(self, data):
     cancel_note = fields.Str(allow_none=True)
     order_notes = fields.Str(allow_none=True)
     tickets_pdf_url = fields.Url(dump_only=True)
+    is_event_invoice = fields.Bool(allow_none=False)
+    invoice_pdf_url = fields.Url(dump_only=True)
 
     # only used in the case of an on site attendee.
     on_site_tickets = fields.List(cls_or_instance=fields.Nested(OnSiteTicketSchema), load_only=True, allow_none=True)
diff --git a/app/models/order.py b/app/models/order.py
--- a/app/models/order.py
+++ b/app/models/order.py
@@ -66,6 +66,8 @@ class Order(SoftDeletionModel):
     cancel_note = db.Column(db.String, nullable=True)
     order_notes = db.Column(db.String)
     tickets_pdf_url = db.Column(db.String)
+    is_event_invoice = db.Column(db.Boolean)
+    invoice_pdf_url = db.Column(db.String)
 
     discount_code_id = db.Column(
         db.Integer, db.ForeignKey('discount_codes.id', ondelete='SET NULL'), nullable=True, default=None)
@@ -97,7 +99,9 @@ def __init__(self,
                  payment_mode=None,
                  deleted_at=None,
                  order_notes=None,
-                 tickets_pdf_url=None):
+                 tickets_pdf_url=None,
+                 invoice_pdf_url=None,
+                 is_event_invoice=False):
         self.identifier = get_new_order_identifier()
         self.quantity = quantity
         self.amount = amount
@@ -120,6 +124,9 @@ def __init__(self,
         self.deleted_at = deleted_at
         self.order_notes = order_notes
         self.tickets_pdf_url = tickets_pdf_url
+        self.is_event_invoice = is_event_invoice
+        self.invoice_pdf_url = invoice_pdf_url
+
 
     def __repr__(self):
         return '<Order %r>' % self.id
diff --git a/migrations/versions/5b5cec07a402_.py b/migrations/versions/5b5cec07a402_.py
new file mode 100644
--- /dev/null
+++ b/migrations/versions/5b5cec07a402_.py
@@ -0,0 +1,30 @@
+"""empty message
+
+Revision ID: 5b5cec07a402
+Revises: ba651e8ce9a3
+Create Date: 2019-07-16 10:07:05.795451
+
+"""
+
+from alembic import op
+import sqlalchemy as sa
+import sqlalchemy_utils
+
+
+# revision identifiers, used by Alembic.
+revision = '5b5cec07a402'
+down_revision = 'ba651e8ce9a3'
+
+
+def upgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.add_column('orders', sa.Column('invoice_pdf_url', sa.String(), nullable=True))
+    op.add_column('orders', sa.Column('is_event_invoice', sa.Boolean(), server_default='false', nullable=False))
+    # ### end Alembic commands ###
+
+
+def downgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.drop_column('orders', 'is_event_invoice')
+    op.drop_column('orders', 'invoice_pdf_url')
+    # ### end Alembic commands ###


Test patch: