lingo: move eopayment options from backend to regie when scope change (#65141)
This commit is contained in:
parent
b6dc499003
commit
ccb841e289
|
@ -19,6 +19,8 @@ import logging
|
|||
|
||||
import django.apps
|
||||
import eopayment
|
||||
from django.db import transaction
|
||||
from django.db.models.signals import post_migrate
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
@ -28,6 +30,28 @@ class AppConfig(django.apps.AppConfig):
|
|||
name = 'combo.apps.lingo'
|
||||
verbose_name = _('Payment')
|
||||
|
||||
def ready(self):
|
||||
post_migrate.connect(self.post_migrate_handler, sender=self)
|
||||
|
||||
def post_migrate_handler(self, **kwargs):
|
||||
from .models import PaymentBackend
|
||||
|
||||
with transaction.atomic():
|
||||
for payment_backend in PaymentBackend.objects.all():
|
||||
service_options = payment_backend.service_options
|
||||
transaction_options = {}
|
||||
for parameter in payment_backend.eopayment.get_parameters(scope='transaction'):
|
||||
name = parameter['name']
|
||||
if name in service_options:
|
||||
transaction_options[name] = service_options.pop(name)
|
||||
if not transaction_options:
|
||||
continue
|
||||
payment_backend.save()
|
||||
for regie in payment_backend.regie_set.all():
|
||||
# merge old values in new transactions options
|
||||
regie.transaction_options = dict(transaction_options, **regie.transaction_options)
|
||||
regie.save()
|
||||
|
||||
def get_before_urls(self):
|
||||
from . import urls
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
from django.core.management import call_command
|
||||
|
||||
from combo.apps.lingo.models import PaymentBackend
|
||||
|
||||
|
||||
def test_post_migrate(db):
|
||||
'''manual_validation is a transaction scope parameter on the systempayv2
|
||||
backend, check it is transfered after a migration.'''
|
||||
|
||||
payment_backend = PaymentBackend.objects.create(
|
||||
label='test', slug='test', service='systempayv2', service_options={'manual_validation': True}
|
||||
)
|
||||
regie = payment_backend.regie_set.create(label='test', slug='test', description='test')
|
||||
|
||||
call_command('migrate', 'lingo')
|
||||
|
||||
payment_backend.refresh_from_db()
|
||||
regie.refresh_from_db()
|
||||
assert 'manual_validation' not in payment_backend.service_options
|
||||
assert 'manual_validation' in regie.transaction_options
|
Loading…
Reference in New Issue