Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improve several coding styles according to PR's comments
Unknown2ec7faf34c5e
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex 0919bf2d0e..dd4b7efe86 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -615,14 +615,11 @@ class BaseFulfillmentLineFormSet(forms.BaseModelFormSet):form.empty_permitted = Falsedef clean(self):- if any(self.errors):- return-- total_quantities = sum(- form.cleaned_data['quantity'] for form in self.forms)- if total_quantities <= 0:+ total_quantity = sum(+ form.cleaned_data.get('quantity', 0) for form in self.forms)+ if total_quantity <= 0:raise forms.ValidationError(- 'Total quantities must be larger than 0.')+ 'Total quantity must be larger than 0.')class FulfillmentLineForm(forms.ModelForm):diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex 57c81e28fd..5c9d893695 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -590,8 +590,8 @@ def fulfill_order_lines(request, order_pk):formset = FulfillmentLineFormSet(request.POST or None, queryset=FulfillmentLine.objects.none(),initial=initial)- all_forms_valid = all([line_form.is_valid() for line_form in formset])- if all_forms_valid and formset.is_valid() and form.is_valid():+ all_line_forms_valid = all([line_form.is_valid() for line_form in formset])+ if all_line_forms_valid and formset.is_valid() and form.is_valid():forms_to_save = [line_form for line_form in formsetif line_form.cleaned_data.get('quantity') > 0]diff --git a/saleor/graphql/order/mutations/fulfillments.py b/saleor/graphql/order/mutations/fulfillments.pyindex d7a3042465..18aa83fe66 100644--- a/saleor/graphql/order/mutations/fulfillments.py+++ b/saleor/graphql/order/mutations/fulfillments.py@@ -92,8 +92,7 @@ class FulfillmentCreate(BaseMutation):if sum(quantities) <= 0:cls.add_error(- errors, order_lines,- 'Total quantities must be larger than 0.')+ errors, 'lines', 'Total quantity must be larger than 0.')if errors:return cls(errors=errors)diff --git a/saleor/order/models.py b/saleor/order/models.pyindex 63d84e9887..b62bbdc6c3 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -315,8 +315,6 @@ class OrderLine(models.Model):def __str__(self):return self.product_name- __repr__ = __str__-def get_total(self):return self.unit_price * self.quantitydiff --git a/tests/api/test_fulfillment.py b/tests/api/test_fulfillment.pyindex 34aef46ac9..3f3da69fca 100644--- a/tests/api/test_fulfillment.py+++ b/tests/api/test_fulfillment.py@@ -99,7 +99,7 @@ def test_create_fulfillment_with_emtpy_quantity(@pytest.mark.parametrize('quantity, error_message',(- (0, 'Total quantities must be larger than 0.'),+ (0, 'Total quantity must be larger than 0.'),(100, 'Only 3 items remaining to fulfill.')))def test_create_fulfillment_not_sufficient_quantity(staff_api_client, order_with_lines, staff_user, quantity,@@ -115,8 +115,7 @@ def test_create_fulfillment_not_sufficient_quantity(content = get_graphql_content(response)data = content['data']['orderFulfillmentCreate']assert data['errors']- assert data['errors'][0]['field'] in (- str(order_line), '[{}]'.format(order_line))+ assert data['errors'][0]['field'] in (str(order_line), 'lines')assert data['errors'][0]['message'] == error_message