Skip to content

Commit

Permalink
enh: Addition of billing info related fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kushthedude committed Sep 15, 2019
1 parent 0426221 commit fcf6de4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
11 changes: 4 additions & 7 deletions app/api/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,9 @@ def is_payment_valid(order, mode):
return (order.paid_via == 'paypal') and order.transaction_id


def check_billing_info(data):
if data.get('amount') and data.get('amount') > 0 and not data.get('is_billing_enabled'):
raise UnprocessableEntity({'pointer': '/data/attributes/is_billing_enabled'},
"Billing information is mandatory for paid orders")
if data.get('is_billing_enabled') and not (data.get('company') and data.get('address') and data.get('city') and
data.get('zipcode') and data.get('country')):
def check_billing_info(data, order):
if order.event.is_billing_info_mandatory and data.get('amount') and data.get('amount') > 0 and not (data.get('company')
and data.get('address') and data.get('city') and data.get('zipcode') and data.get('country')):
raise UnprocessableEntity({'pointer': '/data/attributes/is_billing_enabled'},
"Billing information incomplete")

Expand Down Expand Up @@ -320,7 +317,7 @@ def before_update_object(self, order, data, view_kwargs):
:return:
"""
if data.get('amount') or data.get('is_billing_enabled'):
check_billing_info(data)
check_billing_info(data, order)
if (not has_access('is_coorganizer', event_id=order.event_id)) and (not current_user.id == order.user_id):
raise ForbiddenException({'pointer': ''}, "Access Forbidden")

Expand Down
2 changes: 1 addition & 1 deletion app/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Event(SoftDeletionModel):
payment_currency = db.Column(db.String)
paypal_email = db.Column(db.String)
is_tax_enabled = db.Column(db.Boolean, default=False)
is_billing_info_mandatory = db.Column(db.Boolean, default=False)
is_billing_info_mandatory = db.Column(db.Boolean, default=False, nullable=False)
can_pay_by_paypal = db.Column(db.Boolean, default=False, nullable=False)
can_pay_by_stripe = db.Column(db.Boolean, default=False, nullable=False)
can_pay_by_cheque = db.Column(db.Boolean, default=False, nullable=False)
Expand Down
2 changes: 1 addition & 1 deletion app/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Order(SoftDeletionModel):
transaction_id = db.Column(db.String)
paid_via = db.Column(db.String)
payment_mode = db.Column(db.String)
is_billing_enabled = db.Column(db.Boolean)
is_billing_enabled = db.Column(db.Boolean, nullable=False, default=False)
brand = db.Column(db.String)
exp_month = db.Column(db.Integer)
exp_year = db.Column(db.Integer)
Expand Down
39 changes: 39 additions & 0 deletions migrations/versions/rev-2019-09-15-08:29:32-d1c2b8711223_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""empty message
Revision ID: d1c2b8711223
Revises: 7c32ba647a18
Create Date: 2019-09-15 08:29:32.373041
"""

from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils


# revision identifiers, used by Alembic.
revision = 'd1c2b8711223'
down_revision = '7c32ba647a18'


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('events', 'is_billing_info_mandatory',
existing_type=sa.BOOLEAN(),
nullable=False)
op.alter_column('orders', 'is_billing_enabled',
existing_type=sa.BOOLEAN(),
server_default=false
nullable=False)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('orders', 'is_billing_enabled',
existing_type=sa.BOOLEAN(),
nullable=True)
op.alter_column('events', 'is_billing_info_mandatory',
existing_type=sa.BOOLEAN(),
nullable=True)
# ### end Alembic commands ###

0 comments on commit fcf6de4

Please sign in to comment.