Patch invalid invoice admin registration
This commit is contained in:
26
mandelstudio/admin_fixes.py
Normal file
26
mandelstudio/admin_fixes.py
Normal 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)
|
||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user