Skip to content

Commit

Permalink
Merge pull request #4664 from korycins/fix/avatax_shows_wrong_value_f…
Browse files Browse the repository at this point in the history
…or_total_in_checkout

Fix wrong calculation of total in checkout details
  • Loading branch information
maarcingebala committed Aug 21, 2019
2 parents a1908ca + d0007ec commit 55b621e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
3 changes: 1 addition & 2 deletions saleor/checkout/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,7 @@ def get_checkout_context(checkout, discounts, currency=None, shipping_range=None
start=checkout_subtotal, stop=checkout_subtotal
)
if shipping_required and shipping_range:
total_with_shipping = shipping_range + checkout_subtotal.net

total_with_shipping = shipping_range + checkout_subtotal
context = {
"checkout": checkout,
"checkout_are_taxes_handled": manager.taxes_are_enabled(),
Expand Down
3 changes: 3 additions & 0 deletions saleor/extensions/plugins/avatax/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def _initialize_plugin_configuration(self):
self.config = AvataxConfiguration(
username_or_account=settings.AVATAX_USERNAME_OR_ACCOUNT,
password_or_license=settings.AVATAX_PASSWORD_OR_LICENSE,
use_sandbox=settings.AVATAX_USE_SANDBOX,
autocommit=settings.AVATAX_AUTOCOMMIT,
company_name=settings.AVATAX_COMPANY_NAME,
)
self.active = (
settings.AVATAX_USERNAME_OR_ACCOUNT
Expand Down
4 changes: 2 additions & 2 deletions saleor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ def get_bool_from_env(name, default_value):
# Avatax supports two ways of log in - username:password or account:license
AVATAX_USERNAME_OR_ACCOUNT = os.environ.get("AVATAX_USERNAME_OR_ACCOUNT")
AVATAX_PASSWORD_OR_LICENSE = os.environ.get("AVATAX_PASSWORD_OR_LICENSE")
AVATAX_USE_SANDBOX = os.environ.get("AVATAX_USE_SANDBOX", DEBUG)
AVATAX_USE_SANDBOX = get_bool_from_env("AVATAX_USE_SANDBOX", DEBUG)
AVATAX_COMPANY_NAME = os.environ.get("AVATAX_COMPANY_NAME", "DEFAULT")
AVATAX_AUTOCOMMIT = os.environ.get("AVATAX_AUTOCOMMIT", False)
AVATAX_AUTOCOMMIT = get_bool_from_env("AVATAX_AUTOCOMMIT", False)

ACCOUNT_ACTIVATION_DAYS = 3

Expand Down
25 changes: 25 additions & 0 deletions tests/test_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
create_order,
get_checkout_context,
get_prices_of_products_in_discounted_categories,
get_shipping_price_estimate,
get_voucher_discount_for_checkout,
get_voucher_for_checkout,
is_valid_shipping_method,
Expand Down Expand Up @@ -1405,6 +1406,30 @@ def test_get_checkout_context(checkout_with_voucher):
assert data == expected_data


def test_get_checkout_context_with_shipping_range(
checkout_with_voucher, shipping_method, address, monkeypatch
):
checkout_with_voucher.shipping_method = shipping_method
checkout_with_voucher.shipping_address = address
line_price = TaxedMoney(net=Money("30.00", "USD"), gross=Money("45.00", "USD"))

monkeypatch.setattr(
ExtensionsManager, "calculate_checkout_subtotal", Mock(return_value=line_price)
)

shipping_range = get_shipping_price_estimate(
checkout_with_voucher, discounts=None, country_code="US"
)
expected_total_with_shipping = TaxedMoneyRange(start=line_price, stop=line_price)
expected_total_with_shipping += shipping_range

data = get_checkout_context(
checkout_with_voucher, discounts=None, shipping_range=shipping_range
)

assert data["total_with_shipping"] == expected_total_with_shipping


def test_change_address_in_checkout(checkout, address):
change_shipping_address_in_checkout(checkout, address)
change_billing_address_in_checkout(checkout, address)
Expand Down

0 comments on commit 55b621e

Please sign in to comment.