Repository: saleor/saleor

Issue:
Bug: [Simple Taxes] Add Discount to an order is not working
### What are you trying to achieve?

When staff admin tries to add discount to drafOrder then nothing is changed.

### Steps to reproduce the problem

1. turn on flax rate in selected channel
2.create draftOrder (select product, user &shippingMethod)
3.Try to Add Discount to whole order.

### What did you expect to happen?

Discount should be added and totalPrice should be reduce.

### Logs

![image](https://user-images.githubusercontent.com/29308910/196668741-2e1d0fa8-6987-4c53-8e12-57bf36395975.png)


### Environment

Saleor version: …
OS and version: …



Discussion:

Resolving patch:
diff --git a/saleor/tax/calculations/checkout.py b/saleor/tax/calculations/checkout.py
--- a/saleor/tax/calculations/checkout.py
+++ b/saleor/tax/calculations/checkout.py
@@ -83,24 +83,13 @@ def calculate_checkout_shipping(
     tax_rate: Decimal,
     prices_entered_with_tax: bool,
 ) -> TaxedMoney:
-    default_price = base_calculations.base_checkout_delivery_price(checkout_info, lines)
-    shipping_price = getattr(
-        checkout_info.delivery_method_info.delivery_method,
-        "price",
-        default_price,
+    shipping_price = base_calculations.base_checkout_delivery_price(
+        checkout_info, lines
     )
-    voucher = checkout_info.voucher
-    is_shipping_discount = voucher.type == VoucherType.SHIPPING if voucher else False
-    if is_shipping_discount:
-        shipping_price = max(
-            shipping_price - checkout_info.checkout.discount,
-            zero_money(shipping_price.currency),
-        )
-
-    shipping_price = calculate_flat_rate_tax(
+    shipping_price_taxed = calculate_flat_rate_tax(
         shipping_price, tax_rate, prices_entered_with_tax
     )
-    return quantize_price(shipping_price, shipping_price.currency)
+    return quantize_price(shipping_price_taxed, shipping_price_taxed.currency)
 
 
 def calculate_checkout_line_total(
diff --git a/saleor/tax/calculations/order.py b/saleor/tax/calculations/order.py
--- a/saleor/tax/calculations/order.py
+++ b/saleor/tax/calculations/order.py
@@ -49,6 +49,11 @@ def update_order_prices_with_flat_rates(
     order.shipping_tax_rate = normalize_tax_rate_for_db(shipping_tax_rate)
 
     # Calculate order total.
+    undiscounted_subtotal = sum(
+        [line.undiscounted_total_price for line in lines],
+        zero_taxed_money(order.currency),
+    )
+    order.undiscounted_total = undiscounted_subtotal + order.shipping_price
     order.total = _calculate_order_total(order, lines)
 
 
@@ -70,8 +75,6 @@ def _calculate_order_total(
         undiscounted_subtotal += line.undiscounted_total_price
     total += order.shipping_price
 
-    # Vatlayer doesn't propagate order discount to shipping we should include
-    # remaining amount in total calculation.
     order_discount = order.discounts.filter(type=OrderDiscountType.MANUAL).first()
     if order_discount and order_discount.amount > undiscounted_subtotal.gross:
         remaining_amount = order_discount.amount - undiscounted_subtotal.gross


Test patch:
diff --git a/saleor/tax/tests/test_order_calculations.py b/saleor/tax/tests/test_order_calculations.py
--- a/saleor/tax/tests/test_order_calculations.py
+++ b/saleor/tax/tests/test_order_calculations.py
@@ -34,6 +34,9 @@ def test_calculations_calculate_order_total(order_with_lines):
     update_order_prices_with_flat_rates(order, lines, prices_entered_with_tax)
 
     # then
+    assert order.undiscounted_total == TaxedMoney(
+        net=Money("65.04", "USD"), gross=Money("80.00", "USD")
+    )
     assert order.total == TaxedMoney(
         net=Money("65.04", "USD"), gross=Money("80.00", "USD")
     )