Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add ShopFetchTaxRates mutation
fowczarek5c23e23e5e7d
diff --git a/saleor/graphql/shop/mutations.py b/saleor/graphql/shop/mutations.pyindex 51bbe268c8..a65022b862 100644--- a/saleor/graphql/shop/mutations.py+++ b/saleor/graphql/shop/mutations.py@@ -1,4 +1,8 @@+import logging+import graphene+from django.core.exceptions import ImproperlyConfigured+from django.core.management import call_commandfrom graphql_jwt.decorators import permission_requiredfrom ...site import models as site_models@@ -7,6 +11,8 @@ from ..core.mutations import BaseMutationfrom ..product.types import Collectionfrom .types import AuthorizationKey, AuthorizationKeyType, Shop+logger = logging.getLogger(__name__)+class ShopSettingsInput(graphene.InputObjectType):header_text = graphene.String(description='Header text')@@ -83,6 +89,27 @@ class ShopDomainUpdate(BaseMutation):return ShopDomainUpdate(shop=Shop(), errors=errors)+class ShopFetchTaxRates(BaseMutation):+ shop = graphene.Field(Shop, description='Updated Shop')++ class Meta:+ description = 'Fetch tax rates'++ @classmethod+ @permission_required('site.manage_settings')+ def mutate(cls, root, info):+ errors = []+ try:+ call_command('get_vat_rates')+ except ImproperlyConfigured as exc:+ logger.exception(exc)+ cls.add_error(+ errors, None, 'Could not fetch tax rates. '+ 'Make sure you have supplied a valid API Access Key.'+ 'Check the server logs for more information about this error.')+ return ShopFetchTaxRates(shop=Shop(), errors=errors)++class HomepageCollectionUpdate(BaseMutation):shop = graphene.Field(Shop, description='Updated Shop')diff --git a/saleor/graphql/shop/schema.py b/saleor/graphql/shop/schema.pyindex e86aa6335b..d4146811fb 100644--- a/saleor/graphql/shop/schema.py+++ b/saleor/graphql/shop/schema.py@@ -2,7 +2,7 @@ import graphenefrom .mutations import (AuthorizationKeyAdd, AuthorizationKeyDelete, HomepageCollectionUpdate,- ShopDomainUpdate, ShopSettingsUpdate)+ ShopDomainUpdate, ShopFetchTaxRates, ShopSettingsUpdate)from .types import Shop@@ -20,3 +20,4 @@ class ShopMutations(graphene.ObjectType):homepage_collection_update = HomepageCollectionUpdate.Field()shop_domain_update = ShopDomainUpdate.Field()shop_settings_update = ShopSettingsUpdate.Field()+ shop_fetch_tax_rates = ShopFetchTaxRates.Field()