Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Clean up code
Mateusz Grzybd243001accbc
diff --git a/saleor/payment/gateways/np_atobarai/tests/conftest.py b/saleor/payment/gateways/np_atobarai/tests/conftest.pyindex 6919a2cb7e..bbd028c1c6 100644--- a/saleor/payment/gateways/np_atobarai/tests/conftest.py+++ b/saleor/payment/gateways/np_atobarai/tests/conftest.py@@ -131,9 +131,6 @@ def create_refund(payment_dummy):manual_refund_amount=None,refund_shipping_costs=False,):- # payment_dummy.captured_amount = order.total_gross_amount- # payment_dummy.save(update_fields=["captured_amount"])-with patch("saleor.order.actions.gateway.refund"):return create_refund_fulfillment(user=None,diff --git a/saleor/payment/gateways/np_atobarai/tests/test_api_helpers.py b/saleor/payment/gateways/np_atobarai/tests/test_api_helpers.pyindex 06a6f136a1..13a0cb9ecd 100644--- a/saleor/payment/gateways/np_atobarai/tests/test_api_helpers.py+++ b/saleor/payment/gateways/np_atobarai/tests/test_api_helpers.py@@ -5,8 +5,7 @@ from unittest.mock import DEFAULT, Mock, patch, sentinelimport pytestfrom posuto import Posuto-from saleor.order.fetch import OrderLineInfo-+from .....order.fetch import OrderLineInfofrom ....interface import AddressData, RefundDatafrom ....utils import price_to_minor_unitfrom .. import api_helpers, errorsdiff --git a/saleor/payment/gateways/np_atobarai/tests/test_utils.py b/saleor/payment/gateways/np_atobarai/tests/test_utils.pyindex a59dc18b7d..34a8f0d68c 100644--- a/saleor/payment/gateways/np_atobarai/tests/test_utils.py+++ b/saleor/payment/gateways/np_atobarai/tests/test_utils.py@@ -146,7 +146,7 @@ def test_get_shipping_company_code_invalid_metadata(assert shipping_company_code == config_shipping_company_code-def test_create_refund_lines_order_lines(order_with_lines):+def test_create_refunded_lines_order_lines(order_with_lines):# givenorder_lines = order_with_lines.lines.all()order_refund_lines = [@@ -169,7 +169,7 @@ def test_create_refund_lines_order_lines(order_with_lines):assert lines == {line.line.variant_id: line.quantity for line in order_refund_lines}-def test_create_refund_lines_fulfillment_lines(fulfilled_order):+def test_create_refunded_lines_fulfillment_lines(fulfilled_order):# givenfulfillment_lines = list(fulfilled_order.fulfillments.first().lines.all())order_refund_lines = []@@ -203,7 +203,7 @@ def test_create_refund_lines_fulfillment_lines(fulfilled_order):@patch("saleor.order.actions.gateway.refund")@pytest.mark.parametrize("previous_refund_shipping_costs", [True, False])-def test_create_refund_data_previously_refunded_order_lines(+def test_create_refunded_lines_previously_refunded_order_lines(_mocked_refund,order_with_lines,create_refund,@@ -249,7 +249,7 @@ def test_create_refund_data_previously_refunded_order_lines(@patch("saleor.order.actions.gateway.refund")@pytest.mark.parametrize("previous_refund_shipping_costs", [True, False])-def test_create_refund_data_previously_refunded_fulfillment_lines(+def test_create_refunded_lines_previously_refunded_fulfillment_lines(_mocked_refund,fulfilled_order,create_refund,@@ -302,119 +302,3 @@ def test_create_refund_data_previously_refunded_fulfillment_lines(line.line.order_line.variant_id: line.quantityfor line in fulfillment_refund_lines}---# @pytest.mark.parametrize(-# [-# "current_refund_amount",-# "shipping_amount",-# "refund_shipping",-# "is_manual",-# "order_lines",-# "fulfillment_lines",-# "expected_manual_amount",-# ],-# [-# (None, Decimal("40.00"), False, False, [], [], Decimal("0.00")),-# (Decimal("12.34"), Decimal("40.00"), False, False, [], [], Decimal("12.34")),-# (None, Decimal("40.00"), True, True, [], [], Decimal("40.00")),-# (-# Decimal("12.34"),-# Decimal("40.00"),-# False,-# False,-# [Mock()],-# [],-# Decimal("0.00"),-# ),-# (-# Decimal("12.34"),-# Decimal("40.00"),-# False,-# False,-# [],-# [Mock()],-# Decimal("0.00"),-# ),-# ],-# )-# def test_calculate_refund_amount(-# order,-# current_refund_amount,-# shipping_amount,-# refund_shipping,-# is_manual,-# order_lines,-# fulfillment_lines,-# expected_manual_amount,-# ):-# # given-# payment_information = Mock(-# amount=current_refund_amount,-# lines_data=Mock(-# shipping_amount=shipping_amount,-# ),-# )-# refund_data = Mock(-# refund_shipping_costs=refund_shipping,-# refund_is_automatically_calculated=not is_manual,-# order_lines_to_refund=order_lines,-# fulfillment_lines_to_refund=fulfillment_lines,-# )-#-# # when-# amount = calculate_manual_refund_amount(order, payment_information, refund_data)-#-# # then-# assert amount == expected_manual_amount---# @pytest.mark.parametrize(-# [-# "previous_manual_refund_amount",-# "current_refund_amount",-# "refund_shipping",-# "expected_refund_amount",-# ],-# [-# (None, None, False, Decimal("0.00")),-# (None, None, True, Decimal("12.30")),-# (None, Decimal("8.00"), False, Decimal("8.00")),-# (None, Decimal("8.00"), True, Decimal("20.30")),-# (Decimal("5.00"), None, False, Decimal("5.00")),-# (Decimal("5.00"), None, True, Decimal("17.30")),-# (Decimal("5.00"), Decimal("8.00"), False, Decimal("13.00")),-# (Decimal("5.00"), Decimal("8.00"), True, Decimal("25.30")),-# ],-# )-# def test_calculate_manual_refund_amount_previously_refunded(-# order,-# create_refund,-# previous_manual_refund_amount,-# current_refund_amount,-# refund_shipping,-# expected_refund_amount,-# ):-# # given-# if previous_manual_refund_amount:-# create_refund(order, manual_refund_amount=previous_manual_refund_amount)-# if refund_shipping:-# create_refund(-# order,-# refund_shipping_costs=refund_shipping,-# )-#-# refund_data = Mock(-# refund_shipping_costs=False,-# refund_is_automatically_calculated=False,-# order_lines_to_refund=[],-# fulfillment_lines_to_refund=[],-# )-# payment_information = Mock(amount=current_refund_amount)-#-# # when-# refund_amount = calculate_manual_refund_amount(-# order, payment_information, refund_data-# )-# # then-# assert refund_amount == expected_refund_amountdiff --git a/saleor/payment/gateways/np_atobarai/utils.py b/saleor/payment/gateways/np_atobarai/utils.pyindex 968b33ecb8..9e8e89ab31 100644--- a/saleor/payment/gateways/np_atobarai/utils.py+++ b/saleor/payment/gateways/np_atobarai/utils.py@@ -68,6 +68,14 @@ def np_atobarai_opentracing_trace(span_name: str):yield+_FULFILLMENT_LINE_HAS_MANUAL_AMOUNT_EXPRESSION = CombinedExpression(+ F("fulfillment__total_refund_amount") % F("order_line__unit_price_gross_amount"),+ "!=",+ Value(0),+ output_field=BooleanField(),+)++def create_refunded_lines(order: Order,refund_data: RefundData,@@ -87,15 +95,7 @@ def create_refunded_lines(# Refund fulfillments for product refunds with automatic amountprevious_fulfillment_lines = (FulfillmentLine.objects.prefetch_related("order_line")- .annotate(- has_manual_amount=CombinedExpression(- F("fulfillment__total_refund_amount")- % F("order_line__unit_price_gross_amount"),- "!=",- Value(0),- output_field=BooleanField(),- )- )+ .annotate(has_manual_amount=_FULFILLMENT_LINE_HAS_MANUAL_AMOUNT_EXPRESSION).filter(fulfillment__order_id=order.pk,fulfillment__status__in=[@@ -136,59 +136,3 @@ def create_refunded_lines(summed_refund_lines[variant_id] += quantityreturn dict(summed_refund_lines)---# def calculate_manual_refund_amount(-# order: Order,-# payment_information: PaymentData,-# refund_data: RefundData,-# ) -> Decimal:-# """Return sum of all manual refunds for specified order.-#-# Takes into account previous refunds and current refund mutation amount.-# """-# if (-# refund_data.order_lines_to_refund or refund_data.fulfillment_lines_to_refund-# ) and refund_data.refund_amount_is_automatically_calculated:-# # automatic line refund-# manual_amount_to_refund = Decimal("0.00")-# elif (-# refund_data.refund_shipping_costs-# and refund_data.refund_amount_is_automatically_calculated-# ):-# # automatic shipping refund-# manual_amount_to_refund = payment_information.lines_data.shipping_amount-# else:-# # manual refund-# manual_amount_to_refund = payment_information.amount or Decimal("0.00")-#-# # Sum of all previous manual refunds-# previous_manual_amount_to_refund = (-# order.fulfillments.annotate(-# has_manual_amount=CombinedExpression(-# lhs=F("total_refund_amount")-# % F("lines__order_line__unit_price_gross_amount"),-# connector="!=",-# rhs=Value(0),-# output_field=BooleanField(),-# )-# )-# .filter(-# Q(-# # Misc refunds-# lines__isnull=True,-# )-# | Q(-# # Product refunds with manual amount-# lines__isnull=False,-# has_manual_amount=True,-# ),-# status__in=[-# FulfillmentStatus.REFUNDED,-# FulfillmentStatus.REFUNDED_AND_RETURNED,-# ],-# )-# .aggregate(manual_amount=Sum("total_refund_amount"))["manual_amount"]-# or Decimal("0.00")-# )-# return previous_manual_amount_to_refund + manual_amount_to_refund