Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Use money in discounts, vatlayer-check if addres has country
Maciej Korycinski0daeda9644cf
diff --git a/saleor/core/taxes/vatlayer/interface.py b/saleor/core/taxes/vatlayer/interface.pyindex e54ac3331a..a97a5f3250 100644--- a/saleor/core/taxes/vatlayer/interface.py+++ b/saleor/core/taxes/vatlayer/interface.py@@ -41,7 +41,7 @@ def get_subtotal_gross(checkout: "Checkout", discounts: "SaleQueryset") -> Taxedfor line in lines:price = line.variant.get_price(discounts)lines_total += line.quantity * apply_taxes_to_variant(- line.variant, price, address.country+ line.variant, price, address.country if address else None)return lines_total@@ -61,7 +61,8 @@ def get_line_total_gross(checkout_line: "CheckoutLine", discounts: "SaleQuerysetor checkout_line.checkout.billing_address)price = checkout_line.variant.get_price(discounts) * checkout_line.quantity- return apply_taxes_to_variant(checkout_line.variant, price, address.country)+ country = address.country if address else None+ return apply_taxes_to_variant(checkout_line.variant, price, country)def apply_taxes_to_shipping(price: Money, shipping_address: "Address"):diff --git a/saleor/discount/models.py b/saleor/discount/models.pyindex 1d86d9515d..9811cfee99 100644--- a/saleor/discount/models.py+++ b/saleor/discount/models.py@@ -130,15 +130,14 @@ class Voucher(models.Model):def get_discount_amount_for(self, price):discount = self.get_discount()- gross_price = price.gross- gross_after_discount = discount(gross_price)- if gross_after_discount.amount < 0:- return gross_price- return gross_price - gross_after_discount+ after_discount = discount(price)+ if after_discount.amount < 0:+ return price+ return price - after_discountdef validate_min_amount_spent(self, value):min_amount_spent = self.min_amount_spent- if min_amount_spent and value.gross < min_amount_spent:+ if min_amount_spent and value < min_amount_spent:msg = pgettext("Voucher not applicable","This offer is only valid for orders over %(amount)s.",diff --git a/saleor/discount/utils.py b/saleor/discount/utils.pyindex c9ce721b1f..2f42f7e288 100644--- a/saleor/discount/utils.py+++ b/saleor/discount/utils.py@@ -3,7 +3,7 @@ import uuidfrom django.db.models import Ffrom django.utils.translation import pgettext-from ..core.taxes import ZERO_MONEY, ZERO_TAXED_MONEY+from ..core.taxes import ZERO_MONEYfrom .models import NotApplicable@@ -82,7 +82,7 @@ def get_shipping_voucher_discount(voucher, total_price, shipping_price):def get_products_voucher_discount(voucher, prices):"""Calculate discount value for a voucher of product or category type."""if voucher.apply_once_per_order:- product_total = sum(prices, ZERO_TAXED_MONEY)+ product_total = sum(prices, ZERO_MONEY)return voucher.get_discount_amount_for(product_total)discounts = (voucher.get_discount_amount_for(price) for price in prices)total_amount = sum(discounts, ZERO_MONEY)