internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: saleor/saleor

Issue:
Missing variable in "fulfillment" email
Two small issues in the "fulfillment" email:
- logo is missing
- in footer there is missing template variable

I've just tested it and this is how the email looks like:

![image](https://user-images.githubusercontent.com/5421321/38736166-7bd21386-3f2b-11e8-99e0-65459f62602a.png)



Discussion:
Also headers are not aligned with the column contents.

Resolving patch:
diff --git a/saleor/order/emails.py b/saleor/order/emails.py
--- a/saleor/order/emails.py
+++ b/saleor/order/emails.py
@@ -53,7 +53,7 @@ def collect_data_for_email(order_pk, template):
 def collect_data_for_fullfillment_email(order_pk, template, fulfillment_pk):
     fulfillment = Fulfillment.objects.get(pk=fulfillment_pk)
     email_data = collect_data_for_email(order_pk, template)
-    email_data.update({'context': {'fulfillment': fulfillment}})
+    email_data['context'].update({'fulfillment': fulfillment})
     return email_data
 
 


Test patch:
diff --git a/tests/test_emails.py b/tests/test_emails.py
--- a/tests/test_emails.py
+++ b/tests/test_emails.py
@@ -36,10 +36,14 @@ def test_collect_data_for_order_confirmation_email(order):
 def test_collect_data_for_fullfillment_email(fulfilled_order):
     template = emails.CONFIRM_FULFILLMENT_TEMPLATE
     fulfillment = fulfilled_order.fulfillments.first()
-    email_data = emails.collect_data_for_fullfillment_email(
+    fulfillment_data = emails.collect_data_for_fullfillment_email(
         fulfilled_order.pk, template, fulfillment.pk)
-    email_context = email_data['context']
+    email_context = fulfillment_data['context']
     assert email_context['fulfillment'] == fulfillment
+    email_data = emails.collect_data_for_email(fulfilled_order.pk, template)
+    assert all([
+        key in email_context
+        for key, item in email_data['context'].items()])
 
 
 def test_collect_data_for_email(order):
Repository: saleor/saleor

Issue:
'lines__product' is an invalid parameter to prefetch_related()
### What I'm trying to achieve
See order details page in the storefront.

### Steps to reproduce the problem
1. Create a digital product in the dashboard (no shipping required).
2. Log in as a customer and buy this product.
3. Once the order is created, go to order details page in the storefront. I've accessed it from my order confirmation email.

### What I expected to happen
See order details page in the storefront.

### What happened instead/how it failed
The following error happened:

```
Cannot find 'product' on OrderLine object, 'lines__product' is an invalid parameter to prefetch_related()
```

I don't know why why it works for other orders that I have in database (created by `populatedb`).

Seems that the problem is this line : https://github.com/mirumee/saleor/blob/master/saleor/order/views.py#L29


Discussion:

Resolving patch:
diff --git a/saleor/order/views.py b/saleor/order/views.py
--- a/saleor/order/views.py
+++ b/saleor/order/views.py
@@ -26,7 +26,7 @@
 
 def details(request, token):
     orders = Order.objects.confirmed().prefetch_related(
-        'lines__product', 'fulfillments', 'fulfillments__lines',
+        'lines__variant', 'fulfillments', 'fulfillments__lines',
         'fulfillments__lines__order_line')
     orders = orders.select_related(
         'billing_address', 'shipping_address', 'user')


Test patch:
Repository: saleor/saleor

Issue:
Order line doesn't respect the max char length on product name field
Hello,

I just discovered that someone (in our team) was creating too long names and too long variant names in Saleor, and then discovered it was making the order creation process crash...

I found the line causing that issue:

https://github.com/mirumee/saleor/blob/master/saleor/order/utils.py#L124-L127

```python
def add_variant_to_order(
        order, variant, total_quantity, discounts=None, add_to_existing=True):
    quantity_left = add_variant_to_existing_lines(
        order, variant, total_quantity) if add_to_existing else total_quantity
    price = variant.get_price_per_item(discounts)
    while quantity_left > 0:
        stock = variant.select_stockrecord()
        if not stock:
            raise InsufficientStock(variant)
        quantity = (
            stock.quantity_available
            if quantity_left > stock.quantity_available
            else quantity_left
        )
        order.lines.create(
            product=variant.product,
            product_name=variant.display_product(),  # <----
```

The product name field of the order is taking both the product name and the variant name (128 chars + 100 chars at worst) and only accepts at worst, a 128 chars string which thus produce a crash.

```python
    def display_product(self):
        variant_display = str(self)
        product_display = (
            '%s (%s)' % (self.product, variant_display)
            if variant_display else str(self.product))
        return smart_text(product_display)
```

We would need to quickly put a trimming as it would be way enough to fix this.
Cheers.


Discussion:

Resolving patch:
diff --git a/saleor/order/migrations/0047_order_line_name_length.py b/saleor/order/migrations/0047_order_line_name_length.py
new file mode 100644
--- /dev/null
+++ b/saleor/order/migrations/0047_order_line_name_length.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.0.3 on 2018-04-26 09:11
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('order', '0046_order_line_taxes'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='orderline',
+            name='product_name',
+            field=models.CharField(max_length=386),
+        ),
+    ]
diff --git a/saleor/order/models.py b/saleor/order/models.py
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -182,7 +182,8 @@ class OrderLine(models.Model):
     variant = models.ForeignKey(
         ProductVariant, related_name='+', on_delete=models.SET_NULL,
         blank=True, null=True)
-    product_name = models.CharField(max_length=128)
+    # max_length is as produced by ProductVariant's display_product method
+    product_name = models.CharField(max_length=386)
     product_sku = models.CharField(max_length=32)
     is_shipping_required = models.BooleanField()
     quantity = models.IntegerField(


Test patch:
Repository: saleor/saleor

Issue:
Top and Bottom Menus (Navbar/Footer) ids get set to None when  Header text  is changed in Site Settings
(Please take the time and describe the problem you're having before you propose a solution.)

### What I'm trying to achieve
Remove the default Header Text (ie. "Test Saleor - a sample shop!") by removing it completely in the Dashboard part of the app.
...

### Steps to reproduce the problem

1. Clone a new Saleor shop/site.
2. Setup everything as normal (run migrations etc, as stock).
3. Define one or more categories in the Dashboard.
4. Assign the categories in Navigation > Navbar/Footer > Add Menu Items
5. Navigate to "Site settings > Edit Site Settings" in dashboard 
6. Delete field contents of " Header text (optional) "
7. Click "Update"
8. Navigate to main home page (http://localhost:8000 for development) to find there are no items in the navbar or the menu.
9. (optional) go into db shell and look at SiteSettings to see that top and bottom ids are None! 

### What I expected to happen
The menu items of the navbar and footer to still be there.
...

### What happened instead/how it failed
The items are gone (there is nothing).
...
_



Discussion:

Resolving patch:
diff --git a/saleor/dashboard/sites/forms.py b/saleor/dashboard/sites/forms.py
--- a/saleor/dashboard/sites/forms.py
+++ b/saleor/dashboard/sites/forms.py
@@ -19,7 +19,7 @@ class Meta:
 class SiteSettingsForm(forms.ModelForm):
     class Meta:
         model = SiteSettings
-        exclude = ['site']
+        fields = ['header_text', 'description']
         labels = {
             'header_text': pgettext_lazy(
                 'Header text', 'Header text'),


Test patch:
Repository: saleor/saleor

Issue:
Toggling the price filter toggles the update button as well
Hi,

There is an issue with the price filter: toggling it hides the update button as well.

![video](https://i.imgur.com/aTBtfao.gif)


Discussion:
I think the update button is only for the price filter? Other filters should apply immediately, at least on the demo branch where React is used.
On the demo branch, yes. But on master we have to click on the button, same thing happens when we have other filters.

![scr](https://i.imgur.com/Thkprk2.png)

Kinda relates to what was said on #2118.
There is also an issue with the submit button (`.btn.primary`) it has `padding: 1rem 4rem` which is quite ugly in French, we probably should replace that by `padding: 1rem`

`1rem 4rem` padding:
![scr](https://i.imgur.com/FrKa4KE.png)

`1rem` padding:
![scr](https://i.imgur.com/R1nkMx4.png)

---

And, to fix #2168, it would require to move down the button:
```diff
Index: templates/product/_filters.html
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- templates/product/_filters.html	(revision 8857c3c7b21e641382c6a8e77dc6bac171d75625)
+++ templates/product/_filters.html	(date 1526378744000)
@@ -60,9 +60,10 @@
                         value="{% if field.value.1 %}{{ field.value.1 }}{% endif %}" type="number" min="0"
                         class="form-control d-inline" placeholder="{% trans 'to' context 'Product price filter' %}"/>
                 </div>
-                <button class="btn primary" type="submit">{% trans 'Update' context 'Product price filter' %}</button>
               </div>
             </div>
+
+            <button class="btn primary" type="submit">{% trans 'Update' context 'Product price filter' %}</button>
           {% endif %}
         {% endfor %}
       </form>
```

Resolving patch:
diff --git a/saleor/product/models.py b/saleor/product/models.py
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -98,7 +98,8 @@ class Product(SeoModel):
         Category, related_name='products', on_delete=models.CASCADE)
     price = MoneyField(
         currency=settings.DEFAULT_CURRENCY, max_digits=12,
-        decimal_places=settings.DEFAULT_DECIMAL_PLACES)
+        decimal_places=settings.DEFAULT_DECIMAL_PLACES,
+        verbose_name=pgettext_lazy('Currency amount', 'Price'))
     available_on = models.DateField(blank=True, null=True)
     is_published = models.BooleanField(default=True)
     attributes = HStoreField(default={}, blank=True)


Test patch:
Repository: saleor/saleor

Issue:
Invalid product price
There is a difference between the unit price on the product page and the price shown on the basket.
It looks like we mix net and gross values.

### What I'm trying to achieve
I want to see the same prices in both places (product and basket page).


### Steps to reproduce the problem

1. Open product page
2. Add product to basket
3. Compare the product price in both pages.

![image](https://user-images.githubusercontent.com/1451824/40307523-25127de2-5d03-11e8-9a09-3a4115e80bcf.png)



Discussion:

Resolving patch:
diff --git a/saleor/core/templatetags/taxed_prices.py b/saleor/core/templatetags/taxed_prices.py
--- a/saleor/core/templatetags/taxed_prices.py
+++ b/saleor/core/templatetags/taxed_prices.py
@@ -8,10 +8,8 @@
 
 @register.inclusion_tag('product/_price_range.html', takes_context=True)
 def price_range(context, price_range):
-    display_gross_prices = context['site'].settings.display_gross_prices
-    return {
-        'price_range': price_range,
-        'display_gross_prices': display_gross_prices}
+    display_gross = context['site'].settings.display_gross_prices
+    return {'display_gross': display_gross, 'price_range': price_range}
 
 
 @register.simple_tag


Test patch:
Repository: saleor/saleor

Issue:
Unable to add a new address on checkout of digital goods


### What I'm trying to achieve

Enter a new billing address on checkout when ordering a digital good.

### Steps to reproduce the problem

1. Make sure you have a default billing address;
1. Add to cart a book;
1. Go to checkout;
1. At billing address step, create a new address with a different country;
1. Correct any errors if the default billing address fields differs from the new country;
1. Place order;
1. Shipping address should not have been created.

### What I expected to happen
Have the new address as billing address on order.

### What happened instead/how it failed
Got no address created, and got the previous address as billing address for order.



Discussion:
There is a problem with `summary_without_shipping` view and `billing_address` property on checkout object. When user has default_billing_address and no other billing address for checkout process set, a default_billing_address is returned by property. Then it is took as an instance to create AddressForm (in view mentioned before, `summary.py` file). When modified instance is assigned to checkout, it has and `id` of a user's default address. So restoring it again in checkout's `billing_address` property causes calling `_get_address_from_storage` which fetches from database an object with given id.
I will open a PR with a change solving this problem soon.

Resolving patch:
diff --git a/saleor/checkout/views/summary.py b/saleor/checkout/views/summary.py
--- a/saleor/checkout/views/summary.py
+++ b/saleor/checkout/views/summary.py
@@ -160,8 +160,7 @@ def summary_without_shipping(request, checkout):
         address_form, preview = get_address_form(
             request.POST or None, autocomplete_type='billing',
             initial={'country': request.country},
-            country_code=billing_address.country.code,
-            instance=billing_address)
+            country_code=billing_address.country.code)
         addresses_form = BillingWithoutShippingAddressForm(
             request.POST or None, additional_addresses=user_addresses,
             initial={'address': billing_address.id})


Test patch:
Repository: saleor/saleor

Issue:
Missing informations while choosing shipping method for order
When creating order from dashboard and choosing shipping method, we would like to have information about shipping country. For example, one may same shipping provider, but different prices for different countries.
![image](https://user-images.githubusercontent.com/8645948/40553760-edf6e0fc-6043-11e8-948f-2bcdf3b19503.png)



Discussion:

Resolving patch:
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -717,7 +717,7 @@ def change_fulfillment_tracking(request, order_pk, fulfillment_pk):
 def ajax_order_shipping_methods_list(request, order_pk):
     order = get_object_or_404(Order, pk=order_pk)
     queryset = ShippingMethodCountry.objects.select_related(
-        'shipping_method').order_by('price').all()
+        'shipping_method').order_by('shipping_method__name', 'price')
 
     if order.shipping_address:
         country_code = order.shipping_address.country.code
diff --git a/saleor/shipping/models.py b/saleor/shipping/models.py
--- a/saleor/shipping/models.py
+++ b/saleor/shipping/models.py
@@ -99,5 +99,5 @@ def get_total_price(self, taxes=None):
 
     def get_ajax_label(self):
         price_html = format_money(self.price)
-        label = mark_safe('%s %s' % (self.shipping_method, price_html))
+        label = mark_safe('%s %s' % (self, price_html))
         return label


Test patch:
diff --git a/tests/test_shipping.py b/tests/test_shipping.py
--- a/tests/test_shipping.py
+++ b/tests/test_shipping.py
@@ -36,4 +36,4 @@ def test_shipping_get_total_price(monkeypatch, shipping_method, vatlayer):
 def test_shipping_get_ajax_label(shipping_method):
     method = shipping_method.price_per_country.get()
     label = method.get_ajax_label()
-    assert label == 'DHL $10.00'
+    assert label == 'DHL Rest of World $10.00'
Repository: saleor/saleor

Issue:
Checkout with an empty cart generates infinite HTTP redirection
### Steps to reproduce the problem

1. Checkout with an empty cart ([one click example](https://demo.getsaleor.com/en/checkout/)).

### What I expected to happen
Be redirect to the cart (as it was some time ago).





Discussion:

Resolving patch:
diff --git a/saleor/checkout/views/__init__.py b/saleor/checkout/views/__init__.py
--- a/saleor/checkout/views/__init__.py
+++ b/saleor/checkout/views/__init__.py
@@ -160,7 +160,7 @@ def cart_shipping_options(request, cart):
 def update_cart_line(request, cart, variant_id):
     """Update the line quantities."""
     if not request.is_ajax():
-        return redirect('checkout:index')
+        return redirect('cart:index')
     variant = get_object_or_404(ProductVariant, pk=variant_id)
     discounts = request.discounts
     taxes = request.taxes
diff --git a/saleor/checkout/views/summary.py b/saleor/checkout/views/summary.py
--- a/saleor/checkout/views/summary.py
+++ b/saleor/checkout/views/summary.py
@@ -26,7 +26,7 @@ def handle_order_placement(request, cart):
             discounts=request.discounts,
             taxes=get_taxes_for_cart(cart, request.taxes))
     except InsufficientStock:
-        return redirect('checkout:index')
+        return redirect('cart:index')
 
     if not order:
         msg = pgettext('Checkout warning', 'Please review your checkout.')
diff --git a/saleor/checkout/views/validators.py b/saleor/checkout/views/validators.py
--- a/saleor/checkout/views/validators.py
+++ b/saleor/checkout/views/validators.py
@@ -15,7 +15,7 @@ def validate_cart(view):
     def func(request, cart):
         if cart:
             return view(request, cart)
-        return redirect('checkout:index')
+        return redirect('cart:index')
     return func
 
 


Test patch:
diff --git a/tests/test_checkout.py b/tests/test_checkout.py
--- a/tests/test_checkout.py
+++ b/tests/test_checkout.py
@@ -25,8 +25,8 @@
 
 
 @pytest.mark.parametrize('cart_length, is_shipping_required, redirect_url', [
-    (0, True, reverse('checkout:index')),
-    (0, False, reverse('checkout:index')),
+    (0, True, reverse('cart:index')),
+    (0, False, reverse('cart:index')),
     (1, True, reverse('checkout:shipping-address')),
     (1, False, reverse('checkout:summary'))])
 def test_view_checkout_index(
Repository: saleor/saleor

Issue:
Featured products section should not be shown if there is none
If there is no featured products, the home page should not show the empty section.

### Screenshots
![screenshot](https://i.imgur.com/KFPEPnz.png)



Discussion:

Resolving patch:
diff --git a/saleor/core/views.py b/saleor/core/views.py
--- a/saleor/core/views.py
+++ b/saleor/core/views.py
@@ -14,9 +14,9 @@
 
 def home(request):
     products = products_for_homepage()[:8]
-    products = products_with_availability(
+    products = list(products_with_availability(
         products, discounts=request.discounts, taxes=request.taxes,
-        local_currency=request.currency)
+        local_currency=request.currency))
     webpage_schema = get_webpage_schema(request)
     return TemplateResponse(
         request, 'home.html', {


Test patch:
Repository: saleor/saleor

Issue:
"Track inventory" is always checked when editing a variant no matter what

### Steps to reproduce the problem
1. Edit a variant and set it to not track the inventory;
2. Submit;
3. Edit again this variant;
4. It should be checked despite the value being ` false` in the DB.



Discussion:

Resolving patch:
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.py
--- a/saleor/dashboard/product/forms.py
+++ b/saleor/dashboard/product/forms.py
@@ -289,11 +289,9 @@ class Meta:
                 'product variant handle stock field help text',
                 'Automatically track this product\'s inventory')}
 
-    def __init__(self, *args, initial_track_inventory=True, **kwargs):
+    def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
 
-        self.initial['track_inventory'] = initial_track_inventory
-
         if self.instance.product.pk:
             self.fields['price_override'].widget.attrs[
                 'placeholder'] = self.instance.product.price.amount
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -100,17 +100,17 @@ def product_select_type(request):
 @staff_member_required
 @permission_required('product.edit_product')
 def product_create(request, type_pk):
-    site_settings = request.site.settings
+    track_inventory = request.site.settings.track_inventory_by_default
     product_type = get_object_or_404(ProductType, pk=type_pk)
     create_variant = not product_type.has_variants
     product = Product()
     product.product_type = product_type
     product_form = forms.ProductForm(request.POST or None, instance=product)
     if create_variant:
-        variant = ProductVariant(product=product)
+        variant = ProductVariant(
+            product=product, track_inventory=track_inventory)
         variant_form = forms.ProductVariantForm(
             request.POST or None,
-            initial_track_inventory=site_settings.track_inventory_by_default,
             instance=variant, prefix='variant')
         variant_errors = not variant_form.is_valid()
     else:
@@ -315,12 +315,11 @@ def variant_details(request, product_pk, variant_pk):
 @staff_member_required
 @permission_required('product.edit_product')
 def variant_create(request, product_pk):
-    site_settings = request.site.settings
+    track_inventory = request.site.settings.track_inventory_by_default
     product = get_object_or_404(Product.objects.all(), pk=product_pk)
-    variant = ProductVariant(product=product)
+    variant = ProductVariant(product=product, track_inventory=track_inventory)
     form = forms.ProductVariantForm(
         request.POST or None,
-        initial_track_inventory=site_settings.track_inventory_by_default,
         instance=variant)
     if form.is_valid():
         form.save()


Test patch: