Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
More intuitive address edition
Anna Siwik750c7a5a4b65
diff --git a/saleor/dashboard/order/utils.py b/saleor/dashboard/order/utils.pyindex 521d0c50fa..219936ce4d 100644--- a/saleor/dashboard/order/utils.py+++ b/saleor/dashboard/order/utils.py@@ -146,3 +146,19 @@ def get_voucher_discount_for_order(order):if order.voucher.type in (VoucherType.PRODUCT, VoucherType.CATEGORY):return _get_product_or_category_voucher_discount_for_order(order)raise NotImplementedError('Unknown discount type')+++def save_address_in_order(order, address, address_type):+ """Save new address of a given address type in an order.++ If the other type of address is empty, copy it.+ """+ if address_type == 'shipping':+ order.shipping_address = address+ if not order.billing_address:+ order.billing_address = address.get_copy()+ else:+ order.billing_address = address+ if not order.shipping_address:+ order.shipping_address = address.get_copy()+ order.save(update_fields=['billing_address', 'shipping_address'])diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex 3fd80518e3..f5339e552a 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -35,7 +35,8 @@ from .forms import (OrderRemoveVoucherForm, OrderShippingForm, RefundPaymentForm,ReleasePaymentForm)from .utils import (- create_invoice_pdf, create_packing_slip_pdf, get_statics_absolute_url)+ create_invoice_pdf, create_packing_slip_pdf, get_statics_absolute_url,+ save_address_in_order)@staff_member_required@@ -325,12 +326,8 @@ def address_view(request, order_pk, address_type):form = AddressForm(request.POST or None, instance=address)if form.is_valid():updated_address = form.save()- if address is None:- if address_type == 'shipping':- order.shipping_address = updated_address- else:- order.billing_address = updated_address- order.save()+ if not address:+ save_address_in_order(order, updated_address, address_type)order.history.create(content=success_msg, user=request.user)messages.success(request, success_msg)return redirect('dashboard:order-details', order_pk=order_pk)diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.htmlindex 11ccc2d926..d868cc8188 100644--- a/templates/dashboard/order/detail.html+++ b/templates/dashboard/order/detail.html@@ -234,7 +234,11 @@{% endif %}</span>{% if order.billing_address %}- {% format_address order.billing_address %}+ {% if order.billing_address == order.shipping_address %}+ {% trans "Same as shipping address" context "Order billing address same as shipping address" %}+ {% else %}+ {% format_address order.billing_address %}+ {% endif %}{% else %}{% trans "No billing address" context "Missing billing address message" %}{% endif %}