diff --git a/mandelstudio/admin_fixes.py b/mandelstudio/admin_fixes.py new file mode 100644 index 0000000..39bea05 --- /dev/null +++ b/mandelstudio/admin_fixes.py @@ -0,0 +1,26 @@ +from django.contrib import admin +from django.contrib.admin.sites import NotRegistered + + +def patch_invoice_admin(): + """ + Load the invoice admin stack in a safe order and remove the invalid + date_hierarchy setting injected by the communications plugin. + """ + try: + import oscar_invoices.admin # noqa: F401 + from oscar.core.loading import get_model + from ocyan.plugin.oscar_communications.oscar_invoices_extension.admin import ( + InvoiceAdmin, + ) + except ImportError: + return + + Invoice = get_model("oscar_invoices", "Invoice") + InvoiceAdmin.date_hierarchy = None + + try: + admin.site.unregister(Invoice) + except NotRegistered: + pass + admin.site.register(Invoice, InvoiceAdmin) diff --git a/mandelstudio/apps.py b/mandelstudio/apps.py index 194cd4c..be678d0 100644 --- a/mandelstudio/apps.py +++ b/mandelstudio/apps.py @@ -5,3 +5,8 @@ class MandelstudioConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" name = "mandelstudio" verbose_name = "Mandelstudio" + + def ready(self): + from .admin_fixes import patch_invoice_admin + + patch_invoice_admin()