Skip to content
Snippets Groups Projects
Commit 8f01a050 authored by Tom Teichler's avatar Tom Teichler :beers:
Browse files

Add python migration

parent 862496b1
No related branches found
No related tags found
1 merge request!17Update Invoice if person changes
Pipeline #60792 failed
......@@ -3,6 +3,15 @@
from django.db import migrations
def set_person_on_invoices(apps, schema_editor):
Invoice = apps.get_model("tezor", "Invoice")
for invoice in Invoice.objects.filter(person__isnull=True, for_object_id__isnull=False):
person = invoice.for_object.get_person()
invoice.person=person
invoice.save()
class Migration(migrations.Migration):
dependencies = [
......@@ -14,4 +23,5 @@ class Migration(migrations.Migration):
model_name='invoice',
name='object_or_person',
),
migrations.RunPython(set_person_on_invoices),
]
......@@ -9,7 +9,7 @@ from .models.invoice import Invoice
@receiver(post_save, sender=Person)
def update_on_person_change(sender, instance, **kwargs):
if Invoice.objects.filter(person=instance, status__in=("waiting", "input", "preauth")).exists() and get_site_preferences()["payments__update_on_person_change"]:
if get_site_preferences()["payments__update_on_person_change"]:
Invoice.objects.filter(person=instance, status__in=("waiting", "input", "preauth")).update(
billing_email=instance.email,
billing_first_name=instance.first_name,
......@@ -18,5 +18,3 @@ def update_on_person_change(sender, instance, **kwargs):
billing_postcode=instance.postal_code,
billing_city=instance.place,
)
else:
pass
from django.db.models.signals import pre_save
from django.dispatch import receiver
from aleksis.core.util.core_helpers import get_site_preferences
from aleksis.core.models import Person
from ..models.invoice import Invoice
def provider_factory(variant, payment=None):
from djp_sepa.providers import DirectDebitProvider, PaymentPledgeProvider # noqa
from payments.paypal import PaypalProvider # noqa
......@@ -49,19 +41,3 @@ def provider_factory(variant, payment=None):
)
return KeyError("Provider not found or not configured for client.")
@receiver(post_save, sender=Person)
def update_on_person_change(sender, **kwargs):
print(f"!!! {sender}")
if Invoice.objects.filter(person=sender, status__in=("waiting", "input", "preauth")).exists() and get_site_preferences()["payments__update_on_person_change"]:
Invoice.objects.filter(person=sender).update(
billing_email=person.email,
billing_first_name=person.first_name,
billing_last_name=person.last_name,
billing_address_1=f"{person.street} {person.housenumber}",
billing_postcode=person.postal_code,
billing_city=person.place,
)
else:
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment