Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix avatax default variables
Maciej Korycinski6cd0c17ee3d0
diff --git a/saleor/core/taxes/avatax/__init__.py b/saleor/core/taxes/avatax/__init__.pyindex e5a06264e4..5fdc0a4312 100644--- a/saleor/core/taxes/avatax/__init__.py+++ b/saleor/core/taxes/avatax/__init__.py@@ -15,12 +15,6 @@ if TYPE_CHECKING:from ....order.models import Order-common_carrier_code = "FR020100" # FIXME-cache_key = "avatax_request_id_" # FIXME-TAX_CODES_CACHE_KEY = "avatax_tax_codes_cache_key"-COMMON_CARRIER_CODE = "FR000000"--class TransactionType:INVOICE = "SalesInvoice"ORDER = "SalesOrder"@@ -99,7 +93,7 @@ def validate_checkout(checkout: "Checkout") -> bool:def checkout_needs_new_fetch(data, checkout_token: str) -> bool:"""We store the response from avatax for checkout object for given time. If objectdoesn't exist in cache or something has changed, then we fetch data from avatax."""- checkout_cache_key = cache_key + checkout_token+ checkout_cache_key = settings.AVATAX_CACHE_KEY + checkout_tokencached_checkout = cache.get(checkout_cache_key)if not cached_checkout:@@ -114,7 +108,7 @@ def checkout_needs_new_fetch(data, checkout_token: str) -> bool:def taxes_need_new_fetch(data: Dict[str, Any], taxes_token: str) -> bool:"""We store the response from avatax. If object doesn't exist in cache orsomething has changed, then we fetch data from avatax."""- taxes_cache_key = cache_key + taxes_token+ taxes_cache_key = settings.AVATAX_CACHE_KEY + taxes_tokencached_data = cache.get(taxes_cache_key)if not cached_data:@@ -175,7 +169,7 @@ def get_checkout_lines_data(data,quantity=1,amount=str(checkout.shipping_method.price.amount),- tax_code=common_carrier_code,+ tax_code=settings.AVATAX_COMMON_CARRIER_CODE,item_code="Shipping",)return data@@ -205,7 +199,7 @@ def get_order_lines_data(order: "Order") -> List[Dict[str, str]]:data,quantity=1,amount=order.shipping_method.price.amount,- tax_code=common_carrier_code,+ tax_code=settings.AVATAX_COMMON_CARRIER_CODE,item_code="Shipping",)return data@@ -289,7 +283,7 @@ def generate_request_data_from_checkout(def get_cached_response_or_fetch(data, token_in_cache):"""Try to find response in cache. Return cached response if requests data arethe same. Fetch new data in other cases"""- data_cache_key = cache_key + token_in_cache+ data_cache_key = settings.AVATAX_CACHE_KEY + token_in_cacheif taxes_need_new_fetch(data, token_in_cache):transaction_url = urljoin(get_api_url(), "transactions/createoradjust")print("HIT TO API")@@ -341,11 +335,11 @@ def get_cached_tax_codes_or_fetch():"""Try to get cached tax codes. If cache is empty fetch the newest taxcodes fromavatax"""- tax_codes = cache.get(TAX_CODES_CACHE_KEY, {})+ tax_codes = cache.get(settings.TAX_CODES_CACHE_KEY, {})if not tax_codes:tax_codes_url = urljoin(get_api_url(), "definitions/taxcodes")response = api_get_request(tax_codes_url)if response and "error" not in response:tax_codes = generate_tax_codes_dict(response)- cache.set(TAX_CODES_CACHE_KEY, tax_codes, cache_time)+ cache.set(settings.TAX_CODES_CACHE_KEY, tax_codes, cache_time)return tax_codesdiff --git a/saleor/settings.py b/saleor/settings.pyindex d18da9140b..c31c4bcb9d 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -351,7 +351,11 @@ AVATAX_USE_SANDBOX = os.environ.get("AVATAX_USE_SANDBOX", True)AVATAX_COMPANY_NAME = os.environ.get("AVATAX_COMPANY_NAME", "DEFAULT")AVATAX_CACHE_TIME = os.environ.get("AVATAX_CACHE_TIME", 60 * 60)AVATAX_TAX_CODES_CACHE_TIME = os.environ.get("AVATAX_TAX_CODES_CACHE", 60 * 60 * 24 * 7)-+AVATAX_COMMON_CARRIER_CODE = os.environ.get("AVATAX_COMMON_CARRIER_CODE", "FR020100")+AVATAX_CACHE_KEY = os.environ.get("AVATAX_CACHE_KEY", "avatax_request_id_")+AVATAX_TAX_CODES_CACHE_KEY = os.environ.get(+ "AVATAX_TAX_CODES_CACHE_KEY", "avatax_tax_codes_cache_key"+)ACCOUNT_ACTIVATION_DAYS = 3