Repository: fossasia/open-event-server

Issue:
Fees should include country
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->

Fees are currently dependent on the currency only. This is not correct as the country is responsible for such fees. Therefore, the fees should be calculated using the country of the event and the payment currency in combination



Discussion:

Resolving patch:
diff --git a/app/models/event.py b/app/models/event.py
--- a/app/models/event.py
+++ b/app/models/event.py
@@ -273,10 +273,8 @@ def __setattr__(self, name, value):
     def fee(self):
         """
         Returns the fee as a percentage from 0 to 100 for this event
-
-        Is retrieved from the db using the `payment_currency`
         """
-        return get_fee(self.payment_currency)
+        return get_fee(self.payment_country, self.payment_currency)
 
     def notification_settings(self, user_id):
         try:
diff --git a/app/models/ticket_fee.py b/app/models/ticket_fee.py
--- a/app/models/ticket_fee.py
+++ b/app/models/ticket_fee.py
@@ -1,33 +1,41 @@
-from app.models import db
 from sqlalchemy import desc
 
+from app.models import db
+
 DEFAULT_FEE = 0.0
 
 
 class TicketFees(db.Model):
-    "Persists service and maximum fees for a currency"
+    "Persists service and maximum fees for a currency in a country"
     __tablename__ = 'ticket_fees'
 
     id = db.Column(db.Integer, primary_key=True)
     currency = db.Column(db.String)
+    country = db.Column(db.String)
     service_fee = db.Column(db.Float)
     maximum_fee = db.Column(db.Float)
 
-    def __init__(self, currency=None, service_fee=None, maximum_fee=None):
+    def __init__(self,
+                 country=None,
+                 currency=None,
+                 service_fee=None,
+                 maximum_fee=None):
+        self.country = country
         self.currency = currency
         self.service_fee = service_fee
         self.maximum_fee = maximum_fee
 
     def __repr__(self):
-        return '<Ticket Fee {}>'.format(self.service_fee)
+        return '<Ticket Fee {} {}>'.format(self.country, self.service_fee)
 
     def __str__(self):
         return self.__repr__()
 
 
-def get_fee(currency):
-    "Returns the fee for a given currency string"
+def get_fee(country, currency):
+    "Returns the fee for a given country and currency string"
     fee = db.session.query(TicketFees) \
+                    .filter(TicketFees.country == country) \
                     .filter(TicketFees.currency == currency) \
                     .order_by(desc(TicketFees.id)).first()
 
diff --git a/migrations/versions/3a01b7d9d55e_.py b/migrations/versions/3a01b7d9d55e_.py
new file mode 100644
--- /dev/null
+++ b/migrations/versions/3a01b7d9d55e_.py
@@ -0,0 +1,28 @@
+"""empty message
+
+Revision ID: 3a01b7d9d55e
+Revises: 163f9fc56815
+Create Date: 2018-07-08 21:00:30.438784
+
+"""
+
+from alembic import op
+import sqlalchemy as sa
+import sqlalchemy_utils
+
+
+# revision identifiers, used by Alembic.
+revision = '3a01b7d9d55e'
+down_revision = '163f9fc56815'
+
+
+def upgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.add_column('ticket_fees', sa.Column('country', sa.String(), nullable=True))
+    # ### end Alembic commands ###
+
+
+def downgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.drop_column('ticket_fees', 'country')
+    # ### end Alembic commands ###


Test patch: