Skip to content

Commit e4c026a

Browse files
Fixed invoice logo upload
1 parent 1979b7b commit e4c026a

File tree

5 files changed

+66
-5
lines changed

5 files changed

+66
-5
lines changed

nxtbn/core/admin_mutation.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
from nxtbn.core import CurrencyTypes
55
from nxtbn.core.admin_permissions import gql_required_perm
6-
from nxtbn.core.admin_types import CurrencyExchangeType
7-
from nxtbn.core.models import CurrencyExchange
6+
from nxtbn.core.admin_types import CurrencyExchangeType, InvoiceSettingsInput, InvoiceSettingsType
7+
from nxtbn.core.models import CurrencyExchange, InvoiceSettings
88
from nxtbn.users import UserRole
99

1010
class CurrencyExchangeInput(graphene.InputObjectType):
@@ -77,9 +77,33 @@ def mutate(root, info, id):
7777

7878
currency_exchange.delete() # Delete the record
7979
return DeleteCurrencyExchange(success=True) # Return success
80+
81+
82+
83+
class CreateInvoiceSettings(graphene.Mutation):
84+
class Arguments:
85+
input = InvoiceSettingsInput()
86+
87+
invoice_settings = graphene.Field(InvoiceSettingsType)
88+
89+
@gql_required_perm(InvoiceSettings, 'add_invoicesettings')
90+
@staticmethod
91+
def mutate(root, info, input):
92+
invoice_settings = InvoiceSettings.objects.create(
93+
store_name=input.store_name,
94+
store_address=input.store_address,
95+
city=input.city,
96+
country=input.country,
97+
postal_code=input.postal_code,
98+
contact_email=input.contact_email,
99+
contact_phone=input.contact_phone,
100+
is_default=input.is_default,
101+
)
102+
return CreateInvoiceSettings(invoice_settings=invoice_settings)
80103

81104

82105
class CoreMutation(graphene.ObjectType):
83106
update_exchange_rate = UpdateCurrencyExchange.Field()
84107
create_exchange_rate = CreateCurrencyExchange.Field()
85-
delete_exchange_rate = DeleteCurrencyExchange.Field()
108+
delete_exchange_rate = DeleteCurrencyExchange.Field()
109+
create_invoice_settings = CreateInvoiceSettings.Field()

nxtbn/core/admin_types.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ class Meta:
2020

2121
class InvoiceSettingsType(DjangoObjectType):
2222
db_id = graphene.ID(source='id')
23+
logo = graphene.String()
24+
25+
def resolve_logo(self, info):
26+
if self.logo:
27+
return info.context.build_absolute_uri(self.logo.url)
28+
return None
2329
class Meta:
2430
model = InvoiceSettings
2531
fields = "__all__"
@@ -28,6 +34,18 @@ class Meta:
2834
'store_name': ['exact', 'icontains'],
2935
}
3036

37+
38+
class InvoiceSettingsInput(graphene.InputObjectType):
39+
store_name = graphene.String()
40+
store_address = graphene.String()
41+
city = graphene.String()
42+
country = graphene.String()
43+
postal_code = graphene.String()
44+
contact_email = graphene.String()
45+
contact_phone = graphene.String()
46+
is_default = graphene.Boolean()
47+
48+
3149
class AdminCurrencyTypesEnum(graphene.ObjectType):
3250
value = graphene.String()
3351
label = graphene.String()

nxtbn/core/api/dashboard/serializers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@ class Meta:
2626
'is_default',
2727
]
2828

29-
29+
30+
31+
class InvoiceSettingsLogoSerializer(serializers.ModelSerializer):
32+
class Meta:
33+
model = InvoiceSettings
34+
fields = ['id', 'logo']
35+
read_only_fields = ['id']

nxtbn/core/api/dashboard/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
urlpatterns = [
66
path('site-settings/', core_views.SiteSettingsView.as_view(), name='site-settings'),
77
path('invoice-settings/<int:pk>/', core_views.InvoiceSettingsView.as_view(), name='invoice-settings'),
8+
path('invoice-settings/upload-logo/<int:id>/', core_views.InvoiceSettingsLogoUploadAPIView.as_view(), name='upload-logo'),
9+
810
path('system-status/', status_views.SystemStatusAPIView.as_view(), name='system-status'),
911
path('db-tables-details/', status_views.DatabaseTableInfoAPIView.as_view(), name='db-details'),
1012
path('language-list/', core_views.LanguageChoicesAPIView.as_view(), name='language-list'),

nxtbn/core/api/dashboard/views.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from nxtbn.core import LanguageChoices
2929
from nxtbn.core.admin_permissions import GranularPermission, IsStoreAdmin, IsStoreStaff
30-
from nxtbn.core.api.dashboard.serializers import InvoiceSettingsSerializer, SiteSettingsSerializer
30+
from nxtbn.core.api.dashboard.serializers import InvoiceSettingsLogoSerializer, InvoiceSettingsSerializer, SiteSettingsSerializer
3131
from nxtbn.core.models import InvoiceSettings, SiteSettings
3232
from nxtbn.users import UserRole
3333

@@ -58,6 +58,17 @@ class InvoiceSettingsView(generics.RetrieveUpdateAPIView):
5858

5959

6060

61+
class InvoiceSettingsLogoUploadAPIView(generics.UpdateAPIView):
62+
permission_classes = (IsStoreAdmin,)
63+
queryset = InvoiceSettings.objects.all()
64+
serializer_class = InvoiceSettingsLogoSerializer
65+
lookup_field = 'id'
66+
67+
def partial_update(self, request, *args, **kwargs):
68+
kwargs['partial'] = True
69+
return self.update(request, *args, **kwargs)
70+
71+
6172
class LanguageChoicesAPIView(APIView):
6273
permission_classes = (IsStoreStaff,)
6374
def get(self, request, *args, **kwargs):

0 commit comments

Comments
 (0)