Browse Source

member col for member_type, fee

No known key found for this signature in database

+ 31
- 0
SqliteDecimal.py View File

@@ -0,0 +1,31 @@
1
+#!/usr/bin/python
2
+
3
+# the "correct" place for this would be alembic/
4
+# but alembic can't be a package because namespace collision,
5
+# so please leave this here for the time being :/
6
+
7
+import sqlalchemy.types as types
8
+
9
+class SqliteDecimal(types.TypeDecorator):
10
+    """
11
+    Type decorator for persisting Decimal (currency values)
12
+
13
+    TODO: Use standard SQLAlchemy Decimal
14
+    when a database is used which supports it.
15
+    """
16
+    impl = types.String
17
+
18
+    def load_dialect_impl(self, dialect):
19
+        return dialect.type_descriptor(types.VARCHAR(100))
20
+
21
+    def process_bind_param(self, value, dialect):
22
+        if value is not None:
23
+            return str(value)
24
+        else:
25
+            return None
26
+
27
+    def process_result_value(self, value, dialect):
28
+        if value is not None and value != '':
29
+            return Decimal(value)
30
+        else:
31
+            return None

+ 33
- 0
alembic/versions/cbcea62674f1_member_type_fee_cols.py View File

@@ -0,0 +1,33 @@
1
+"""member type+fee cols
2
+
3
+Revision ID: cbcea62674f1
4
+Revises: 2fbe1bde5df8
5
+Create Date: 2018-04-23 22:57:58.020018
6
+
7
+"""
8
+
9
+# revision identifiers, used by Alembic.
10
+revision = 'cbcea62674f1'
11
+down_revision = '2fbe1bde5df8'
12
+
13
+from alembic import op
14
+import sqlalchemy as sa
15
+from SqliteDecimal import SqliteDecimal
16
+
17
+
18
+def upgrade():
19
+    # ### commands auto generated by Alembic - please adjust! ###
20
+    with op.batch_alter_table('members', schema=None) as batch_op:
21
+        batch_op.add_column(sa.Column('fee', SqliteDecimal(length=12, collation=2), nullable=True))
22
+        batch_op.add_column(sa.Column('member_type', sa.Unicode(length=255), nullable=True))
23
+
24
+    # ### end Alembic commands ###
25
+
26
+
27
+def downgrade():
28
+    # ### commands auto generated by Alembic - please adjust! ###
29
+    with op.batch_alter_table('members', schema=None) as batch_op:
30
+        batch_op.drop_column('member_type')
31
+        batch_op.drop_column('fee')
32
+
33
+    # ### end Alembic commands ###

+ 11
- 2
c3smembership/models.py View File

@@ -334,6 +334,7 @@ class Shares(Base):
334 334
     """A free text comment for accounting purposes."""
335 335
 
336 336
 
337
+
337 338
 # table for relation between membership and shares
338 339
 members_shares = Table(
339 340
     'members_shares', Base.metadata,
@@ -669,7 +670,13 @@ class C3sMember(Base):
669 670
         DatabaseDecimal(12, 2), default=Decimal('0'))
670 671
     dues17_paid_date = Column(DateTime())  # paid when?
671 672
 
673
+    member_type = Column(Unicode(255))
674
+    """type of the member, like individual, commercial entity"""
675
+    fee = Column(DatabaseDecimal(12, 2), default=Decimal('NaN'))
676
+    """membership fee"""
677
+
672 678
     def __init__(self, **kwargs):
679
+        print(kwargs)
673 680
         self.firstname = kwargs.pop('firstname')
674 681
         self.lastname = kwargs.pop('lastname')
675 682
         self.email = kwargs.pop('email')
@@ -703,13 +710,15 @@ class C3sMember(Base):
703 710
         else:
704 711
             self.membership_type = kwargs.pop('membership_type')
705 712
 
706
-        if len(membership_fees)>1:
713
+        if len(customization.membership_fees)>1:
707 714
             self.fee = kwargs.pop('fee')
708
-            self.member_type = kwargs.pop('membership_type')
715
+            self.member_type = kwargs.pop('member_type')
709 716
 
710 717
         if len(kwargs)!=0:
711 718
             raise TypeError('__init__ did not consume all arguments')
712 719
 
720
+
721
+
713 722
     def _get_password(self):
714 723
         return self._password
715 724
 

+ 4
- 4
c3smembership/views/afm.py View File

@@ -447,12 +447,12 @@ def join_c3s(request):
447 447
                 appstruct['membership_info']['member_of_colsoc'] == u'yes'),
448 448
             coopMemberArgs['name_of_colsoc']=appstruct['membership_info']['name_of_colsoc']
449 449
 
450
-        if customization.membership_types and len(customization.membership_types) > 1:
451
-            coopMemberArgs['membership_type']=appstruct['membership_info']['membership_type']
452
-            if coopMemberArgs['membership_type'] == 'sustaining':
450
+        if customization.membership_fees and len(customization.membership_fees) > 1:
451
+            coopMemberArgs['member_type']=appstruct['fees']['member_type']
452
+            if coopMemberArgs['member_type'] == 'sustaining':
453 453
                 coopMemberArgs['fee'] = appstruct['fees']['member_custom_fee']
454 454
             else:
455
-                appstruct['fees']['fee'] = [ v for v,t,d in customization.membership_fees if t == appstruct['fees']['member_type'] ][0]
455
+                coopMemberArgs['fee'] = [ v for v,t,d in customization.membership_fees if t == appstruct['fees']['member_type'] ][0]
456 456
 
457 457
 
458 458
         member = C3sMember(**coopMemberArgs)

Loading…
Cancel
Save