Add protocoin to Transaction model and editor
This commit is contained in:
@@ -78,6 +78,7 @@ class Transaction(models.Model):
|
||||
paypal_txn_id = models.CharField(max_length=17, blank=True, null=True, unique=True)
|
||||
paypal_txn_type = models.CharField(max_length=64, blank=True, null=True)
|
||||
paypal_payer_id = models.CharField(max_length=13, blank=True, null=True)
|
||||
protocoin = models.DecimalField(max_digits=7, decimal_places=2)
|
||||
|
||||
report_type = models.TextField(blank=True, null=True)
|
||||
report_memo = models.TextField(blank=True, null=True)
|
||||
|
@@ -38,6 +38,7 @@ class TransactionSerializer(serializers.ModelSerializer):
|
||||
'Member',
|
||||
'Clearing',
|
||||
'Cash',
|
||||
'Protocoin',
|
||||
])
|
||||
category = serializers.ChoiceField([
|
||||
'Membership',
|
||||
@@ -49,6 +50,7 @@ class TransactionSerializer(serializers.ModelSerializer):
|
||||
'Garage Sale',
|
||||
'Reimburse',
|
||||
'Other',
|
||||
'Exchange',
|
||||
])
|
||||
member_id = serializers.SerializerMethodField()
|
||||
member_name = serializers.SerializerMethodField()
|
||||
@@ -58,8 +60,10 @@ class TransactionSerializer(serializers.ModelSerializer):
|
||||
'Unmatched Purchase',
|
||||
'User Flagged',
|
||||
], allow_null=True, required=False)
|
||||
number_of_membership_months = serializers.IntegerField(max_value=36, min_value=-36)
|
||||
number_of_membership_months = serializers.IntegerField(max_value=36, min_value=-36, default=0)
|
||||
recorder = serializers.SerializerMethodField()
|
||||
amount = serializers.DecimalField(max_digits=None, decimal_places=2, default=0)
|
||||
protocoin = serializers.DecimalField(max_digits=None, decimal_places=2, default=0)
|
||||
|
||||
class Meta:
|
||||
model = models.Transaction
|
||||
@@ -80,18 +84,26 @@ class TransactionSerializer(serializers.ModelSerializer):
|
||||
member = get_object_or_404(models.Member, id=self.initial_data['member_id'])
|
||||
validated_data['user'] = member.user
|
||||
|
||||
if validated_data['account_type'] != 'Clearing':
|
||||
if validated_data['account_type'] == 'Protocoin' and validated_data['category'] == 'Exchange':
|
||||
raise ValidationError(dict(category='Can\'t purchase Protocoin with Protocoin.'))
|
||||
|
||||
if validated_data['category'] == 'Exchange':
|
||||
if validated_data['amount'] == 0:
|
||||
raise ValidationError(dict(category='Can\'t purchase 0 Protocoin.'))
|
||||
validated_data['protocoin'] = validated_data['amount']
|
||||
|
||||
if validated_data['account_type'] not in ['Clearing', 'Protocoin']:
|
||||
if validated_data['amount'] == 0:
|
||||
raise ValidationError(dict(account_type='Can\'t have a $0.00 {} transaction. Do you want "Membership Adjustment"?'.format(validated_data['account_type'])))
|
||||
|
||||
if validated_data['category'] != 'Reimburse':
|
||||
if validated_data['amount'] < 0:
|
||||
raise ValidationError(dict(category='Can\'t have a negative {} transaction. Do you want "Reimbursement"?'.format(validated_data['category'])))
|
||||
|
||||
if validated_data['account_type'] == 'PayPal':
|
||||
msg = 'Manual PayPal transaction added:\n' + str(validated_data)
|
||||
utils.alert_tanner(msg)
|
||||
|
||||
if validated_data['account_type'] == 'Protocoin':
|
||||
msg = 'Manual Protocoin transaction added:\n' + str(validated_data)
|
||||
utils.alert_tanner(msg)
|
||||
|
||||
if validated_data['account_type'] in ['Interac', 'Dream Pmt', 'Square Pmt', 'PayPal']:
|
||||
if not validated_data.get('reference_number', None):
|
||||
raise ValidationError(dict(reference_number='This field is required.'))
|
||||
|
Reference in New Issue
Block a user