Skip to content

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

Remove gettext occurrences from order

IKarbowiak8471ffd11012
diff --git a/saleor/graphql/order/mutations/fulfillments.py b/saleor/graphql/order/mutations/fulfillments.py
index 7e004362d9..3e158dae20 100644
--- a/saleor/graphql/order/mutations/fulfillments.py
+++ b/saleor/graphql/order/mutations/fulfillments.py
@@ -1,6 +1,6 @@
import graphene
from django.core.exceptions import ValidationError
-from django.utils.translation import npgettext_lazy, pgettext_lazy
+from django.template.defaultfilters import pluralize
from ....core.permissions import OrderPermissions
from ....order import models
@@ -104,14 +104,14 @@ class FulfillmentCreate(BaseMutation):
@classmethod
def clean_lines(cls, order_lines, quantities):
for order_line, quantity in zip(order_lines, quantities):
- if quantity > order_line.quantity_unfulfilled:
- msg = npgettext_lazy(
- "Fulfill order line mutation error",
- "Only %(quantity)d item remaining to fulfill: %(order_line)s.",
- "Only %(quantity)d items remaining to fulfill: %(order_line)s.",
- number="quantity",
+ line_quantity_unfulfilled = order_line.quantity_unfulfilled
+ if quantity > line_quantity_unfulfilled:
+ msg = (
+ "Only %(quantity)d item%(item_pluralize)s remaining"
+ "to fulfill: %(order_line)s."
) % {
- "quantity": order_line.quantity_unfulfilled,
+ "quantity": line_quantity_unfulfilled,
+ "item_pluralize": pluralize(line_quantity_unfulfilled),
"order_line": order_line,
}
raise ValidationError(
@@ -241,10 +241,7 @@ class FulfillmentCancel(BaseMutation):
fulfillment = cls.get_node_or_error(info, data.get("id"), only_type=Fulfillment)
if not fulfillment.can_edit():
- err_msg = pgettext_lazy(
- "Cancel fulfillment mutation error",
- "This fulfillment can't be canceled",
- )
+ err_msg = "This fulfillment can't be canceled"
raise ValidationError(
{
"fulfillment": ValidationError(
diff --git a/saleor/order/__init__.py b/saleor/order/__init__.py
index 79f6f0d614..30b7055ae2 100644
--- a/saleor/order/__init__.py
+++ b/saleor/order/__init__.py
@@ -1,68 +1,28 @@
-from django.utils.translation import pgettext_lazy
-
-
class OrderStatus:
- DRAFT = "draft"
- UNFULFILLED = "unfulfilled"
- PARTIALLY_FULFILLED = "partially fulfilled"
- FULFILLED = "fulfilled"
- CANCELED = "canceled"
+ DRAFT = "draft" # fully editable, not confirmed order created by staff users
+ UNFULFILLED = "unfulfilled" # order with no items marked as fulfilled
+ PARTIALLY_FULFILLED = (
+ "partially fulfilled" # order with some items marked as fulfilled
+ )
+ FULFILLED = "fulfilled" # order with all items marked as fulfilled
+ CANCELED = "canceled" # permanently canceled order
CHOICES = [
- (
- DRAFT,
- pgettext_lazy(
- "Status for a fully editable, not confirmed order created by "
- "staff users",
- "Draft",
- ),
- ),
- (
- UNFULFILLED,
- pgettext_lazy(
- "Status for an order with no items marked as fulfilled", "Unfulfilled"
- ),
- ),
- (
- PARTIALLY_FULFILLED,
- pgettext_lazy(
- "Status for an order with some items marked as fulfilled",
- "Partially fulfilled",
- ),
- ),
- (
- FULFILLED,
- pgettext_lazy(
- "Status for an order with all items marked as fulfilled", "Fulfilled"
- ),
- ),
- (
- CANCELED,
- pgettext_lazy("Status for a permanently canceled order", "Canceled"),
- ),
+ (DRAFT, "Draft"),
+ (UNFULFILLED, "Unfulfilled"),
+ (PARTIALLY_FULFILLED, "Partially fulfilled"),
+ (FULFILLED, "Fulfilled"),
+ (CANCELED, "Canceled"),
]
class FulfillmentStatus:
- FULFILLED = "fulfilled"
- CANCELED = "canceled"
+ FULFILLED = "fulfilled" # group of products in an order marked as fulfilled
+ CANCELED = "canceled" # fulfilled group of products in an order marked as canceled
CHOICES = [
- (
- FULFILLED,
- pgettext_lazy(
- "Status for a group of products in an order marked as fulfilled",
- "Fulfilled",
- ),
- ),
- (
- CANCELED,
- pgettext_lazy(
- "Status for a fulfilled group of products in an order marked "
- "as canceled",
- "Canceled",
- ),
- ),
+ (FULFILLED, "Fulfilled"),
+ (CANCELED, "Canceled"),
]
@@ -101,159 +61,27 @@ class OrderEvents:
OTHER = "other"
CHOICES = [
- (
- DRAFT_CREATED,
- pgettext_lazy(
- "Event from a staff user that created a draft order",
- "The draft order was created",
- ),
- ),
- (
- DRAFT_ADDED_PRODUCTS,
- pgettext_lazy(
- "Event from a staff user that added products to a draft order",
- "Some products were added to the draft order",
- ),
- ),
- (
- DRAFT_REMOVED_PRODUCTS,
- pgettext_lazy(
- "Event from a staff user that removed products from a draft order",
- "Some products were removed from the draft order",
- ),
- ),
- (
- PLACED,
- pgettext_lazy(
- "Event from a user or anonymous user that placed their order",
- "The order was placed",
- ),
- ),
- (
- PLACED_FROM_DRAFT,
- pgettext_lazy(
- "Event from a staff user that placed a draft order",
- "The draft order was placed",
- ),
- ),
- (
- OVERSOLD_ITEMS,
- pgettext_lazy(
- "Event from a staff user that placed a draft order by passing "
- "oversold items",
- "The draft order was placed with oversold items",
- ),
- ),
- (
- CANCELED,
- pgettext_lazy(
- "Event from a staff user that canceled an order",
- "The order was canceled",
- ),
- ),
- (
- ORDER_MARKED_AS_PAID,
- pgettext_lazy(
- "Event from a staff user that manually marked an order as "
- "fully paid",
- "The order was manually marked as fully paid",
- ),
- ),
- (
- ORDER_FULLY_PAID,
- pgettext_lazy(
- "Event from a payment that made the order to be fully paid",
- "The order was fully paid",
- ),
- ),
- (
- UPDATED_ADDRESS,
- pgettext_lazy(
- "Event from a staff user that updated an address of a " "placed order",
- "The address from the placed order was updated",
- ),
- ),
- (
- EMAIL_SENT,
- pgettext_lazy(
- "Event generated from a user action that led to a " "email being sent",
- "The email was sent",
- ),
- ),
- (
- PAYMENT_CAPTURED,
- pgettext_lazy(
- "Event from a user payment that successfully captured a "
- "given amount of money",
- "The payment was captured",
- ),
- ),
- (
- PAYMENT_REFUNDED,
- pgettext_lazy(
- "Event from a staff user that successfully refunded a payment",
- "The payment was refunded",
- ),
- ),
- (
- PAYMENT_VOIDED,
- pgettext_lazy(
- "Event from a staff user that successfully voided an "
- "authorized payment",
- "The payment was voided",
- ),
- ),
- (
- PAYMENT_FAILED,
- pgettext_lazy(
- "Event from a user that generated an unsuccessful payment",
- "The payment was failed",
- ),
- ),
- (
- FULFILLMENT_CANCELED,
- pgettext_lazy(
- "Event from a staff user that canceled a fulfillment",
- "A fulfillment was canceled",
- ),
- ),
- (
- FULFILLMENT_RESTOCKED_ITEMS,
- pgettext_lazy(
- "Event from a staff user that restocked the items that were used "
- "for a fulfillment",
- "The items of the fulfillment were restocked",
- ),
- ),
- (
- FULFILLMENT_FULFILLED_ITEMS,
- pgettext_lazy(
- "Event from a staff user that fulfilled some items",
- "Some items were fulfilled",
- ),
- ),
- (
- TRACKING_UPDATED,
- pgettext_lazy(
- "Event from a staff user that updated the tracking code of an "
- "existing fulfillment",
- "The fulfillment's tracking code was updated",
- ),
- ),
- (
- NOTE_ADDED,
- pgettext_lazy(
- "Event from an user that added a note to an order",
- "A note was added to the order",
- ),
- ),
- (
- OTHER,
- pgettext_lazy(
- "An other type of order event containing a message",
- "An unknown order event containing a message",
- ),
- ),
+ (DRAFT_CREATED, "The draft order was created"),
+ (DRAFT_ADDED_PRODUCTS, "Some products were added to the draft order"),
+ (DRAFT_REMOVED_PRODUCTS, "Some products were removed from the draft order"),
+ (PLACED, "The order was placed"),
+ (PLACED_FROM_DRAFT, "The draft order was placed"),
+ (OVERSOLD_ITEMS, "The draft order was placed with oversold items"),
+ (CANCELED, "The order was canceled"),
+ (ORDER_MARKED_AS_PAID, "The order was manually marked as fully paid"),
+ (ORDER_FULLY_PAID, "The order was fully paid"),
+ (UPDATED_ADDRESS, "The address from the placed order was updated"),
+ (EMAIL_SENT, "The email was sent"),
+ (PAYMENT_CAPTURED, "The payment was captured"),
+ (PAYMENT_REFUNDED, "The payment was refunded"),
+ (PAYMENT_VOIDED, "The payment was voided"),
+ (PAYMENT_FAILED, "The payment was failed"),
+ (FULFILLMENT_CANCELED, "A fulfillment was canceled"),
+ (FULFILLMENT_RESTOCKED_ITEMS, "The items of the fulfillment were restocked"),
+ (FULFILLMENT_FULFILLED_ITEMS, "Some items were fulfilled"),
+ (TRACKING_UPDATED, "The fulfillment's tracking code was updated"),
+ (NOTE_ADDED, "A note was added to the order"),
+ (OTHER, "An unknown order event containing a message"),
]
@@ -268,46 +96,10 @@ class OrderEventsEmails:
DIGITAL_LINKS = "digital_links"
CHOICES = [
- (
- PAYMENT,
- pgettext_lazy(
- "A payment confirmation email was sent",
- "The payment confirmation email was sent",
- ),
- ),
- (
- SHIPPING,
- pgettext_lazy(
- "A shipping confirmation email was sent",
- "The shipping confirmation email was sent",
- ),
- ),
- (
- TRACKING_UPDATED,
- pgettext_lazy(
- "A tracking code update confirmation email was sent",
- "The fulfillment tracking code email was sent",
- ),
- ),
- (
- ORDER,
- pgettext_lazy(
- "A order confirmation email was sent",
- "The order placement confirmation email was sent",
- ),
- ),
- (
- FULFILLMENT,
- pgettext_lazy(
- "A fulfillment confirmation email was sent",
- "The fulfillment confirmation email was sent",
- ),
- ),
- (
- DIGITAL_LINKS,
- pgettext_lazy(
- "An email containing a or some digital link was sent",
- "The email containing the digital links was sent",
- ),
- ),
+ (PAYMENT, "The payment confirmation email was sent"),
+ (SHIPPING, "The shipping confirmation email was sent"),
+ (TRACKING_UPDATED, "The fulfillment tracking code email was sent"),
+ (ORDER, "The order placement confirmation email was sent"),
+ (FULFILLMENT, "The fulfillment confirmation email was sent"),
+ (DIGITAL_LINKS, "The email containing the digital links was sent"),
]
diff --git a/saleor/order/actions.py b/saleor/order/actions.py
index 7a21075973..3b9c6469ef 100644
--- a/saleor/order/actions.py
+++ b/saleor/order/actions.py
@@ -3,7 +3,6 @@ from decimal import Decimal
from typing import TYPE_CHECKING, List
from django.db import transaction
-from django.utils.translation import pgettext_lazy
from ..core import analytics
from ..extensions.manager import get_extensions_manager
@@ -207,12 +206,7 @@ def mark_order_as_paid(order: "Order", request_user: "User"):
def clean_mark_order_as_paid(order: "Order"):
"""Check if an order can be marked as paid."""
if order.payments.exists():
- raise PaymentError(
- pgettext_lazy(
- "Mark order as paid validation error",
- "Orders with payments can not be manually marked as paid.",
- )
- )
+ raise PaymentError("Orders with payments can not be manually marked as paid.",)
def fulfill_order_line(order_line, quantity):
diff --git a/saleor/order/models.py b/saleor/order/models.py
index 62f7e6bb1e..d0b98f2cc7 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -9,7 +9,6 @@ from django.core.validators import MinValueValidator
from django.db import models
from django.db.models import F, Max, Sum
from django.utils.timezone import now
-from django.utils.translation import pgettext_lazy
from django_measurement.models import MeasurementField
from django_prices.models import MoneyField, TaxedMoneyField
from measurement.measures import Weight
@@ -173,12 +172,7 @@ class Order(ModelWithMetadata):
class Meta:
ordering = ("-pk",)
- permissions = (
- (
- OrderPermissions.MANAGE_ORDERS.codename,
- pgettext_lazy("Permission description", "Manage orders."),
- ),
- )
+ permissions = ((OrderPermissions.MANAGE_ORDERS.codename, "Manage orders."),)
def save(self, *args, **kwargs):
if not self.token:
@@ -440,7 +434,7 @@ class Fulfillment(ModelWithMetadata):
created = models.DateTimeField(auto_now_add=True)
def __str__(self):
- return pgettext_lazy("Fulfillment str", "Fulfillment #%s") % (self.composed_id,)
+ return f"Fulfillment #{self.composed_id}"
def __iter__(self):
return iter(self.lines.all())
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index 67eb08c1a1..9f3c93c8cd 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -3,7 +3,6 @@ from functools import wraps
from django.conf import settings
from django.db import transaction
from django.utils import timezone
-from django.utils.translation import pgettext
from prices import Money, TaxedMoney
from ..core.taxes import zero_money
@@ -313,9 +312,7 @@ def get_products_voucher_discount_for_order(voucher: Voucher) -> Money:
"""Calculate products discount value for a voucher, depending on its type."""
prices = None
if not prices:
- msg = pgettext(
- "Voucher not applicable", "This offer is only valid for selected items."
- )
+ msg = "This offer is only valid for selected items."
raise NotApplicable(msg)
return get_products_voucher_discount(voucher, prices)