Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
undo obselote avatax updates
Tomasz Szymanskif5d716484f08
diff --git a/saleor/graphql/checkout/tests/test_checkout_complete.py b/saleor/graphql/checkout/tests/test_checkout_complete.pyindex 450a010657..c2fb459a7d 100644--- a/saleor/graphql/checkout/tests/test_checkout_complete.py+++ b/saleor/graphql/checkout/tests/test_checkout_complete.py@@ -268,7 +268,7 @@ def test_checkout_complete_requires_confirmation()[1])order = Order.objects.get(pk=order_id)- assert order.status == OrderStatus.UNCONFIRMED+ assert order.is_unconfirmed()order_confirmed_mock.assert_not_called()diff --git a/saleor/graphql/invoice/mutations.py b/saleor/graphql/invoice/mutations.pyindex 0b1ceea4c1..d451840be4 100644--- a/saleor/graphql/invoice/mutations.py+++ b/saleor/graphql/invoice/mutations.py@@ -6,7 +6,6 @@ from ...core.permissions import OrderPermissionsfrom ...invoice import events, modelsfrom ...invoice.emails import send_invoicefrom ...invoice.error_codes import InvoiceErrorCode-from ...order import OrderStatusfrom ...order import events as order_eventsfrom ..core.mutations import ModelDeleteMutation, ModelMutationfrom ..core.types.common import InvoiceError@@ -35,7 +34,7 @@ class InvoiceRequest(ModelMutation):@staticmethoddef clean_order(order):- if order.status in (OrderStatus.DRAFT, OrderStatus.UNCONFIRMED):+ if order.is_draft() or order.is_unconfirmed():raise ValidationError({"orderId": ValidationError(@@ -121,7 +120,7 @@ class InvoiceCreate(ModelMutation):@classmethoddef clean_order(cls, info, order):- if order.status in (OrderStatus.DRAFT, OrderStatus.UNCONFIRMED):+ if order.is_draft() or order.is_unconfirmed():raise ValidationError({"orderId": ValidationError(diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.pyindex f2d0cd43bd..9c1542ad22 100644--- a/saleor/graphql/order/mutations/orders.py+++ b/saleor/graphql/order/mutations/orders.py@@ -551,7 +551,7 @@ class OrderConfirm(ModelMutation):@classmethoddef get_instance(cls, info, **data):instance = super().get_instance(info, **data)- if instance.status != OrderStatus.UNCONFIRMED:+ if not instance.is_unconfirmed():raise ValidationError({"id": ValidationError(@@ -636,8 +636,7 @@ class OrderLinesCreate(EditableOrderValidationMixin, BaseMutation):)quantity = input_line["quantity"]if quantity > 0:- if variant:- lines_to_add.append((quantity, variant))+ lines_to_add.append((quantity, variant))else:invalid_ids.append(variant_id)if invalid_ids:@@ -715,7 +714,7 @@ class OrderLineDelete(EditableOrderValidationMixin, BaseMutation):cls.validate_order(line.order)db_id = line.id- delete_order_line(info.context.plugins, line)+ delete_order_line(line)line.id = db_id# Create the removal event@@ -764,7 +763,7 @@ class OrderLineUpdate(EditableOrderValidationMixin, ModelMutation):@classmethoddef save(cls, info, instance, cleaned_input):change_order_line_quantity(- info.context, instance, instance.old_quantity, instance.quantity+ info.context.user, instance, instance.old_quantity, instance.quantity)recalculate_order(instance.order)diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.pyindex 0c5b8c7a3b..45060155ff 100644--- a/saleor/graphql/order/tests/test_order.py+++ b/saleor/graphql/order/tests/test_order.py@@ -792,7 +792,7 @@ def test_order_confirm_no_products_in_order(errors = content["orderErrors"]order_unconfirmed.refresh_from_db()- assert order_unconfirmed.status == OrderStatus.UNCONFIRMED+ assert order_unconfirmed.is_unconfirmed()assert content["order"] is Noneassert len(errors) == 1assert errors[0]["field"] == "id"diff --git a/saleor/order/models.py b/saleor/order/models.pyindex 6bab34de51..376135c8a5 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -307,6 +307,9 @@ class Order(ModelWithMetadata):def is_draft(self):return self.status == OrderStatus.DRAFT+ def is_unconfirmed(self):+ return self.status == OrderStatus.UNCONFIRMED+def is_open(self):statuses = {OrderStatus.UNFULFILLED, OrderStatus.PARTIALLY_FULFILLED}return self.status in statusesdiff --git a/saleor/order/tests/test_order.py b/saleor/order/tests/test_order.pyindex 3649cb4cf1..5ad5e25b4a 100644--- a/saleor/order/tests/test_order.py+++ b/saleor/order/tests/test_order.py@@ -582,11 +582,9 @@ def test_order_weight_add_new_variant(order_with_lines, product):def test_order_weight_change_line_quantity(staff_user, order_with_lines):- context_mock = Mock(user=staff_user)- context_mock.plugins.calculate_order_line_unit.return_value = Noneline = order_with_lines.lines.first()new_quantity = line.quantity + 2- change_order_line_quantity(context_mock, line, new_quantity, line.quantity)+ change_order_line_quantity(staff_user, line, new_quantity, line.quantity)order_with_lines.refresh_from_db()assert order_with_lines.weight == _calculate_order_weight_from_lines(order_with_lines@@ -594,10 +592,8 @@ def test_order_weight_change_line_quantity(staff_user, order_with_lines):def test_order_weight_delete_line(order_with_lines):- context_mock = Mock()- context_mock.plugins.calculate_order_line_unit.return_value = Noneline = order_with_lines.lines.first()- delete_order_line(context_mock, line)+ delete_order_line(line)assert order_with_lines.weight == _calculate_order_weight_from_lines(order_with_lines)@@ -877,24 +873,20 @@ def test_category_voucher_checkout_discount_raises_not_applicable(def test_ordered_item_change_quantity(staff_user, transactional_db, order_with_lines):- context_mock = Mock(user=staff_user)- context_mock.plugins.calculate_order_line_unit.return_value = Noneassert not order_with_lines.events.count()lines = order_with_lines.lines.all()- change_order_line_quantity(context_mock, lines[1], lines[1].quantity, 0)- change_order_line_quantity(context_mock, lines[0], lines[0].quantity, 0)+ change_order_line_quantity(staff_user, lines[1], lines[1].quantity, 0)+ change_order_line_quantity(staff_user, lines[0], lines[0].quantity, 0)assert order_with_lines.get_total_quantity() == 0def test_change_order_line_quantity_changes_total_prices(staff_user, transactional_db, order_with_lines):- context_mock = Mock(user=staff_user)- context_mock.plugins.calculate_order_line_unit.return_value = Noneassert not order_with_lines.events.count()line = order_with_lines.lines.all()[0]new_quantity = line.quantity + 1- change_order_line_quantity(context_mock, line, line.quantity, new_quantity)+ change_order_line_quantity(staff_user, line, line.quantity, new_quantity)line.refresh_from_db()assert line.total_price == line.unit_price * new_quantitydiff --git a/saleor/order/tests/test_order_utils.py b/saleor/order/tests/test_order_utils.pyindex 7b0e8042da..f1642e1b3b 100644--- a/saleor/order/tests/test_order_utils.py+++ b/saleor/order/tests/test_order_utils.py@@ -1,5 +1,3 @@-from unittest.mock import Mock-import pytestfrom .. import OrderStatus@@ -26,9 +24,6 @@ def test_change_quantity_generates_proper_event(order_with_lines,staff_user,):- context_mock = Mock(user=staff_user)- context_mock.plugins.calculate_order_line_unit.return_value = None-assert not OrderEvent.objects.exists()order_with_lines.status = statusorder_with_lines.save(update_fields=["status"])@@ -36,7 +31,7 @@ def test_change_quantity_generates_proper_event(line = order_with_lines.lines.last()line.quantity = previous_quantity- change_order_line_quantity(context_mock, line, previous_quantity, new_quantity)+ change_order_line_quantity(staff_user, line, previous_quantity, new_quantity)if removed_count:expected_type = OrderEvents.REMOVED_PRODUCTSdiff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex abadc335e6..e219cbb7f6 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -364,19 +364,12 @@ def add_gift_card_to_order(order, gift_card, total_price_left):return total_price_left-def change_order_line_quantity(context, line, old_quantity, new_quantity):+def change_order_line_quantity(user, line, old_quantity, new_quantity):"""Change the quantity of ordered items in a order line."""if new_quantity:line.quantity = new_quantity- line.save(update_fields=["quantity"])- net = line.unit_price.net.amount- unit_price = context.plugins.calculate_order_line_unit(- line.order, line, line.variant, line.variant.product- )- if unit_price is not None:- net = unit_price.net.amount- total_price_net_amount = net * line.quantity- total_price_gross_amount = line.unit_price.gross.amount * line.quantity+ total_price_net_amount = line.quantity * line.unit_price_net_amount+ total_price_gross_amount = line.quantity * line.unit_price_gross_amountline.total_price_net_amount = total_price_net_amount.quantize(Decimal("0.001"))line.total_price_gross_amount = total_price_gross_amount.quantize(Decimal("0.001")@@ -384,33 +377,29 @@ def change_order_line_quantity(context, line, old_quantity, new_quantity):line.save(update_fields=["quantity",- "tax_rate","total_price_net_amount","total_price_gross_amount",])else:- delete_order_line(context.plugins, line)+ delete_order_line(line)quantity_diff = old_quantity - new_quantity- # Create the added / removed products event+ # Create the removal eventif quantity_diff > 0:events.order_removed_products_event(- order=line.order, user=context.user, order_lines=[(quantity_diff, line)]+ order=line.order, user=user, order_lines=[(quantity_diff, line)])elif quantity_diff < 0:events.order_added_products_event(- order=line.order,- user=context.user,- order_lines=[(quantity_diff * -1, line)],+ order=line.order, user=user, order_lines=[(quantity_diff * -1, line)])-def delete_order_line(manager, line):+def delete_order_line(line):"""Delete an order line from an order."""line.delete()- manager.order_line_deleted(line.order, line)def restock_order_lines(order):diff --git a/saleor/plugins/avatax/__init__.py b/saleor/plugins/avatax/__init__.pyindex bebfa7ebde..c0ecfdd75a 100644--- a/saleor/plugins/avatax/__init__.py+++ b/saleor/plugins/avatax/__init__.py@@ -443,7 +443,9 @@ def get_order_request_data(order: "Order", config: AvataxConfiguration):address = order.shipping_address or order.billing_addresslines = get_order_lines_data(order)transaction = (- TransactionType.INVOICE if not order.is_draft() else TransactionType.ORDER+ TransactionType.INVOICE+ if not (order.is_draft() or order.is_unconfirmed())+ else TransactionType.ORDER)data = generate_request_data(transaction_type=transaction,diff --git a/saleor/plugins/base_plugin.py b/saleor/plugins/base_plugin.pyindex 078b7f3ee8..492bb61c95 100644--- a/saleor/plugins/base_plugin.py+++ b/saleor/plugins/base_plugin.py@@ -505,16 +505,6 @@ class BasePlugin:"""return NotImplemented- def order_line_deleted(- self, order: "Order", order_line: "OrderLine", previous_value: Any- ) -> Any:- """Trigger after order line is deleted.-- Overwrite this method if you need to trigger specific logic after an order line is- deleted.- """- return NotImplemented-def fulfillment_created(self, fulfillment: "Fulfillment", previous_value: Any) -> Any: