2017-04-03 20:32:16 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import django.db.models.deletion
|
2018-10-06 12:35:49 +02:00
|
|
|
from django.db import migrations, models
|
2017-04-03 20:32:16 +02:00
|
|
|
|
|
|
|
from kfet.forms import KFetConfigForm
|
|
|
|
|
|
|
|
|
|
|
|
def adapt_settings(apps, schema_editor):
|
2018-10-06 12:35:49 +02:00
|
|
|
Settings = apps.get_model("kfet", "Settings")
|
2017-04-03 20:32:16 +02:00
|
|
|
db_alias = schema_editor.connection.alias
|
|
|
|
obj = Settings.objects.using(db_alias)
|
|
|
|
|
|
|
|
cfg = {}
|
|
|
|
|
|
|
|
def try_get(new, old, type_field):
|
|
|
|
try:
|
|
|
|
value = getattr(obj.get(name=old), type_field)
|
|
|
|
cfg[new] = value
|
|
|
|
except Settings.DoesNotExist:
|
|
|
|
pass
|
|
|
|
|
2017-04-10 11:36:06 +02:00
|
|
|
try:
|
2018-10-06 12:35:49 +02:00
|
|
|
subvention = obj.get(name="SUBVENTION_COF").value_decimal
|
|
|
|
subvention_mult = 1 + subvention / 100
|
|
|
|
reduction = (1 - 1 / subvention_mult) * 100
|
|
|
|
cfg["kfet_reduction_cof"] = reduction
|
2017-04-10 11:36:06 +02:00
|
|
|
except Settings.DoesNotExist:
|
|
|
|
pass
|
2018-10-06 12:35:49 +02:00
|
|
|
try_get("kfet_addcost_amount", "ADDCOST_AMOUNT", "value_decimal")
|
|
|
|
try_get("kfet_addcost_for", "ADDCOST_FOR", "value_account")
|
|
|
|
try_get("kfet_overdraft_duration", "OVERDRAFT_DURATION", "value_duration")
|
|
|
|
try_get("kfet_overdraft_amount", "OVERDRAFT_AMOUNT", "value_decimal")
|
|
|
|
try_get("kfet_cancel_duration", "CANCEL_DURATION", "value_duration")
|
2017-04-03 20:32:16 +02:00
|
|
|
|
|
|
|
cfg_form = KFetConfigForm(initial=cfg)
|
|
|
|
if cfg_form.is_valid():
|
|
|
|
cfg_form.save()
|
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
dependencies = [("kfet", "0053_created_at"), ("djconfig", "0001_initial")]
|
2017-04-03 20:32:16 +02:00
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.RunPython(adapt_settings),
|
2018-10-06 12:35:49 +02:00
|
|
|
migrations.RemoveField(model_name="settings", name="value_account"),
|
|
|
|
migrations.DeleteModel(name="Settings"),
|
2017-04-03 20:32:16 +02:00
|
|
|
]
|