add new database fields and migrate the data
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
# Generated by Django 3.2 on 2021-05-11 05:03
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
def separate_fees(apps, schema_editor):
|
||||
|
||||
Person = apps.get_model('transactions', 'Transaction')
|
||||
for tr in Transaction.objects.all():
|
||||
if tr.amount_before_fee > 0:
|
||||
tr.crypto_fee = tr.amount_before_fee - tr.amount_after_fee
|
||||
tr.crypto_amount = tr.amount_before_fee
|
||||
tr.transaction_type = 'B'
|
||||
elif tr.amount_before_fee < 0:
|
||||
tr.crypto_fee = -1 * tr.amount_before_fee + tr.amount_after_fee
|
||||
tr.crypto_amount = -1 * tr.amount_before_fee
|
||||
tr.transaction_type = 'S'
|
||||
else:
|
||||
tr.crypto_fee = 0
|
||||
tr.crypto_amount = 0
|
||||
tr.transaction_type = 'T'
|
||||
|
||||
tr.fiat_amount = tr.amount
|
||||
tr.fiat_fee = 0
|
||||
|
||||
tr.save()
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('transactions', '0003_auto_20210511_0703'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(separate_fees),
|
||||
]
|
||||
Reference in New Issue
Block a user