Patch invalid invoice admin registration

This commit is contained in:
2026-04-10 18:12:01 +02:00
parent d1c6a5f85c
commit ea011b2993
2 changed files with 31 additions and 0 deletions

View File

@@ -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)

View File

@@ -5,3 +5,8 @@ class MandelstudioConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField" default_auto_field = "django.db.models.BigAutoField"
name = "mandelstudio" name = "mandelstudio"
verbose_name = "Mandelstudio" verbose_name = "Mandelstudio"
def ready(self):
from .admin_fixes import patch_invoice_admin
patch_invoice_admin()