Skip to content

Commit

Permalink
Merge pull request #4778 from NyanKiyoshi/fix/dashboard-1.0/sales/upd…
Browse files Browse the repository at this point in the history
…ate/missing-required-fields

Fixed crash of sale form when required values are missing
  • Loading branch information
maarcingebala committed Sep 30, 2019
2 parents e44fcd5 + e1d8460 commit f263382
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Add support for webhooks - #4731 by @korycins
- Fixed the random failure of `populatedb` trying to create a new user with an existing email - #4769 by @NyanKiyoshi
- Fixed the inability of filtering attributes using `inCategory` and `inCollection` and deprecated those fields to use `filter { inCollection: ..., inCategory: ... }` instead - #4700 by @NyanKiyoshi & @khalibloo
- Fixed internal error when updating or creating a sale with missing required values - #4778 by @NyanKiyoshi

## 2.8.0

Expand Down
3 changes: 3 additions & 0 deletions saleor/dashboard/discount/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def __init__(self, *args, **kwargs):

def clean(self):
cleaned_data = super().clean()
if self.errors:
return cleaned_data

discount_type = cleaned_data["type"]
value = cleaned_data["value"]
if discount_type == DiscountValueType.PERCENTAGE and value > 100:
Expand Down
19 changes: 19 additions & 0 deletions tests/dashboard/test_discounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ def test_view_sale_add(admin_client, category, collection):
assert collection in sale.collections.all()


def test_view_sale_update_invalid_values(admin_client, sale, collection):
url = reverse("dashboard:sale-update", kwargs={"pk": sale.pk})
data = {
"name": sale.name,
"categories": [],
"collections": [],
"start_date": "2018-01-01",
}

response = admin_client.post(url, data)
assert response.status_code == 200

form_ctx = response.context["form"]
assert form_ctx.errors == {
"type": ["This field is required."],
"value": ["This field is required."],
}


def test_view_sale_add_requires_product_category_or_collection(
admin_client, category, product, collection
):
Expand Down

0 comments on commit f263382

Please sign in to comment.