Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix tests and styling
Anna Siwik2c5d07cd1db8
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex b45c827d04..17dfdeccca 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -131,8 +131,6 @@ class ChangeQuantityForm(forms.ModelForm):super().__init__(*args, **kwargs)self.initial_quantity = self.instance.quantityself.fields['quantity'].initial = self.initial_quantity- self.fields['quantity'].widget.attrs['min'] = (- self.instance.quantity_fulfilled)def clean_quantity(self):quantity = self.cleaned_data['quantity']@@ -147,14 +145,6 @@ class ChangeQuantityForm(forms.ModelForm):'remaining') % {'remaining': (self.initial_quantity + stock.quantity_available)})- if quantity < self.instance.quantity_fulfilled:- raise forms.ValidationError(- npgettext_lazy(- 'Change quantity form error',- '%(quantity)d is already fulfilled.',- '%(quantity)d are already fulfilled.',- 'quantity') % {- 'quantity': self.instance.quantity_fulfilled})return quantitydef save(self):diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex 691ccd7c38..1694cbafab 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -1,6 +1,5 @@from functools import wraps-from django.conf import settingsfrom django.db.models import Ffrom django.shortcuts import get_object_or_404, redirect@@ -80,6 +79,10 @@ def cancel_fulfillment(fulfillment, restock):Return products to corresponding stocks if restock is set to True."""if restock:restock_fulfillment_lines(fulfillment)+ for line in fulfillment:+ order_line = line.order_line+ order_line.quantity_fulfilled -= line.quantity+ order_line.save(update_fields=['quantity_fulfilled'])fulfillment.status = FulfillmentStatus.CANCELEDfulfillment.save(update_fields=['status'])update_order_status(fulfillment.order)@@ -193,12 +196,12 @@ def restock_order_lines(order):"""Return ordered products to corresponding stocks."""for line in order:if line.stock:+ if line.quantity_unfulfilled > 0:+ deallocate_stock(line.stock, line.quantity_unfulfilled)if line.quantity_fulfilled > 0:increase_stock(line.stock, line.quantity_fulfilled)line.quantity_fulfilled = 0- line.save()- if line.quantity_unfulfilled > 0:- deallocate_stock(line.stock, line.quantity_unfulfilled)+ line.save(update_fields=['quantity_fulfilled'])def restock_fulfillment_lines(fulfillment):@@ -207,5 +210,3 @@ def restock_fulfillment_lines(fulfillment):order_line = line.order_lineif order_line.stock:increase_stock(line.order_line.stock, line.quantity)- order_line.quantity_fulfilled -= line.quantity- order_line.save(update_fields=['quantity_fulfilled'])diff --git a/saleor/static/dashboard/scss/components/_data-table.scss b/saleor/static/dashboard/scss/components/_data-table.scssindex 364f581adc..07dcc1aa25 100644--- a/saleor/static/dashboard/scss/components/_data-table.scss+++ b/saleor/static/dashboard/scss/components/_data-table.scss@@ -196,14 +196,19 @@}}- .fulfillment-quantity {- display: flex;- align-items: center;+ &.fulfillment-quantity {+ .fulfillment-quantity-input {+ display: flex;+ align-items: center;- input {- width: 64px;- margin-bottom: 0;- text-align: right;+ input {+ width: 64px;+ margin-bottom: 0;+ text-align: right;+ }+ }+ label p {+ margin: 8px 0;}}}diff --git a/templates/dashboard/order/fulfillment.html b/templates/dashboard/order/fulfillment.htmlindex 0938d64386..6b6a51d282 100644--- a/templates/dashboard/order/fulfillment.html+++ b/templates/dashboard/order/fulfillment.html@@ -89,9 +89,9 @@{% endblocktrans %}</span></td>- <td class="right-align">+ <td class="right-align fulfillment-quantity">{% get_formset_form formset forloop.counter0 as line_form %}- <div class="fulfillment-quantity">+ <div class="fulfillment-quantity-input"><input id="{{ line_form.order_line.auto_id }}"type="hidden"name="{{ line_form.order_line.html_name }}"diff --git a/tests/test_order.py b/tests/test_order.pyindex e513e48f30..a90c1b63c2 100644--- a/tests/test_order.py+++ b/tests/test_order.py@@ -224,14 +224,22 @@ def test_cancel_fulfillment(fulfilled_order):def test_update_order_status(fulfilled_order):fulfillment = fulfilled_order.fulfillments.first()+ line = fulfillment.lines.first()+ order_line = line.order_line- fulfillment.lines.first().delete()+ order_line.quantity_fulfilled -= line.quantity+ order_line.save()+ line.delete()update_order_status(fulfilled_order)assert fulfilled_order.status == OrderStatus.PARTIALLY_FULFILLED- fulfillment.status = FulfillmentStatus.CANCELED- fulfillment.save()+ line = fulfillment.lines.first()+ order_line = line.order_line++ order_line.quantity_fulfilled -= line.quantity+ order_line.save()+ line.delete()update_order_status(fulfilled_order)assert fulfilled_order.status == OrderStatus.UNFULFILLED