Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Applied changes against reviews

NyanKiyoshi202cec0ad37b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 88c7dd7b44..bd5868307a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -58,6 +58,7 @@ All notable, unreleased changes to this project will be documented in this file.
- New stripe gateway implementation based on Stripe PaymentIntents API - #4606 by @salwator
- Change AddressValidationRules API - #4655 by @Kwaidan00
- Refactor account deletion mutations - #4668 by @fowczarek
+- Upgraded django-prices from v1 to v2.1. Currency codes are now locked at 3 characters max by default for consistency. - #4639 by @NyanKiyoshi
## 2.8.0
diff --git a/saleor/checkout/migrations/0021_django_price_2.py b/saleor/checkout/migrations/0021_django_price_2.py
index da82f26bb8..7e457a432a 100644
--- a/saleor/checkout/migrations/0021_django_price_2.py
+++ b/saleor/checkout/migrations/0021_django_price_2.py
@@ -11,6 +11,9 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="checkout",
name="currency",
- field=models.CharField(default=settings.DEFAULT_CURRENCY, max_length=3),
+ field=models.CharField(
+ default=settings.DEFAULT_CURRENCY,
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ ),
)
]
diff --git a/saleor/checkout/models.py b/saleor/checkout/models.py
index 81efa3445b..c325d0ffa1 100644
--- a/saleor/checkout/models.py
+++ b/saleor/checkout/models.py
@@ -68,7 +68,10 @@ class Checkout(ModelWithMetadata):
)
note = models.TextField(blank=True, default="")
- currency = models.CharField(max_length=3, default=settings.DEFAULT_CURRENCY)
+ currency = models.CharField(
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ default=settings.DEFAULT_CURRENCY,
+ )
discount_amount = models.DecimalField(
max_digits=settings.DEFAULT_MAX_DIGITS,
@@ -107,13 +110,13 @@ class Checkout(ModelWithMetadata):
return (
self.shipping_method.get_total()
if self.shipping_method and self.is_shipping_required()
- else zero_money()
+ else zero_money(self.currency)
)
def get_subtotal(self, discounts=None):
"""Return the total cost of the checkout prior to shipping."""
subtotals = (line.get_total(discounts) for line in self)
- return sum(subtotals, zero_money(currency=settings.DEFAULT_CURRENCY))
+ return sum(subtotals, zero_money(currency=self.currency))
def get_total(self, discounts=None):
"""Return the total cost of the checkout."""
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.py
index 7876018829..6ec0705b9f 100644
--- a/saleor/checkout/utils.py
+++ b/saleor/checkout/utils.py
@@ -17,7 +17,7 @@ from ..account.forms import get_address_form
from ..account.models import Address, User
from ..account.utils import store_user_address
from ..core.exceptions import InsufficientStock
-from ..core.taxes import quantize_price, zero_money, zero_taxed_money
+from ..core.taxes import quantize_price, zero_taxed_money
from ..core.utils import to_local_currency
from ..core.utils.promo_code import (
InvalidPromoCode,
@@ -963,7 +963,7 @@ def remove_voucher_from_checkout(checkout: Checkout):
checkout.voucher_code = None
checkout.discount_name = None
checkout.translated_discount_name = None
- checkout.discount = zero_money()
+ checkout.discount_amount = 0
checkout.save(
update_fields=[
"voucher_code",
diff --git a/saleor/core/taxes.py b/saleor/core/taxes.py
index 79b8d3a1ff..fec800c590 100644
--- a/saleor/core/taxes.py
+++ b/saleor/core/taxes.py
@@ -12,11 +12,14 @@ class TaxError(Exception):
"""Default tax error."""
-def zero_money(currency=settings.DEFAULT_CURRENCY):
+def zero_money(currency=None):
"""Return a money object set to zero.
This is a function used as a model's default.
"""
+
+ if currency is None:
+ currency = settings.DEFAULT_CURRENCY
return Money(0, currency)
diff --git a/saleor/dashboard/order/utils.py b/saleor/dashboard/order/utils.py
index 3a745542fb..6ce5508581 100644
--- a/saleor/dashboard/order/utils.py
+++ b/saleor/dashboard/order/utils.py
@@ -144,7 +144,7 @@ def get_voucher_discount_for_order(order):
Raise NotApplicable if voucher of given type cannot be applied.
"""
if not order.voucher:
- return zero_money()
+ return zero_money(order.currency)
validate_voucher_in_order(order)
subtotal = order.get_subtotal()
if order.voucher.type == VoucherType.ENTIRE_ORDER:
diff --git a/saleor/discount/migrations/0017_django_price_2.py b/saleor/discount/migrations/0017_django_price_2.py
index fa10bd5b8b..50b5bcd69f 100644
--- a/saleor/discount/migrations/0017_django_price_2.py
+++ b/saleor/discount/migrations/0017_django_price_2.py
@@ -17,6 +17,9 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="voucher",
name="currency",
- field=models.CharField(default=settings.DEFAULT_CURRENCY, max_length=10),
+ field=models.CharField(
+ default=settings.DEFAULT_CURRENCY,
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ ),
),
]
diff --git a/saleor/discount/models.py b/saleor/discount/models.py
index 6ada6a2b4f..4c39b47aac 100644
--- a/saleor/discount/models.py
+++ b/saleor/discount/models.py
@@ -72,7 +72,10 @@ class Voucher(models.Model):
# not mandatory fields, usage depends on type
countries = CountryField(multiple=True, blank=True)
- currency = models.CharField(max_length=10, default=settings.DEFAULT_CURRENCY)
+ currency = models.CharField(
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ default=settings.DEFAULT_CURRENCY,
+ )
min_spent_amount = models.DecimalField(
max_digits=settings.DEFAULT_MAX_DIGITS,
decimal_places=settings.DEFAULT_DECIMAL_PLACES,
@@ -144,14 +147,13 @@ class Voucher(models.Model):
return price - after_discount
def validate_min_spent(self, value: Money):
- min_spent = self.min_spent
- if min_spent and value < min_spent:
+ if self.min_spent and value < self.min_spent:
msg = pgettext(
"Voucher not applicable",
"This offer is only valid for orders over %(amount)s.",
)
raise NotApplicable(
- msg % {"amount": amount(min_spent)}, min_spent=min_spent
+ msg % {"amount": amount(self.min_spent)}, min_spent=self.min_spent
)
def validate_min_checkout_items_quantity(self, quantity):
diff --git a/saleor/discount/utils.py b/saleor/discount/utils.py
index 7d3d913f33..bab8152f7d 100644
--- a/saleor/discount/utils.py
+++ b/saleor/discount/utils.py
@@ -111,7 +111,7 @@ def get_products_voucher_discount(voucher, prices):
if voucher.apply_once_per_order:
return voucher.get_discount_amount_for(min(prices))
discounts = (voucher.get_discount_amount_for(price) for price in prices)
- total_amount = sum(discounts, zero_money())
+ total_amount = sum(discounts, zero_money(voucher.currency))
return total_amount
diff --git a/saleor/extensions/plugins/avatax/__init__.py b/saleor/extensions/plugins/avatax/__init__.py
index 1407130c44..8e4bf68099 100644
--- a/saleor/extensions/plugins/avatax/__init__.py
+++ b/saleor/extensions/plugins/avatax/__init__.py
@@ -260,7 +260,7 @@ def get_order_lines_data(order: "Order") -> List[Dict[str, str]]:
item_code=line.variant.sku,
description=line.variant.product.plain_text_description,
)
- if order.discount_amount and order.discount_amount:
+ if order.discount_amount:
append_line_to_data(
data=data,
quantity=1,
diff --git a/saleor/extensions/plugins/avatax/plugin.py b/saleor/extensions/plugins/avatax/plugin.py
index fad8b4073f..59c4b57fc7 100644
--- a/saleor/extensions/plugins/avatax/plugin.py
+++ b/saleor/extensions/plugins/avatax/plugin.py
@@ -157,9 +157,9 @@ class AvataxPlugin(BasePlugin):
total_gross = Money(amount=total_net + tax, currency=currency)
total_net = Money(amount=total_net, currency=currency)
total = TaxedMoney(net=total_net, gross=total_gross)
- voucher_amount = checkout.discount
- if voucher_amount:
- total -= voucher_amount
+ voucher_value = checkout.discount
+ if voucher_value:
+ total -= voucher_value
return max(total, zero_taxed_money(total.currency))
def _calculate_checkout_subtotal(
diff --git a/saleor/giftcard/migrations/0002_auto_20190814_0413.py b/saleor/giftcard/migrations/0002_auto_20190814_0413.py
index 1743eede95..1eed2448c8 100644
--- a/saleor/giftcard/migrations/0002_auto_20190814_0413.py
+++ b/saleor/giftcard/migrations/0002_auto_20190814_0413.py
@@ -22,6 +22,9 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="giftcard",
name="currency",
- field=models.CharField(default=settings.DEFAULT_CURRENCY, max_length=3),
+ field=models.CharField(
+ default=settings.DEFAULT_CURRENCY,
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ ),
),
]
diff --git a/saleor/giftcard/models.py b/saleor/giftcard/models.py
index 947f0d7536..eed035f18f 100644
--- a/saleor/giftcard/models.py
+++ b/saleor/giftcard/models.py
@@ -31,7 +31,10 @@ class GiftCard(models.Model):
last_used_on = models.DateTimeField(null=True, blank=True)
is_active = models.BooleanField(default=True)
- currency = models.CharField(max_length=3, default=settings.DEFAULT_CURRENCY)
+ currency = models.CharField(
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ default=settings.DEFAULT_CURRENCY,
+ )
initial_balance_amount = models.DecimalField(
max_digits=settings.DEFAULT_MAX_DIGITS,
diff --git a/saleor/graphql/discount/mutations.py b/saleor/graphql/discount/mutations.py
index 8236045512..1a33e07db1 100644
--- a/saleor/graphql/discount/mutations.py
+++ b/saleor/graphql/discount/mutations.py
@@ -164,6 +164,7 @@ class VoucherCreate(ModelMutation):
if voucher_type == VoucherTypeEnum.VALUE:
data["type"] = VoucherTypeEnum.ENTIRE_ORDER.value
+ # Deprecated field
min_spent_amount = data.pop("min_amount_spent", None)
if min_spent_amount is not None:
data["min_spent_amount"] = min_spent_amount
diff --git a/saleor/graphql/discount/types.py b/saleor/graphql/discount/types.py
index b579b13639..c8a6d5090d 100644
--- a/saleor/graphql/discount/types.py
+++ b/saleor/graphql/discount/types.py
@@ -103,7 +103,7 @@ class Voucher(CountableDjangoObjectType):
)
type = VoucherTypeEnum(description="Determines a type of voucher", required=True)
min_amount_spent = graphene.Field(
- types.Money, deprecation_reason="Use the minAmount field instead."
+ types.Money, deprecation_reason="Use the minSpent field instead."
)
class Meta:
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.py
index 4e2a77af2c..2d66ae25f3 100644
--- a/saleor/graphql/order/types.py
+++ b/saleor/graphql/order/types.py
@@ -327,7 +327,7 @@ class Order(CountableDjangoObjectType):
description="Returns True, if order requires shipping.", required=True
)
discount_amount = graphene.Field(
- Money, description="Deprecated: use discount instead.", required=True
+ Money, deprecation_reason="Deprecated: use discount instead.", required=True
)
class Meta:
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index ce6604e5a3..b9f04c1a02 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -656,21 +656,8 @@ class ProductVariantInput(graphene.InputObjectType):
required=False,
description="List of attributes specific to this variant.",
)
- cost_price = Decimal(
- description=(
- "Deprecated: use costPriceAmount instead.\n" "Cost price of the variant."
- )
- )
- cost_price_amount = Decimal(description="Cost price of the variant.")
- price_override = Decimal(
- description=(
- "Deprecated: use priceOverrideAmount instead.\n"
- "Special price of the particular variant."
- )
- )
- price_override_amount = Decimal(
- description="Special price of the particular variant."
- )
+ cost_price = Decimal(description="Cost price of the variant.")
+ price_override = Decimal(description="Special price of the particular variant.")
sku = graphene.String(description="Stock keeping unit.")
quantity = graphene.Int(
description="The total quantity of this variant available for sale."
@@ -740,16 +727,15 @@ class ProductVariantCreate(ModelMutation):
@classmethod
def clean_input(cls, info, instance, data):
+ cleaned_input = super().clean_input(info, instance, data)
- cost_price_amount = data.pop("cost_price", None)
+ cost_price_amount = cleaned_input.pop("cost_price", None)
if cost_price_amount is not None:
- data["cost_price_amount"] = cost_price_amount
+ cleaned_input["cost_price_amount"] = cost_price_amount
- price_override_amount = data.pop("price_override", None)
+ price_override_amount = cleaned_input.pop("price_override", None)
if price_override_amount is not None:
- data["price_override_amount"] = price_override_amount
-
- cleaned_input = super().clean_input(info, instance, data)
+ cleaned_input["price_override_amount"] = price_override_amount
# Attributes are provided as list of `AttributeValueInput` objects.
# We need to transform them into the format they're stored in the
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index fb945c619e..00a26bf0ef 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -2045,7 +2045,7 @@ type Order implements Node {
totalBalance: Money!
userEmail: String
isShippingRequired: Boolean!
- discountAmount: Money!
+ discountAmount: Money! @deprecated(reason: "Deprecated: use discount instead.")
}
enum OrderAction {
@@ -3621,7 +3621,7 @@ type Voucher implements Node {
products(before: String, after: String, first: Int, last: Int): ProductCountableConnection
countries: [CountryDisplay]
translation(languageCode: LanguageCodeEnum!): VoucherTranslation
- minAmountSpent: Money @deprecated(reason: "Use the minAmount field instead.")
+ minAmountSpent: Money @deprecated(reason: "Use the minSpent field instead.")
}
type VoucherAddCatalogues {
diff --git a/saleor/graphql/shipping/mutations.py b/saleor/graphql/shipping/mutations.py
index 1956bc1b39..affd8b78e9 100644
--- a/saleor/graphql/shipping/mutations.py
+++ b/saleor/graphql/shipping/mutations.py
@@ -11,29 +11,11 @@ from .types import ShippingMethod, ShippingZone
class ShippingPriceInput(graphene.InputObjectType):
name = graphene.String(description="Name of the shipping method.")
- price = Decimal(
- description=(
- "Deprecated: use priceAmount instead.\n"
- "Shipping price of the shipping method."
- )
- )
- price_amount = Decimal(description="Shipping price of the shipping method.")
+ price = Decimal(description="Shipping price of the shipping method.")
minimum_order_price = Decimal(
- description=(
- "deprecated: use minimumOrderPriceAmount instead.\n"
- "Minimum order price to use this shipping method"
- )
- )
- minimum_order_price_amount = Decimal(
description="Minimum order price to use this shipping method"
)
maximum_order_price = Decimal(
- description=(
- "deprecated: use maximumOrderPriceAmount instead.\n"
- "Maximum order price to use this shipping method"
- )
- )
- maximum_order_price_amount = Decimal(
description="Maximum order price to use this shipping method"
)
minimum_order_weight = WeightScalar(
@@ -121,12 +103,13 @@ class ShippingZoneDelete(ModelDeleteMutation):
class ShippingPriceMixin:
@classmethod
def clean_input(cls, info, instance, data):
- price_amount = data.pop("price", None)
- if price_amount is not None:
- data["price_amount"] = price_amount
-
cleaned_input = super().clean_input(info, instance, data)
+ # Rename the price field to price_amount (the model's)
+ price_amount = cleaned_input.pop("price", None)
+ if price_amount is not None:
+ cleaned_input["price_amount"] = price_amount
+
cleaned_type = cleaned_input.get("type")
if cleaned_type:
if cleaned_type == ShippingMethodTypeEnum.PRICE.value:
@@ -135,13 +118,9 @@ class ShippingPriceMixin:
if min_price is not None:
cleaned_input["minimum_order_price_amount"] = min_price
- else:
- min_price = cleaned_input.get("minimum_order_price_amount")
if max_price is not None:
cleaned_input["maximum_order_price_amount"] = max_price
- else:
- max_price = cleaned_input.get("maximum_order_price_amount")
if (
min_price is not None
diff --git a/saleor/order/migrations/0072_django_price_2.py b/saleor/order/migrations/0072_django_price_2.py
index 59e3ffe341..7dfb15185b 100644
--- a/saleor/order/migrations/0072_django_price_2.py
+++ b/saleor/order/migrations/0072_django_price_2.py
@@ -38,11 +38,17 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="order",
name="currency",
- field=models.CharField(default=settings.DEFAULT_CURRENCY, max_length=3),
+ field=models.CharField(
+ default=settings.DEFAULT_CURRENCY,
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ ),
),
migrations.AddField(
model_name="orderline",
name="currency",
- field=models.CharField(default=settings.DEFAULT_CURRENCY, max_length=3),
+ field=models.CharField(
+ default=settings.DEFAULT_CURRENCY,
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ ),
),
]
diff --git a/saleor/order/models.py b/saleor/order/models.py
index 41571acfe0..ad3e54392c 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -82,7 +82,10 @@ class Order(models.Model):
)
user_email = models.EmailField(blank=True, default="")
- currency = models.CharField(max_length=3, default=settings.DEFAULT_CURRENCY)
+ currency = models.CharField(
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ default=settings.DEFAULT_CURRENCY,
+ )
shipping_method = models.ForeignKey(
ShippingMethod,
@@ -365,7 +368,10 @@ class OrderLine(models.Model):
validators=[MinValueValidator(0)], default=0
)
- currency = models.CharField(max_length=3, default=settings.DEFAULT_CURRENCY)
+ currency = models.CharField(
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ default=settings.DEFAULT_CURRENCY,
+ )
unit_price_net_amount = models.DecimalField(
max_digits=settings.DEFAULT_MAX_DIGITS,
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index 6239201dab..1aca17048c 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -113,7 +113,7 @@ def update_voucher_discount(func):
try:
discount = get_voucher_discount_for_order(order)
except NotApplicable:
- discount = zero_money()
+ discount = zero_money(order.currency)
order.discount = discount
return func(*args, **kwargs)
@@ -156,8 +156,8 @@ def recalculate_order_weight(order):
def update_order_prices(order, discounts):
"""Update prices in order with given discounts and proper taxes."""
manager = get_extensions_manager()
- for line in order:
- if line.variant: # type: OrderLine
+ for line in order: # type: OrderLine
+ if line.variant:
unit_price = line.variant.get_price(discounts)
unit_price = TaxedMoney(unit_price, unit_price)
line.unit_price = unit_price
diff --git a/saleor/payment/migrations/0014_django_price_2.py b/saleor/payment/migrations/0014_django_price_2.py
new file mode 100644
index 0000000000..f610fd93a3
--- /dev/null
+++ b/saleor/payment/migrations/0014_django_price_2.py
@@ -0,0 +1,21 @@
+# Generated by Django 2.2.4 on 2019-08-19 10:50
+from django.conf import settings
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [("payment", "0013_auto_20190813_0735")]
+
+ operations = [
+ migrations.AlterField(
+ model_name="payment",
+ name="currency",
+ field=models.CharField(max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH),
+ ),
+ migrations.AlterField(
+ model_name="transaction",
+ name="currency",
+ field=models.CharField(max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH),
+ ),
+ ]
diff --git a/saleor/payment/models.py b/saleor/payment/models.py
index b36c19c635..4fb5e997b2 100644
--- a/saleor/payment/models.py
+++ b/saleor/payment/models.py
@@ -53,7 +53,9 @@ class Payment(models.Model):
decimal_places=settings.DEFAULT_DECIMAL_PLACES,
default=Decimal("0.0"),
)
- currency = models.CharField(max_length=10) # FIXME: add ISO4217 validator
+ currency = models.CharField(
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH
+ ) # FIXME: add ISO4217 validator
checkout = models.ForeignKey(
Checkout, null=True, related_name="payments", on_delete=models.SET_NULL
@@ -202,7 +204,7 @@ class Transaction(models.Model):
token = models.CharField(max_length=128, blank=True, default="")
kind = models.CharField(max_length=10, choices=TransactionKind.CHOICES)
is_success = models.BooleanField(default=False)
- currency = models.CharField(max_length=10)
+ currency = models.CharField(max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH)
amount = models.DecimalField(
max_digits=settings.DEFAULT_MAX_DIGITS,
decimal_places=settings.DEFAULT_DECIMAL_PLACES,
diff --git a/saleor/product/migrations/0106_django_prices_2.py b/saleor/product/migrations/0106_django_prices_2.py
index 0b4c652a05..dfa27e127d 100644
--- a/saleor/product/migrations/0106_django_prices_2.py
+++ b/saleor/product/migrations/0106_django_prices_2.py
@@ -25,13 +25,19 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="product",
name="currency",
- field=models.CharField(default=settings.DEFAULT_CURRENCY, max_length=10),
+ field=models.CharField(
+ default=settings.DEFAULT_CURRENCY,
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ ),
),
migrations.AddField(
model_name="productvariant",
name="currency",
field=models.CharField(
- blank=True, default=settings.DEFAULT_CURRENCY, max_length=10, null=True
+ blank=True,
+ default=settings.DEFAULT_CURRENCY,
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ null=True,
),
),
]
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 309426d63f..b081fad3a7 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -194,7 +194,10 @@ class Product(SeoModel, ModelWithMetadata, PublishableModel):
Category, related_name="products", on_delete=models.CASCADE
)
- currency = models.CharField(max_length=10, default=settings.DEFAULT_CURRENCY)
+ currency = models.CharField(
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ default=settings.DEFAULT_CURRENCY,
+ )
price_amount = models.DecimalField(
max_digits=settings.DEFAULT_MAX_DIGITS,
@@ -209,6 +212,7 @@ class Product(SeoModel, ModelWithMetadata, PublishableModel):
minimal_variant_price = MoneyField(
amount_field="minimal_variant_price_amount", currency_field="currency"
)
+
attributes = FilterableJSONBField(
default=dict, blank=True, validators=[validate_attribute_json]
)
@@ -353,7 +357,10 @@ class ProductVariant(ModelWithMetadata):
sku = models.CharField(max_length=32, unique=True)
name = models.CharField(max_length=255, blank=True)
currency = models.CharField(
- max_length=10, default=settings.DEFAULT_CURRENCY, blank=True, null=True
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ default=settings.DEFAULT_CURRENCY,
+ blank=True,
+ null=True,
)
price_override_amount = models.DecimalField(
max_digits=settings.DEFAULT_MAX_DIGITS,
diff --git a/saleor/settings.py b/saleor/settings.py
index 102e41ca9e..a2481f5c84 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -348,6 +348,7 @@ DEFAULT_COUNTRY = os.environ.get("DEFAULT_COUNTRY", "US")
DEFAULT_CURRENCY = os.environ.get("DEFAULT_CURRENCY", "USD")
DEFAULT_DECIMAL_PLACES = get_currency_fraction(DEFAULT_CURRENCY)
DEFAULT_MAX_DIGITS = 12
+DEFAULT_CURRENCY_CODE_LENGTH = 3
# note: having multiple currencies is not supported yet
AVAILABLE_CURRENCIES = [DEFAULT_CURRENCY]
diff --git a/saleor/shipping/migrations/0017_django_price_2.py b/saleor/shipping/migrations/0017_django_price_2.py
index 2da95095f0..dc92ff1abc 100644
--- a/saleor/shipping/migrations/0017_django_price_2.py
+++ b/saleor/shipping/migrations/0017_django_price_2.py
@@ -25,6 +25,9 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="shippingmethod",
name="currency",
- field=models.CharField(default=settings.DEFAULT_CURRENCY, max_length=10),
+ field=models.CharField(
+ default=settings.DEFAULT_CURRENCY,
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ ),
),
]
diff --git a/saleor/shipping/models.py b/saleor/shipping/models.py
index bee1451889..03366abac5 100644
--- a/saleor/shipping/models.py
+++ b/saleor/shipping/models.py
@@ -160,7 +160,10 @@ class ShippingMethodQueryset(models.QuerySet):
class ShippingMethod(models.Model):
name = models.CharField(max_length=100)
type = models.CharField(max_length=30, choices=ShippingMethodType.CHOICES)
- currency = models.CharField(max_length=10, default=settings.DEFAULT_CURRENCY)
+ currency = models.CharField(
+ max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,
+ default=settings.DEFAULT_CURRENCY,
+ )
price_amount = models.DecimalField(
max_digits=settings.DEFAULT_MAX_DIGITS,
decimal_places=settings.DEFAULT_DECIMAL_PLACES,
diff --git a/templates/checkout/shipping_method.html b/templates/checkout/shipping_method.html
index 3480777f15..58e8e085d2 100644
--- a/templates/checkout/shipping_method.html
+++ b/templates/checkout/shipping_method.html
@@ -12,7 +12,7 @@
</div>
<p>
<a class="text-uppercase" href="{% url 'checkout:shipping-address' %}">
- {% trans "Select another address" %}
+ {% trans "Select other address" %}
</a>
</p>
<hr>