Skip to content

Commit

Permalink
feat: Addition and Updation of billing related fields (fossasia#6447)
Browse files Browse the repository at this point in the history
  • Loading branch information
kushthedude authored and codedsun committed Dec 22, 2019
1 parent 5eb5398 commit 2ddaae7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
6 changes: 2 additions & 4 deletions app/api/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def is_payment_valid(order, mode):
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")
"Billing information is mandatory for this order")
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')):
raise UnprocessableEntity({'pointer': '/data/attributes/is_billing_enabled'},
Expand Down Expand Up @@ -111,8 +111,6 @@ def before_create_object(self, data, view_kwargs):
:param view_kwargs:
:return:
"""
if data.get('amount') > 0 and not data.get('is_billing_enabled'):
data['is_billing_enabled'] = True

free_ticket_quantity = 0

Expand Down Expand Up @@ -319,7 +317,7 @@ def before_update_object(self, order, data, view_kwargs):
:param view_kwargs:
:return:
"""
if data.get('amount') or data.get('is_billing_enabled'):
if data.get('amount') and (data.get('is_billing_enabled') or order.event.is_billing_info_mandatory):
check_billing_info(data)
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 @@ -97,7 +97,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
40 changes: 40 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,40 @@
"""empty message
Revision ID: d1c2b8711223
Revises: 9effd270a6ae
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 = '9effd270a6ae'


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('events', 'is_billing_info_mandatory',
existing_type=sa.BOOLEAN(),
server_default='False',
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 2ddaae7

Please sign in to comment.