Files
2021-05-11 20:58:24 +02:00

38 lines
1.1 KiB
Python

# Generated by Django 3.2 on 2021-05-11 05:03
from django.db import migrations
def separate_fees(apps, schema_editor):
Transaction = 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
if tr.fiat_amount < 0:
tr.fiat_amount = -1 * tr.fiat_amount
tr.fiat_fee = 0
tr.save()
class Migration(migrations.Migration):
dependencies = [
('transactions', '0003_auto_20210511_0703'),
]
operations = [
migrations.RunPython(separate_fees),
]