Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add option to remove company address

fowczarek9ea66c1ff584
diff --git a/saleor/graphql/shop/mutations.py b/saleor/graphql/shop/mutations.py
index 61b7e67e4f..177024ce1c 100644
--- a/saleor/graphql/shop/mutations.py
+++ b/saleor/graphql/shop/mutations.py
@@ -114,14 +114,18 @@ class ShopAddressUpdate(BaseMutation, I18nMixin):
site_settings = info.context.site.settings
data = data.get("input")
- if not site_settings.company_address:
- company_address = Address()
+ if data:
+ if not site_settings.company_address:
+ company_address = Address()
+ else:
+ company_address = site_settings.company_address
+ company_address = cls.validate_address(data, company_address)
+ company_address.save()
+ site_settings.company_address = company_address
+ site_settings.save(update_fields=["company_address"])
else:
- company_address = site_settings.company_address
- company_address = cls.validate_address(data, company_address)
- company_address.save()
- site_settings.company_address = company_address
- site_settings.save()
+ if site_settings.company_address:
+ site_settings.company_address.delete()
return ShopAddressUpdate(shop=Shop())
diff --git a/saleor/site/models.py b/saleor/site/models.py
index 4eaba2be38..c27e3a0f79 100644
--- a/saleor/site/models.py
+++ b/saleor/site/models.py
@@ -59,7 +59,7 @@ class SiteSettings(models.Model):
default_digital_max_downloads = models.IntegerField(blank=True, null=True)
default_digital_url_valid_days = models.IntegerField(blank=True, null=True)
company_address = models.ForeignKey(
- "account.Address", blank=True, null=True, on_delete=models.CASCADE
+ "account.Address", blank=True, null=True, on_delete=models.SET_NULL
)
default_mail_sender_name = models.CharField(
max_length=settings.DEFAULT_MAX_EMAIL_DISPLAY_NAME_LENGTH,