From a2f614ad41853b7c45232cb15929e5d217088fd5 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 14 Aug 2023 16:17:03 +1000 Subject: [PATCH] Disable "add rate" button in Admin interface (#5444) - Does not work with custom backend - Throws error if the button is pressed - So, remove the button --- InvenTree/InvenTree/admin.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/InvenTree/InvenTree/admin.py b/InvenTree/InvenTree/admin.py index d21f68aaac..241e5633ae 100644 --- a/InvenTree/InvenTree/admin.py +++ b/InvenTree/InvenTree/admin.py @@ -1,5 +1,10 @@ """Admin classes""" +from django.contrib import admin +from django.http.request import HttpRequest + +from djmoney.contrib.exchange.admin import RateAdmin +from djmoney.contrib.exchange.models import Rate from import_export.resources import ModelResource @@ -43,3 +48,15 @@ class InvenTreeResource(ModelResource): ] return [f for f in fields if f.column_name not in fields_to_exclude] + + +class CustomRateAdmin(RateAdmin): + """Admin interface for the Rate class""" + + def has_add_permission(self, request: HttpRequest) -> bool: + """Disable the 'add' permission for Rate objects""" + return False + + +admin.site.unregister(Rate) +admin.site.register(Rate, CustomRateAdmin)