Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix country fetching for flat rates (#18352)
Iga Karbowiak2c770c685a57
diff --git a/saleor/checkout/actions.py b/saleor/checkout/actions.pyindex 8d5dbcb958..2776bf00b2 100644--- a/saleor/checkout/actions.py+++ b/saleor/checkout/actions.py@@ -102,9 +102,6 @@ def _trigger_checkout_sync_webhooks(checkout_info=checkout_info,manager=manager,lines=lines,- address=address- or checkout_info.shipping_address- or checkout_info.billing_address,force_update=True,)diff --git a/saleor/checkout/calculations.py b/saleor/checkout/calculations.pyindex 7a3c902e31..efcf28203b 100644--- a/saleor/checkout/calculations.py+++ b/saleor/checkout/calculations.py@@ -65,7 +65,6 @@ def checkout_shipping_price(checkout_info,manager=manager,lines=lines,- address=address,database_connection_name=database_connection_name,pregenerated_subscription_payloads=pregenerated_subscription_payloads,allow_sync_webhooks=allow_sync_webhooks,@@ -90,7 +89,6 @@ def checkout_shipping_tax_rate(checkout_info,manager=manager,lines=lines,- address=address,database_connection_name=database_connection_name,allow_sync_webhooks=allow_sync_webhooks,)@@ -118,7 +116,6 @@ def checkout_subtotal(checkout_info,manager=manager,lines=lines,- address=address,database_connection_name=database_connection_name,pregenerated_subscription_payloads=pregenerated_subscription_payloads,allow_sync_webhooks=allow_sync_webhooks,@@ -199,7 +196,6 @@ def calculate_checkout_total(checkout_info,manager=manager,lines=lines,- address=address,database_connection_name=database_connection_name,pregenerated_subscription_payloads=pregenerated_subscription_payloads,force_update=force_update,@@ -225,12 +221,10 @@ def checkout_line_total(if pregenerated_subscription_payloads is None:pregenerated_subscription_payloads = {}currency = checkout_info.checkout.currency- address = checkout_info.shipping_address or checkout_info.billing_address_, lines = fetch_checkout_data(checkout_info,manager=manager,lines=lines,- address=address,database_connection_name=database_connection_name,pregenerated_subscription_payloads=pregenerated_subscription_payloads,allow_sync_webhooks=allow_sync_webhooks,@@ -256,12 +250,10 @@ def checkout_line_unit_price(if pregenerated_subscription_payloads is None:pregenerated_subscription_payloads = {}currency = checkout_info.checkout.currency- address = checkout_info.shipping_address or checkout_info.billing_address_, lines = fetch_checkout_data(checkout_info,manager=manager,lines=lines,- address=address,database_connection_name=database_connection_name,pregenerated_subscription_payloads=pregenerated_subscription_payloads,allow_sync_webhooks=allow_sync_webhooks,@@ -284,12 +276,10 @@ def checkout_line_tax_rate(It takes in account all plugins."""- address = checkout_info.shipping_address or checkout_info.billing_address_, lines = fetch_checkout_data(checkout_info,manager=manager,lines=lines,- address=address,database_connection_name=database_connection_name,allow_sync_webhooks=allow_sync_webhooks,)@@ -358,7 +348,6 @@ def _fetch_checkout_prices_if_expired(manager: "PluginsManager",lines: list["CheckoutLineInfo"],allow_sync_webhooks: bool,- address: Optional["Address"] = None,force_update: bool = False,database_connection_name: str = settings.DATABASE_CONNECTION_DEFAULT_NAME,pregenerated_subscription_payloads: dict | None = None,@@ -425,7 +414,6 @@ def _fetch_checkout_prices_if_expired(checkout_info,lines,prices_entered_with_tax,- address,database_connection_name=database_connection_name,pregenerated_subscription_payloads=pregenerated_subscription_payloads,)@@ -508,7 +496,6 @@ def _calculate_and_add_tax(checkout_info: "CheckoutInfo",lines: list["CheckoutLineInfo"],prices_entered_with_tax: bool,- address: Optional["Address"] = None,database_connection_name: str = settings.DATABASE_CONNECTION_DEFAULT_NAME,pregenerated_subscription_payloads: dict | None = None,):@@ -522,7 +509,6 @@ def _calculate_and_add_tax(checkout_info,lines,prices_entered_with_tax,- address,database_connection_name=database_connection_name,)return@@ -532,7 +518,7 @@ def _calculate_and_add_tax(# configured with Avatax plugin identifier.if not tax_app_identifier:# Call the tax plugins.- _apply_tax_data_from_plugins(checkout, manager, checkout_info, lines, address)+ _apply_tax_data_from_plugins(checkout, manager, checkout_info, lines)# Get the taxes calculated with apps and apply to checkout.# We should allow empty tax_data in case any tax webhook has not been# configured - handled by `allowed_empty_tax_data`@@ -552,7 +538,6 @@ def _calculate_and_add_tax(manager,checkout_info,lines,- address,pregenerated_subscription_payloads,)@@ -563,7 +548,6 @@ def _call_plugin_or_tax_app(manager: "PluginsManager",checkout_info: "CheckoutInfo",lines: list["CheckoutLineInfo"],- address: Optional["Address"] = None,pregenerated_subscription_payloads: dict | None = None,):if pregenerated_subscription_payloads is None:@@ -583,7 +567,6 @@ def _call_plugin_or_tax_app(manager,checkout_info,lines,- address,plugin_ids=plugin_ids,)if checkout.tax_error:@@ -702,9 +685,9 @@ def _apply_tax_data_from_plugins(manager: "PluginsManager",checkout_info: "CheckoutInfo",lines: list["CheckoutLineInfo"],- address: Optional["Address"],plugin_ids: list[str] | None = None,) -> None:+ address = checkout_info.shipping_address or checkout_info.billing_addressfor line_info in lines:line = line_info.line@@ -787,7 +770,6 @@ def fetch_checkout_data(checkout_info: "CheckoutInfo",manager: "PluginsManager",lines: list["CheckoutLineInfo"],- address: Optional["Address"] = None,force_update: bool = False,checkout_transactions: Iterable["TransactionItem"] | None = None,force_status_update: bool = False,@@ -807,7 +789,6 @@ def fetch_checkout_data(checkout_info=checkout_info,manager=manager,lines=lines,- address=address,force_update=force_update,database_connection_name=database_connection_name,pregenerated_subscription_payloads=pregenerated_subscription_payloads,diff --git a/saleor/checkout/tests/test_calculations.py b/saleor/checkout/tests/test_calculations.pyindex 01fedf6b8e..e77ccf8c5a 100644--- a/saleor/checkout/tests/test_calculations.py+++ b/saleor/checkout/tests/test_calculations.py@@ -29,6 +29,7 @@ from ...product.models import ProductVariantChannelListingfrom ...shipping.interface import ShippingMethodDatafrom ...tax import TaxCalculationStrategyfrom ...tax.calculations.checkout import update_checkout_prices_with_flat_rates+from ...tax.models import TaxClass, TaxClassCountryRatefrom ...tests import race_conditionfrom .. import CheckoutAuthorizeStatus, CheckoutChargeStatusfrom ..base_calculations import (@@ -154,8 +155,6 @@ def fetch_kwargs(checkout_with_items, plugins_manager):),"manager": plugins_manager,"lines": lines,- "address": checkout_with_items.shipping_address- or checkout_with_items.billing_address,}@@ -407,7 +406,6 @@ def test_fetch_checkout_data_flat_rates_with_weighted_shipping_tax(plugins_manager,lines,allow_sync_webhooks=allow_sync_webhooks,- address=checkout.shipping_address,)# then@@ -635,7 +633,6 @@ def test_fetch_checkout_prices_when_tax_exemption_and_include_taxes_in_prices("checkout_info": fetch_checkout_info(checkout, lines_info, manager),"manager": manager,"lines": lines_info,- "address": checkout.shipping_address or checkout.billing_address,}# when@@ -693,7 +690,6 @@ def test_fetch_checkout_prices_when_tax_exemption_and_not_include_taxes_in_price"checkout_info": checkout_info,"manager": manager,"lines": lines_info,- "address": checkout.shipping_address or checkout.billing_address,}# when@@ -749,7 +745,6 @@ def test_fetch_checkout_data_calls_plugin("checkout_info": fetch_checkout_info(checkout, lines_info, manager),"manager": manager,"lines": lines_info,- "address": checkout.shipping_address or checkout.billing_address,}# when@@ -790,7 +785,6 @@ def test_fetch_checkout_data_calls_tax_app("checkout_info": fetch_checkout_info(checkout, lines_info, manager),"manager": manager,"lines": lines_info,- "address": checkout.shipping_address or checkout.billing_address,"allow_sync_webhooks": True,}@@ -836,7 +830,6 @@ def test_fetch_checkout_data_calls_tax_app_when_allow_sync_webhooks_set_to_false"checkout_info": checkout_info,"manager": manager,"lines": lines_info,- "address": checkout.shipping_address or checkout.billing_address,"allow_sync_webhooks": False,}assert (@@ -878,7 +871,6 @@ def test_fetch_checkout_data_calls_inactive_plugin("checkout_info": fetch_checkout_info(checkout, lines_info, manager),"manager": manager,"lines": lines_info,- "address": checkout.shipping_address or checkout.billing_address,}# when@@ -889,6 +881,61 @@ def test_fetch_checkout_data_calls_inactive_plugin(assert checkout_with_items.tax_error == "Empty tax data."+def test_fetch_checkout_data_flat_rates_shipping_tax_differs_from_default(+ checkout_with_items,+ address,+ plugins_manager,+):+ # given the checkout with the shipping country and tax different than the channel+ # default country+ checkout = checkout_with_items+ tc = checkout.channel.tax_configuration+ tc.prices_entered_with_tax = True+ tc.tax_calculation_strategy = TaxCalculationStrategy.FLAT_RATES+ tc.country_exceptions.all().delete()+ tc.save()++ default_country = checkout.channel.default_country+ default_country_rate = 21+ shipping_address_country = "PL"+ shipping_address_rate = 23+ tax_class = TaxClass.objects.create(name="Product")+ tax_class.country_rates.bulk_create(+ [+ TaxClassCountryRate(country=default_country, rate=default_country_rate),+ TaxClassCountryRate(+ country=shipping_address_country, rate=shipping_address_rate+ ),+ ]+ )+ for line in checkout.lines.all():+ product = line.variant.product+ product.tax_class = tax_class+ product.save(update_fields=["tax_class"])++ checkout.shipping_address = address+ checkout.billing_address = address+ checkout.save(update_fields=["shipping_address", "billing_address"])++ lines, _ = fetch_checkout_lines(checkout_with_items)+ fetch_kwargs = {+ "checkout_info": fetch_checkout_info(+ checkout_with_items, lines, plugins_manager+ ),+ "manager": plugins_manager,+ "lines": lines,+ }++ # when+ fetch_checkout_data(**fetch_kwargs, allow_sync_webhooks=False)++ # then+ checkout.refresh_from_db()+ assert round(checkout.total.tax / checkout.total.net * 100) == shipping_address_rate+ for line in checkout.lines.all():+ assert line.tax_rate * 100 == shipping_address_rate++@patch("saleor.webhook.transport.synchronous.transport.send_webhook_request_sync")def test_external_shipping_method_called_only_once_during_tax_calculations(mock_send_webhook_request_sync,@@ -1226,8 +1273,6 @@ def test_fetch_checkout_with_prior_price_change("checkout_info": fetch_checkout_info(checkout_with_items, lines_info, manager),"manager": manager,"lines": lines_info,- "address": checkout_with_items.shipping_address- or checkout_with_items.billing_address,}# when@@ -1260,8 +1305,6 @@ def test_fetch_checkout_with_prior_price_none("checkout_info": fetch_checkout_info(checkout_with_items, lines_info, manager),"manager": manager,"lines": lines_info,- "address": checkout_with_items.shipping_address- or checkout_with_items.billing_address,}# when@@ -1280,10 +1323,6 @@ def test_fetch_checkout_data_updates_status_for_zero_amount_checkout_with_lines(lines, _ = fetch_checkout_lines(checkout_with_item_total_0)manager = get_plugins_manager(allow_replica=False)checkout_info = fetch_checkout_info(checkout_with_item_total_0, lines, manager)- address = (- checkout_with_item_total_0.shipping_address- or checkout_with_item_total_0.billing_address,- )assert checkout_with_item_total_0.total.gross == zero_money(checkout_with_item_total_0.total.currency@@ -1297,7 +1336,6 @@ def test_fetch_checkout_data_updates_status_for_zero_amount_checkout_with_lines(checkout_info=checkout_info,manager=manager,lines=lines,- address=address,)# then@@ -1352,7 +1390,6 @@ def test_fetch_checkout_data_considers_gift_cards_balance_when_updating_checkoutcheckout_info=checkout_info,manager=manager,lines=lines,- address=address,)# then@@ -1378,7 +1415,6 @@ def test_fetch_checkout_data_checkout_removed_before_save("checkout_info": fetch_checkout_info(checkout, lines_info, manager),"manager": manager,"lines": lines_info,- "address": checkout.shipping_address,}# when@@ -1427,7 +1463,6 @@ def test_fetch_checkout_data_checkout_updated_during_price_recalculation("checkout_info": fetch_checkout_info(checkout, lines_info, manager),"manager": manager,"lines": lines_info,- "address": checkout.shipping_address,}expected_email = "[email protected]"diff --git a/saleor/graphql/account/tests/queries/test_me.py b/saleor/graphql/account/tests/queries/test_me.pyindex 05c6e5a872..c23537a74f 100644--- a/saleor/graphql/account/tests/queries/test_me.py+++ b/saleor/graphql/account/tests/queries/test_me.py@@ -198,7 +198,6 @@ def test_me_query_checkouts_do_not_trigger_sync_tax_webhooks(mocked_fetch_checkout_prices_if_expired.assert_called_once_with(checkout_info=mock.ANY,allow_sync_webhooks=False,- address=None,database_connection_name=mock.ANY,force_update=False,lines=lines,@@ -246,13 +245,11 @@ def test_me_query_checkouts_calculate_flat_taxes(mock.ANY,lines,tax_configuration_flat_rates.prices_entered_with_tax,- None,database_connection_name=mock.ANY,)mocked_fetch_checkout_prices_if_expired.assert_called_once_with(checkout_info=mock.ANY,allow_sync_webhooks=False,- address=None,database_connection_name=mock.ANY,force_update=False,lines=lines,diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.pyindex 2dcc0a49ea..49af6b5ef8 100644--- a/saleor/graphql/checkout/tests/test_checkout.py+++ b/saleor/graphql/checkout/tests/test_checkout.py@@ -3689,7 +3689,6 @@ def test_checkout_prices_variant_listing_price_changed(checkout_info,manager,lines,- checkout_with_item.shipping_address,force_update=True,)@@ -3768,7 +3767,6 @@ def test_checkout_prices_expired_variant_listing_price_changed(checkout_info,manager,lines,- checkout_with_item.shipping_address,force_update=True,)checkout_with_item.price_expiration = timezone.now() - datetime.timedelta(days=1)@@ -3974,7 +3972,6 @@ def test_query_checkouts_do_not_trigger_sync_tax_webhooks(mocked_fetch_checkout_prices_if_expired.assert_called_once_with(checkout_info=mock.ANY,allow_sync_webhooks=False,- address=None,database_connection_name=mock.ANY,force_update=False,lines=lines,@@ -4021,13 +4018,11 @@ def test_query_checkouts_calculate_flat_taxes(mock.ANY,lines,tax_configuration_flat_rates.prices_entered_with_tax,- None,database_connection_name=mock.ANY,)mocked_fetch_checkout_prices_if_expired.assert_called_once_with(checkout_info=mock.ANY,allow_sync_webhooks=False,- address=None,database_connection_name=mock.ANY,force_update=False,lines=lines,@@ -4123,7 +4118,6 @@ def test_query_checkout_lines_do_not_trigger_sync_tax_webhooks(mocked_fetch_checkout_prices_if_expired.assert_called_once_with(checkout_info=mock.ANY,allow_sync_webhooks=False,- address=None,database_connection_name=mock.ANY,force_update=False,lines=lines,@@ -4166,13 +4160,11 @@ def test_query_checkout_lines_calculate_flat_taxes(mock.ANY,lines,tax_configuration_flat_rates.prices_entered_with_tax,- None,database_connection_name=mock.ANY,)mocked_fetch_checkout_prices_if_expired.assert_called_once_with(checkout_info=mock.ANY,allow_sync_webhooks=False,- address=None,database_connection_name=mock.ANY,force_update=False,lines=lines,diff --git a/saleor/graphql/checkout/tests/test_checkout_line_problems.py b/saleor/graphql/checkout/tests/test_checkout_line_problems.pyindex 08ce612f2a..c279f92744 100644--- a/saleor/graphql/checkout/tests/test_checkout_line_problems.py+++ b/saleor/graphql/checkout/tests/test_checkout_line_problems.py@@ -604,7 +604,6 @@ def test_query_checkouts_do_not_trigger_sync_tax_webhooks_when_variant_not_availmocked_fetch_checkout_prices_if_expired.assert_called_once_with(checkout_info=mock.ANY,allow_sync_webhooks=False,- address=None,database_connection_name=mock.ANY,force_update=False,lines=lines,@@ -657,7 +656,6 @@ def test_query_checkouts_calculate_flat_taxes_when_variant_not_available(mock.ANY,lines,tax_configuration_flat_rates.prices_entered_with_tax,- None,database_connection_name=mock.ANY,)mocked_fetch_checkout_prices_if_expired.assert_called_once()@@ -713,7 +711,6 @@ def test_query_checkouts_do_not_trigger_sync_tax_webhooks_when_out_of_stock(mocked_fetch_checkout_prices_if_expired.assert_called_once_with(checkout_info=mock.ANY,allow_sync_webhooks=False,- address=None,database_connection_name=mock.ANY,force_update=False,lines=lines,@@ -772,7 +769,6 @@ def test_query_checkouts_calculate_flat_taxes_when_variant_out_of_stock(mock.ANY,lines,tax_configuration_flat_rates.prices_entered_with_tax,- None,database_connection_name=mock.ANY,)mocked_fetch_checkout_prices_if_expired.assert_called_once()diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex 2ddc5620bf..0cf29059e7 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -1482,7 +1482,6 @@ class Checkout(SyncWebhookControlContextModelObjectType[models.Checkout]):checkout_info=checkout_info,manager=manager,lines=lines,- address=address,checkout_transactions=transactions,force_status_update=True,database_connection_name=database_connection_name,@@ -1520,7 +1519,6 @@ class Checkout(SyncWebhookControlContextModelObjectType[models.Checkout]):checkout_info=checkout_info,manager=manager,lines=lines,- address=address,checkout_transactions=transactions,force_status_update=True,database_connection_name=database_connection_name,diff --git a/saleor/tax/calculations/checkout.py b/saleor/tax/calculations/checkout.pyindex 06b8d4c09f..b3e5b6c48b 100644--- a/saleor/tax/calculations/checkout.py+++ b/saleor/tax/calculations/checkout.py@@ -1,5 +1,5 @@from decimal import Decimal-from typing import TYPE_CHECKING, Optional+from typing import TYPE_CHECKINGfrom django.conf import settingsfrom prices import TaxedMoney@@ -7,9 +7,9 @@ from prices import TaxedMoneyfrom ...checkout import base_calculationsfrom ...core.prices import quantize_pricefrom ...core.taxes import zero_taxed_money-from ...core.utils.country import get_active_countryfrom ..models import TaxClassCountryRatefrom ..utils import (+ get_checkout_active_country,get_shipping_tax_rate_for_checkout,get_tax_rate_for_country,normalize_tax_rate_for_db,@@ -17,7 +17,6 @@ from ..utils import (from . import calculate_flat_rate_taxif TYPE_CHECKING:- from ...account.models import Addressfrom ...checkout.fetch import CheckoutInfo, CheckoutLineInfofrom ...checkout.models import Checkout@@ -27,10 +26,9 @@ def update_checkout_prices_with_flat_rates(checkout_info: "CheckoutInfo",lines: list["CheckoutLineInfo"],prices_entered_with_tax: bool,- address: Optional["Address"] = None,database_connection_name: str = settings.DATABASE_CONNECTION_DEFAULT_NAME,):- country_code = get_active_country(checkout_info.channel, address)+ country_code = get_checkout_active_country(checkout_info)default_country_rate_obj = (TaxClassCountryRate.objects.using(database_connection_name).filter(country=country_code, tax_class=None)diff --git a/saleor/tax/tests/test_checkout_calculations.py b/saleor/tax/tests/test_checkout_calculations.pyindex 619a5e23ee..2f4f4c8244 100644--- a/saleor/tax/tests/test_checkout_calculations.py+++ b/saleor/tax/tests/test_checkout_calculations.py@@ -141,7 +141,7 @@ def test_calculate_checkout_total(# whenupdate_checkout_prices_with_flat_rates(- checkout, checkout_info, lines, prices_entered_with_tax, address+ checkout, checkout_info, lines, prices_entered_with_tax)# then@@ -203,7 +203,7 @@ def test_calculate_checkout_total_with_multiple_tax_rates(# whenupdate_checkout_prices_with_flat_rates(- checkout, checkout_info, lines, prices_entered_with_tax, address+ checkout, checkout_info, lines, prices_entered_with_tax)# then@@ -260,7 +260,7 @@ def test_calculate_checkout_shipping_with_not_weighted_taxes(# whenupdate_checkout_prices_with_flat_rates(- checkout, checkout_info, lines, prices_entered_with_tax, address+ checkout, checkout_info, lines, prices_entered_with_tax)# then@@ -318,7 +318,7 @@ def test_calculate_checkout_shipping_with_weighted_taxes(# whenupdate_checkout_prices_with_flat_rates(- checkout, checkout_info, lines, prices_entered_with_tax, address+ checkout, checkout_info, lines, prices_entered_with_tax)# then@@ -380,7 +380,6 @@ def test_calculate_checkout_total_with_sale(checkout_info,lines,prices_entered_with_tax,- address,)# then@@ -412,7 +411,7 @@ def test_calculate_checkout_total_no_tax_rates(# whenupdate_checkout_prices_with_flat_rates(- checkout, checkout_info, lines, prices_entered_with_tax, address+ checkout, checkout_info, lines, prices_entered_with_tax)# then@@ -445,7 +444,7 @@ def test_calculate_checkout_total_default_tax_rate_for_country(# whenupdate_checkout_prices_with_flat_rates(- checkout, checkout_info, lines, prices_entered_with_tax, address+ checkout, checkout_info, lines, prices_entered_with_tax)# then@@ -494,7 +493,7 @@ def test_calculate_checkout_total_with_shipping_voucher(# whenupdate_checkout_prices_with_flat_rates(- checkout, checkout_info, lines, prices_entered_with_tax, address+ checkout, checkout_info, lines, prices_entered_with_tax)# then@@ -547,7 +546,6 @@ def test_calculate_checkout_total_with_shipping_voucher_and_sale(checkout_info,lines,prices_entered_with_tax,- address,)# then@@ -595,7 +593,6 @@ def test_calculate_checkout_subtotal(checkout_info,lines,prices_entered_with_tax,- address,)# then@@ -634,7 +631,6 @@ def test_calculate_checkout_subtotal_with_promotion_prices_entered_with_tax(checkout_info,lines,prices_entered_with_tax,- address,)# then@@ -679,7 +675,6 @@ def test_calculate_checkout_subtotal_with_promotion_prices_not_entered_with_tax(checkout_info,lines,prices_entered_with_tax,- address,)# then@@ -720,7 +715,6 @@ def test_calculate_checkout_subtotal_with_order_promotion(checkout_info,lines,prices_entered_with_tax,- address,)# then@@ -761,7 +755,6 @@ def test_calculate_checkout_subtotal_with_gift_promotion(checkout_info,lines,prices_entered_with_tax,- address,)# thendiff --git a/saleor/tax/utils.py b/saleor/tax/utils.pyindex 469ca1a2d7..fd855e69ad 100644--- a/saleor/tax/utils.py+++ b/saleor/tax/utils.py@@ -156,11 +156,7 @@ def get_tax_configuration_for_checkout(database_connection_name: str = settings.DATABASE_CONNECTION_DEFAULT_NAME,) -> tuple["TaxConfiguration", Optional["TaxConfigurationPerCountry"]]:tax_configuration = checkout_info.tax_configuration- country_code = get_active_country(- checkout_info.channel,- checkout_info.shipping_address,- checkout_info.billing_address,- )+ country_code = get_checkout_active_country(checkout_info)country_tax_configuration = next((tc@@ -174,6 +170,23 @@ def get_tax_configuration_for_checkout(return tax_configuration, country_tax_configuration+def get_checkout_active_country(checkout_info: "CheckoutInfo") -> str:+ """Get active checkout country for the given checkout info.++ Return country code based on the following rules:+ - use country code from shipping address if it's provided in the first place+ - use country code from billing address if shipping address is not provided+ - if both shipping and billing addresses are not provided use the default country+ from channel+ """++ return get_active_country(+ channel=checkout_info.channel,+ shipping_address=checkout_info.shipping_address,+ billing_address=checkout_info.billing_address,+ )++def get_charge_taxes_for_checkout(checkout_info: "CheckoutInfo",database_connection_name: str = settings.DATABASE_CONNECTION_DEFAULT_NAME,diff --git a/saleor/webhook/transport/asynchronous/tests/test_deferred_payload.py b/saleor/webhook/transport/asynchronous/tests/test_deferred_payload.pyindex 7fe52ce0ee..9af96b3e71 100644--- a/saleor/webhook/transport/asynchronous/tests/test_deferred_payload.py+++ b/saleor/webhook/transport/asynchronous/tests/test_deferred_payload.py@@ -28,8 +28,6 @@ def fetch_kwargs(checkout_with_items, plugins_manager):),"manager": plugins_manager,"lines": lines,- "address": checkout_with_items.shipping_address- or checkout_with_items.billing_address,}