Skip to content

Commit b962840

Browse files
Raised error
1 parent e4c026a commit b962840

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

nxtbn/core/admin_queries.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ def resolve_allowed_currency_list(self, info):
4242
@gql_store_admin_required
4343
def resolve_invoice_setting(self, info, invoice_settings_id=None, **kwargs):
4444
if not invoice_settings_id:
45-
return InvoiceSettings.objects.get(is_default=True)
45+
try:
46+
return InvoiceSettings.objects.get(is_default=True)
47+
except InvoiceSettings.DoesNotExist:
48+
raise GraphQLError("Default Invoice Settings not found.")
4649
return InvoiceSettings.objects.get(id=invoice_settings_id)
4750

4851
@gql_store_admin_required

nxtbn/core/models.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,6 @@ class InvoiceSettings(models.Model): # This info will be seen in the invoice
172172
contact_phone = models.CharField(max_length=20, blank=True, null=True, help_text="Contact phone number for site administrators.")
173173
is_default = models.BooleanField(default=False, help_text="If this is the default invoice settings.")
174174

175-
def save(self, *args, **kwargs):
176-
if self.is_default:
177-
InvoiceSettings.objects.filter(is_default=True).update(is_default=False)
178-
else:
179-
if not InvoiceSettings.objects.filter(is_default=True).exists():
180-
raise ValidationError("There must be at least one default invoice setting.")
181-
super().save(*args, **kwargs)
182-
183175

184176

185177

0 commit comments

Comments
 (0)