18 lines
906 B
Python
18 lines
906 B
Python
from django.db import migrations
|
|
|
|
|
|
def normalize_existing_identifiers(apps, schema_editor):
|
|
digit_map = str.maketrans('۰۱۲۳۴۵۶۷۸۹٠١٢٣٤٥٦٧٨٩', '01234567890123456789')
|
|
for name in ('PaymentNotice', 'PaymentReceiptRevision'):
|
|
records = apps.get_model('payments', name).objects.using(schema_editor.connection.alias)
|
|
for pk, original in records.exclude(deposit_id='').values_list('pk', 'deposit_id').iterator(chunk_size=500):
|
|
value = original.translate(digit_map).strip()
|
|
normalized = (value.lstrip('0') or '0') if value else ''
|
|
if normalized != original:
|
|
records.filter(pk=pk).update(deposit_id=normalized)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [('payments', '0005_paymentnotice_deleted_at')]
|
|
operations = [migrations.RunPython(normalize_existing_identifiers, migrations.RunPython.noop)]
|