Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Drop StockLocation

Pacu2bcca95403349
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
index 2997a685a9..07e699fe99 100644
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -398,7 +398,6 @@ def create_order_line(order):
is_shipping_required=product.product_type.is_shipping_required,
quantity=quantity,
stock=stock,
- stock_location=stock.location.name,
unit_price=TaxedMoney(net=product.price, gross=product.price))
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 2965bedcd4..44c5ed83b8 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -585,8 +585,6 @@ class ChangeStockForm(forms.ModelForm):
def save(self, commit=True):
quantity = self.instance.quantity
stock = self.instance.stock
- self.instance.stock_location = (
- stock.location.name if stock.location else '')
if self.old_stock:
deallocate_stock(self.old_stock, quantity)
allocate_stock(stock, quantity)
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index 12682109d2..168bf8caa1 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -21,7 +21,6 @@ from ...order.emails import (
send_order_confirmation)
from ...order.models import Fulfillment, FulfillmentLine, Order, OrderNote
from ...order.utils import update_order_status
-from ...product.models import StockLocation
from ...shipping.models import ShippingMethodCountry
from ..views import staff_member_required
from .filters import OrderFilter
@@ -136,14 +135,12 @@ def order_details(request, order_pk):
else:
can_capture = can_release = can_refund = False
can_mark_as_paid = not order.payments.exists()
- is_many_stock_locations = StockLocation.objects.count() > 1
ctx = {
'order': order, 'all_payments': all_payments, 'payment': payment,
'notes': notes, 'events': events, 'captured': captured,
'balance': balance, 'preauthorized': preauthorized,
'can_capture': can_capture, 'can_release': can_release,
- 'can_refund': can_refund, 'can_mark_as_paid': can_mark_as_paid,
- 'is_many_stock_locations': is_many_stock_locations}
+ 'can_refund': can_refund, 'can_mark_as_paid': can_mark_as_paid}
return TemplateResponse(request, 'dashboard/order/detail.html', ctx)
diff --git a/saleor/dashboard/product/filters.py b/saleor/dashboard/product/filters.py
index 92a8845ac1..4e398c052a 100644
--- a/saleor/dashboard/product/filters.py
+++ b/saleor/dashboard/product/filters.py
@@ -6,7 +6,7 @@ from django_filters import (
from ...core.filters import SortedFilterSet
from ...product.models import (
- Category, Product, ProductAttribute, ProductType, StockLocation)
+ Category, Product, ProductAttribute, ProductType)
from ..widgets import MoneyRangeWidget
PRODUCT_SORT_BY_FIELDS = {
@@ -19,9 +19,6 @@ PRODUCT_ATTRIBUTE_SORT_BY_FIELDS = {
PRODUCT_TYPE_SORT_BY_FIELDS = {
'name': pgettext_lazy('Product type list sorting option', 'name')}
-STOCK_LOCATION_SORT_BY_FIELDS = {
- 'name': pgettext_lazy('Stock location list sorting option', 'name')}
-
PUBLISHED_CHOICES = (
('1', pgettext_lazy('Is publish filter choice', 'Published')),
('0', pgettext_lazy('Is publish filter choice', 'Not published')))
@@ -119,18 +116,3 @@ class ProductTypeFilter(SortedFilterSet):
'Found %(counter)d matching product type',
'Found %(counter)d matching product types',
number=counter) % {'counter': counter}
-
-
-class StockLocationFilter(SortedFilterSet):
- sort_by = OrderingFilter(
- label=pgettext_lazy(
- 'Stock location list filter label', 'Sort by'),
- fields=STOCK_LOCATION_SORT_BY_FIELDS.keys(),
- field_labels=STOCK_LOCATION_SORT_BY_FIELDS)
- name = CharFilter(
- label=pgettext_lazy('Stock location list filter label', 'Name'),
- lookup_expr='icontains')
-
- class Meta:
- model = StockLocation
- fields = []
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.py
index 8fb9b15937..84b6c6a656 100644
--- a/saleor/dashboard/product/forms.py
+++ b/saleor/dashboard/product/forms.py
@@ -12,8 +12,7 @@ from mptt.forms import TreeNodeChoiceField
from . import ProductBulkAction
from ...product.models import (
AttributeChoiceValue, Category, Collection, Product, ProductAttribute,
- ProductImage, ProductType, ProductVariant, Stock, StockLocation,
- VariantImage)
+ ProductImage, ProductType, ProductVariant, Stock, VariantImage)
from ...product.thumbnails import create_product_thumbnails
from ...product.utils.attributes import get_name_from_attributes
from ..forms import ModelChoiceOrCreationField, OrderedModelMultipleChoiceField
diff --git a/saleor/dashboard/product/urls.py b/saleor/dashboard/product/urls.py
index e3e785835c..92f82bf718 100644
--- a/saleor/dashboard/product/urls.py
+++ b/saleor/dashboard/product/urls.py
@@ -86,15 +86,6 @@ urlpatterns = [
views.attribute_choice_value_delete,
name='product-attribute-value-delete'),
- url(r'stocklocations/$', views.stock_location_list,
- name='product-stock-location-list'),
- url(r'stocklocations/add/$', views.stock_location_add,
- name='product-stock-location-add'),
- url(r'stocklocations/(?P<location_pk>[0-9]+)/$', views.stock_location_edit,
- name='product-stock-location-edit'),
- url(r'stocklocations/(?P<location_pk>[0-9]+)/delete/$',
- views.stock_location_delete, name='product-stock-location-delete'),
-
url(r'^ajax/variants/$',
views.ajax_available_variants_list, name='ajax-available-variants'),
url(r'^ajax/products/$',
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
index 3382d5fd3e..f47fb42a10 100644
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -13,14 +13,12 @@ from . import forms
from ...core.utils import get_paginator_items
from ...product.models import (
AttributeChoiceValue, Product, ProductAttribute, ProductImage, ProductType,
- ProductVariant, Stock, StockLocation)
+ ProductVariant)
from ...product.utils.availability import get_availability
from ...product.utils.costs import (
get_product_costs_data, get_variant_costs_data)
from ..views import staff_member_required
-from .filters import (
- ProductAttributeFilter, ProductFilter, ProductTypeFilter,
- StockLocationFilter)
+from .filters import ProductAttributeFilter, ProductFilter, ProductTypeFilter
@staff_member_required
@@ -262,7 +260,7 @@ def product_delete(request, pk):
@staff_member_required
-@permission_required('product.view_stock_location')
+@permission_required('product.view_stock')
def stock_details(request, product_pk, variant_pk, stock_pk):
product = get_object_or_404(Product, pk=product_pk)
variant = get_object_or_404(product.variants, pk=variant_pk)
@@ -275,7 +273,7 @@ def stock_details(request, product_pk, variant_pk, stock_pk):
@staff_member_required
-@permission_required('product.edit_stock_location')
+@permission_required('product.edit_stock')
def stock_add(request, product_pk, variant_pk):
product = get_object_or_404(Product, pk=product_pk)
variant = get_object_or_404(product.variants, pk=variant_pk)
@@ -295,7 +293,7 @@ def stock_add(request, product_pk, variant_pk):
@staff_member_required
-@permission_required('product.edit_stock_location')
+@permission_required('product.edit_stock')
def stock_edit(request, product_pk, variant_pk, stock_pk):
product = get_object_or_404(Product, pk=product_pk)
variant = get_object_or_404(product.variants, pk=variant_pk)
@@ -315,7 +313,7 @@ def stock_edit(request, product_pk, variant_pk, stock_pk):
@staff_member_required
-@permission_required('product.edit_stock_location')
+@permission_required('product.edit_stock')
def stock_delete(request, product_pk, variant_pk, stock_pk):
product = get_object_or_404(Product, pk=product_pk)
variant = get_object_or_404(product.variants, pk=variant_pk)
@@ -656,76 +654,6 @@ def attribute_choice_value_delete(request, attribute_pk, value_pk):
{'value': value, 'attribute_pk': attribute_pk})
-@staff_member_required
-@permission_required('product.view_stock_location')
-def stock_location_list(request):
- stock_locations = StockLocation.objects.all().order_by('name')
- stock_location_filter = StockLocationFilter(
- request.GET, queryset=stock_locations)
- stock_locations = get_paginator_items(
- stock_location_filter.qs, settings.DASHBOARD_PAGINATE_BY,
- request.GET.get('page'))
- ctx = {
- 'locations': stock_locations, 'filter_set': stock_location_filter,
- 'is_empty': not stock_location_filter.queryset.exists()}
- return TemplateResponse(
- request,
- 'dashboard/product/stock_location/list.html',
- ctx)
-
-
-@staff_member_required
-@permission_required('product.edit_stock_location')
-def stock_location_add(request):
- location = StockLocation()
- form = forms.StockLocationForm(request.POST or None, instance=location)
- if form.is_valid():
- form.save()
- msg = pgettext_lazy(
- 'Dashboard message for stock location', 'Added location')
- messages.success(request, msg)
- return redirect('dashboard:product-stock-location-list')
- return TemplateResponse(
- request,
- 'dashboard/product/stock_location/form.html',
- {'form': form, 'location': location})
-
-
-@staff_member_required
-@permission_required('product.edit_stock_location')
-def stock_location_edit(request, location_pk):
- location = get_object_or_404(StockLocation, pk=location_pk)
- form = forms.StockLocationForm(request.POST or None, instance=location)
- if form.is_valid():
- form.save()
- msg = pgettext_lazy(
- 'Dashboard message for stock location', 'Updated location')
- messages.success(request, msg)
- return redirect('dashboard:product-stock-location-list')
- return TemplateResponse(
- request,
- 'dashboard/product/stock_location/form.html',
- {'form': form, 'location': location})
-
-
-@staff_member_required
-@permission_required('product.edit_stock_location')
-def stock_location_delete(request, location_pk):
- location = get_object_or_404(StockLocation, pk=location_pk)
- if request.method == 'POST':
- location.delete()
- msg = pgettext_lazy(
- 'Dashboard message for stock location',
- 'Removed location %s') % (location,)
- messages.success(request, msg)
- return redirect('dashboard:product-stock-location-list')
- ctx = {'location': location, 'stock_count': location.stock_set.count()}
- return TemplateResponse(
- request,
- 'dashboard/product/stock_location/modal/confirm_delete.html',
- ctx)
-
-
@require_POST
@staff_member_required
def ajax_reorder_product_images(request, product_pk):
diff --git a/saleor/order/models.py b/saleor/order/models.py
index dd155679a1..b69545a068 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -183,7 +183,6 @@ class OrderLine(models.Model):
product_name = models.CharField(max_length=128)
product_sku = models.CharField(max_length=32)
is_shipping_required = models.BooleanField()
- stock_location = models.CharField(max_length=100, default='')
stock = models.ForeignKey(
'product.Stock', on_delete=models.SET_NULL, null=True)
quantity = models.IntegerField(
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index b11ab4fc70..6f3346d79a 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -160,11 +160,10 @@ def add_variant_to_order(
variant.product.product_type.is_shipping_required),
quantity=quantity,
unit_price=price,
- stock=stock,
- stock_location=stock.location.name)
- allocate_stock(stock, quantity)
+ stock=stock)
+ allocate_stock(variant, quantity)
# refresh stock for accessing quantity_allocated
- stock.refresh_from_db()
+ variant.refresh_from_db()
quantity_left -= quantity
@@ -238,6 +237,6 @@ def restock_fulfillment_lines(fulfillment, allocate=True):
"""Return fulfilled products to corresponding stocks."""
for line in fulfillment:
order_line = line.order_line
- if order_line.stock:
+ if order_line.variant:
increase_stock(
- line.order_line.stock, line.quantity, allocate=allocate)
+ line.order_line.variant, line.quantity, allocate=allocate)
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 05860c1d76..bd641e2c6e 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -257,27 +257,9 @@ class ProductVariant(models.Model):
return None
-class StockLocation(models.Model):
- name = models.CharField(max_length=100)
-
- class Meta:
- permissions = (
- ('view_stock_location',
- pgettext_lazy('Permission description',
- 'Can view stock location')),
- ('edit_stock_location',
- pgettext_lazy('Permission description',
- 'Can edit stock location')))
-
- def __str__(self):
- return self.name
-
-
class Stock(models.Model):
variant = models.ForeignKey(
ProductVariant, related_name='stock', on_delete=models.CASCADE)
- location = models.ForeignKey(
- StockLocation, null=True, on_delete=models.CASCADE)
quantity = models.IntegerField(
validators=[MinValueValidator(0)], default=Decimal(1))
quantity_allocated = models.IntegerField(
diff --git a/templates/dashboard/base.html b/templates/dashboard/base.html
index ab1643aa16..38cc92ea33 100644
--- a/templates/dashboard/base.html
+++ b/templates/dashboard/base.html
@@ -96,7 +96,7 @@
{% trans "Home" context "Dashboard homepage" %}
</a>
</li>
- {% if perms.product.view_product or perms.product.view_category or perms.product.view_stock_location %}
+ {% if perms.product.view_product or perms.product.view_category or perms.product.view_stock %}
<li class="side-nav-section" id="first">
<p>
{% trans "Catalogue" context "Dashboard catalogue" %}
@@ -116,13 +116,6 @@
</a>
</li>
{% endif %}
- {% if perms.product.view_stock_location %}
- <li class="{% block menu_location_class %}{% endblock %}">
- <a href="{% url 'dashboard:product-stock-location-list' %}">
- {% trans "Stock locations" context "Dashboard stock loactions list" %}
- </a>
- </li>
- {% endif %}
{% if perms.product.view_product %}
<li class="{% block menu_collections_class %}{% endblock %}">
<a href="{% url 'dashboard:collection-list' %}">
diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.html
index d6ac7e2a42..0167ad6926 100644
--- a/templates/dashboard/order/detail.html
+++ b/templates/dashboard/order/detail.html
@@ -312,7 +312,7 @@
<td class="right-align">
{% if perms.order.edit_order and order.is_draft %}
<a class="dropdown-button" href="#" data-activates="line-actions-{{ line.pk }}" data-constrainwidth="false">
- {{ line.quantity }} {% if line.stock_location and is_many_stock_locations %} ({{ line.stock_location|truncatechars:10 }}) {% endif %}
+ {{ line.quantity }}
<svg data-src="{% static "dashboard/images/arrow-drop-down.svg" %}" width="24" height="24" />
</a>
<ul id="line-actions-{{ line.pk }}" class="dropdown-content">
@@ -321,13 +321,6 @@
{% trans "Change quantity" context "Order table row action" %}
</a>
</li>
- {% if is_many_stock_locations %}
- <li>
- <a href="#base-modal" data-href="{% url 'dashboard:orderline-change-stock' order_pk=order.pk line_pk=line.pk %}" class="modal-trigger-custom" title="{% trans "Change stock location" context "Order table row action" %}">
- {% trans "Change stock" context "Order table row action" %}
- </a>
- </li>
- {% endif %}
<li>
<a href="#base-modal" data-href="{% url 'dashboard:orderline-cancel' order_pk=order.pk line_pk=line.pk %}" class="modal-trigger-custom" title="{% trans "Remove line" context "Order table row action" %}">
{% trans "Remove line" context "Order table row action" %}
diff --git a/templates/dashboard/product/product_variant/detail.html b/templates/dashboard/product/product_variant/detail.html
index f51041f2c1..d2369bec64 100644
--- a/templates/dashboard/product/product_variant/detail.html
+++ b/templates/dashboard/product/product_variant/detail.html
@@ -100,12 +100,12 @@
</div>
{% endif %}
</div>
- {% if perms.product.view_stock_location %}
+ {% if perms.product.view_stock %}
<div class="card">
<div class="card-content">
<span class="card-title">{% trans "Stock" context "Dashboard variant details view" %}</span>
</div>
- {% if perms.product.edit_stock_location %}
+ {% if perms.product.edit_stock %}
<div class="data-table-header-action">
<a class="btn-flat waves-effect" href="{% url "dashboard:variant-stock-add" product_pk=product.pk variant_pk=variant.pk %}">
{% trans "Add" context "Dashboard action" %}
diff --git a/templates/dashboard/product/stock/detail.html b/templates/dashboard/product/stock/detail.html
index 2fc5c3c99a..911820c7c9 100644
--- a/templates/dashboard/product/stock/detail.html
+++ b/templates/dashboard/product/stock/detail.html
@@ -60,7 +60,7 @@
</div>
</div>
</div>
- {% if perms.product.edit_stock_location %}
+ {% if perms.product.edit_stock %}
<div class="card-action">
<a class="btn-flat waves-effect" href="{% url "dashboard:variant-stock-update" product_pk=product.pk variant_pk=variant.pk stock_pk=stock.pk %}">
{% trans "Edit stock" context "Dashboard action" %}
diff --git a/templates/dashboard/product/stock/form.html b/templates/dashboard/product/stock/form.html
index 5f34696c87..2b86a0c9a4 100644
--- a/templates/dashboard/product/stock/form.html
+++ b/templates/dashboard/product/stock/form.html
@@ -5,7 +5,7 @@
{% block title %}
{% if stock.pk %}
- {% blocktrans trimmed with location=stock.location context "Dashboard stock" %}
+ {% blocktrans trimmed context "Dashboard stock" %}
Edit - Stock {{ variant }}
{% endblocktrans %}
{% else %}
@@ -78,11 +78,6 @@
<div class="card-content">
{% csrf_token %}
<div class="row">
- <div class="col s12 m8">
- <div class="row">
- {{ form.location|materializecss }}
- </div>
- </div>
<div class="col s12 m4">
<div class="row">
{{ form.quantity|materializecss }}
diff --git a/templates/dashboard/product/stock_location/form.html b/templates/dashboard/product/stock_location/form.html
deleted file mode 100644
index 0d1735c1bd..0000000000
--- a/templates/dashboard/product/stock_location/form.html
+++ /dev/null
@@ -1,90 +0,0 @@
-{% extends 'dashboard/base.html' %}
-
-{% load i18n %}
-{% load materializecss %}
-{% load staticfiles %}
-
-{% block title %}
- {% if location.pk %}
- {{ location }}
- {% else %}
- {% trans "Add new stock location" context "Stock location page title" %}
- {% endif %}
- - {% trans "Stock location" context "Dashboard stock location" %} - {{ block.super }}
-{% endblock %}
-
-{% block body_class %}body-locations{% endblock %}
-
-{% block header_extra %}
- {% if location.pk %}
- <a class="dropdown-button right" href="#" data-activates="attribute-delete" data-constrainwidth="false">
- <svg data-src="{% static "dashboard/images/more-vert.svg" %}" height="24" width="24" />
- </a>
- <ul id="attribute-delete" class="dropdown-content">
- <li>
- <a class="modal-trigger-custom" href="#base-modal"
- data-href="{% url 'dashboard:product-stock-location-delete' location.pk %}">
- {% trans "Remove location" context "Stock location detail action" %}
- </a>
- </li>
- </ul>
- {% endif %}
-{% endblock %}
-
-{% block breadcrumbs %}
- <ul class="breadcrumbs breadcrumbs--history">
- <li>
- <a href="{% url 'dashboard:product-stock-location-list' %}" class="breadcrumbs--ellipsed-item">
- {% trans "Stock location" context "Dashboard stock location" %}
- </a>
- </li>
- <li class="back-mobile">
- <a href="{% url 'dashboard:sale-list' %}">
- <svg data-src="{% static "dashboard/images/arrow-left.svg" %}" fill="#fff" width="20px" height="20px" />
- </a>
- </li>
- <li>
- <span class="breadcrumbs--ellipsed-item">
- {% if location.pk %}
- {{ location }}
- {% else %}
- {% trans "Add new stock location" context "Stock location detail breadcrumbs" %}
- {% endif %}
- </span>
- </li>
- </ul>
-{% endblock %}
-
-{% block menu_location_class %} active{% endblock %}
-
-{% block content %}
- <div class="row">
- <div class="col s12 l9">
- <div class="card">
- <form method="post" id="form-product" novalidate>
- <div class="card-content card-content-form">
- {% csrf_token %}
- <div class="row">
- {{ form.name|materializecss }}
- </div>
- </div>
- <div class="card-action right-align">
- <a href="{% url 'dashboard:product-stock-location-list' %}" class="btn-flat waves-effect">
- {% trans "Cancel" context "Dashboard cancel action" %}
- </a>
- {% if location.pk %}
- <button type="submit" class="btn waves-effect">
- {% trans "Update" context "Dashboard update action" %}
- </button>
- {% else %}
- <button type="submit" class="btn waves-effect">
- {% trans "Create" context "Dashboard create action" %}
- </button>
- {% endif %}
- </div>
- </form>
- </div>
- </div>
- <div class="col m12 l3 help-box"></div>
- </div>
-{% endblock %}
diff --git a/templates/dashboard/product/stock_location/list.html b/templates/dashboard/product/stock_location/list.html
deleted file mode 100644
index ef738ffcd7..0000000000
--- a/templates/dashboard/product/stock_location/list.html
+++ /dev/null
@@ -1,75 +0,0 @@
-{% extends 'dashboard/base.html' %}
-{% load i18n %}
-{% load materializecss %}
-{% load staticfiles %}
-{% load utils %}
-
-{% block title %}
- {% trans "Stock locations" context "Dashboard stock location" %} - {{ block.super }}
-{% endblock %}
-
-{% block body_class %}body-locations{% endblock %}
-
-{% block header_extra %}
- {% if perms.product.edit_stock_location %}
- <div class="btn-fab-fixed">
- <a class="btn-fab-default waves-effect waves-light" href="{% url 'dashboard:product-stock-location-add' %}" title="{% trans "Add stock location" context "Stock location list add button text" %}">
- <svg data-src="{% static "dashboard/images/add.svg" %}" />
- </a>
- </div>
- {% endif %}
-{% endblock %}
-
-{% block breadcrumbs %}
- <ul class="breadcrumbs">
- <li class="visible-s">
- {% trans "Stock locations" context "Dashboard stock location" %}
- </li>
- </ul>
-{% endblock %}
-
-{% block menu_location_class %} active{% endblock %}
-
-{% block content %}
- <div class="row">
- <div class="col s12 l9">
- {% if locations %}
- <div class="card">
- <div class="data-table-container">
- <table class="highlight bordered data-table">
- <thead>
- <tr>
- {% trans "Name" context "Dashboard stock location table header name" as label %}
- {% sorting_header 'name' label is_wide=True %}
- </tr>
- </thead>
- <tbody>
- {% for location in locations %}
- <tr data-action-go="{% if perms.product.edit_stock_location %}{% url 'dashboard:product-stock-location-edit' location.pk %}{% endif %}">
- <td>{{ location }}</td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
- </div>
- </div>
- {% paginate locations %}
- {% else %}
- {% if is_empty %}
- {% include 'dashboard/product/stock_location/zero_page.html' %}
- {% else %}
- <div class="col s12">
- <div class="not-found">
- <p class="grey-text">
- {% trans "No locations found." context "Empty stock location list message" %}
- </p>
- </div>
- </div>
- {% endif %}
- {% endif %}
- </div>
- <div class="col s12 l3" id="filters">
- {% if not is_empty %}{% filters filter_set %}{% endif %}
- </div>
- </div>
-{% endblock %}
diff --git a/templates/dashboard/product/stock_location/modal/confirm_delete.html b/templates/dashboard/product/stock_location/modal/confirm_delete.html
deleted file mode 100644
index 21dff4b29e..0000000000
--- a/templates/dashboard/product/stock_location/modal/confirm_delete.html
+++ /dev/null
@@ -1,39 +0,0 @@
-{% extends "dashboard/base_modal.html" %}
-
-{% load i18n %}
-
-{% block form_class %}{% endblock %}
-
-{% block action_url %}
-{% url 'dashboard:product-stock-location-delete' location.pk %}
-{% endblock %}
-
-{% block title %}
-{% blocktrans trimmed context "Modal remove stock location text" %}
-Remove stock location {{ location }}
-{% endblocktrans %}
-{% endblock title %}
-
-{% block content %}
- <div class="col s12">
- <p>
- {% blocktrans trimmed context "Modal remove stock location text" %}
- Are you sure you want to remove stock location <strong>{{ location }}</strong>?
- {% endblocktrans %}
- </p>
- {% if stock_count %}
- <p>
- {% blocktrans trimmed count counter=stock_count context "Modal remove stock location text" %}
- There is one stock associated with this stock location that will be removed.
- {% plural %}
- There are {{ counter }} stocks associated with this stock location that will be removed.
- {% endblocktrans %}
- </p>
- {% endif %}
- </div>
-{% endblock content %}
-
-{% block primary_action %}
-{% trans "Remove" context "Dashboard delete action" %}
-{% endblock %}
-
diff --git a/templates/dashboard/product/stock_location/zero_page.html b/templates/dashboard/product/stock_location/zero_page.html
deleted file mode 100644
index a1ae482422..0000000000
--- a/templates/dashboard/product/stock_location/zero_page.html
+++ /dev/null
@@ -1,12 +0,0 @@
-{% extends 'dashboard/base_zero_page.html' %}
-{% load i18n %}
-{% load static %}
-
-{% block title %}{% trans "No stock locations found." %}{% endblock %}
-{% block content %}
- {% static "dashboard/images/add.svg" as img_path %}
- {% blocktrans %}
- Stock locations are the warehouses that you're sending the products from.<br>
- You can create stock locations by using the <span class="btn-fab-presentation"><svg data-src="{{ img_path }}" /></span> button.
- {% endblocktrans %}
-{% endblock %}
diff --git a/tests/conftest.py b/tests/conftest.py
index 444f186102..48b3ba0497 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -26,7 +26,7 @@ from saleor.order.utils import recalculate_order
from saleor.page.models import Page
from saleor.product.models import (
AttributeChoiceValue, Category, Collection, Product, ProductAttribute,
- ProductImage, ProductType, ProductVariant, Stock, StockLocation)
+ ProductImage, ProductType, ProductVariant, Stock)
from saleor.shipping.models import ShippingMethod
from saleor.site.models import AuthorizationKey, SiteSettings
@@ -176,11 +176,6 @@ def non_default_category(db): # pylint: disable=W0613
return Category.objects.create(name='Not default', slug='not-default')
-def default_stock_location(db):
- return StockLocation.objects.create(name='Warehouse 1')
-
-
@pytest.fixture
def staff_group():
return Group.objects.create(name='test')
@@ -207,13 +202,13 @@ def permission_edit_category():
@pytest.fixture
-def permission_view_stock_location():
- return Permission.objects.get(codename='view_stock_location')
+def permission_view_stock():
+ return Permission.objects.get(codename='view_stock')
@pytest.fixture
-def permission_edit_stock_location():
- return Permission.objects.get(codename='edit_stock_location')
+def permission_edit_stock():
+ return Permission.objects.get(codename='edit_stock')
@pytest.fixture
@@ -272,19 +267,8 @@ def product(product_type, default_category):
smart_text(variant_attr.pk): smart_text(variant_attr_value.pk)}
variant = ProductVariant.objects.create(
- product=product, sku='123', attributes=variant_attributes)
- warehouse_1 = StockLocation.objects.create(name='Warehouse 1')
- warehouse_2 = StockLocation.objects.create(name='Warehouse 2')
- warehouse_3 = StockLocation.objects.create(name='Warehouse 3')
- Stock.objects.create(
- variant=variant, cost_price=Money('1.00', 'USD'), quantity=5,
- quantity_allocated=5, location=warehouse_1)
- Stock.objects.create(
- variant=variant, cost_price=Money('100.00', 'USD'), quantity=5,
- quantity_allocated=5, location=warehouse_2)
- Stock.objects.create(
- variant=variant, cost_price=Money('10.00', 'USD'), quantity=5,
- quantity_allocated=0, location=warehouse_3)
+ product=product, sku='123', attributes=variant_attributes,
+ cost_price=Money('1.00', 'USD'), quantity=5, quantity_allocated=5)
return product
@@ -337,12 +321,6 @@ def order_list(customer_user):
return [order, order1, order2]
-def stock_location():
- warehouse_1 = StockLocation.objects.create(name='Warehouse 1')
- return warehouse_1
-
-
@pytest.fixture
def product_image():
img_data = BytesIO()
@@ -403,10 +381,6 @@ def order_with_lines(order, product_type, default_category, shipping_method):
name='Test product', price=Money('10.00', 'USD'),
product_type=product_type, category=default_category)
variant = ProductVariant.objects.create(product=product, sku='SKU_A')
- warehouse = StockLocation.objects.create(name='Warehouse 1')
- stock = Stock.objects.create(
- variant=variant, cost_price=Money(1, 'USD'), quantity=5,
- quantity_allocated=3, location=warehouse)
order.lines.create(
product=product,
product_name=product.name,
@@ -414,17 +388,11 @@ def order_with_lines(order, product_type, default_category, shipping_method):
is_shipping_required=product.product_type.is_shipping_required,
quantity=3,
unit_price_net=Decimal('30.00'),
- unit_price_gross=Decimal('30.00'),
- stock=stock,
- stock_location=stock.location.name)
-
+ unit_price_gross=Decimal('30.00'))
product = Product.objects.create(
name='Test product 2', price=Money('20.00', 'USD'),
product_type=product_type, category=default_category)
variant = ProductVariant.objects.create(product=product, sku='SKU_B')
- stock = Stock.objects.create(
- variant=variant, cost_price=Money(2, 'USD'), quantity=2,
- quantity_allocated=2, location=warehouse)
order.lines.create(
product=product,
product_name=product.name,
@@ -432,9 +400,7 @@ def order_with_lines(order, product_type, default_category, shipping_method):
is_shipping_required=product.product_type.is_shipping_required,
quantity=2,
unit_price_net=Decimal('20.00'),
- unit_price_gross=Decimal('20.00'),
- stock=stock,
- stock_location=stock.location.name)
+ unit_price_gross=Decimal('20.00'))
order.shipping_address = order.billing_address.get_copy()
order.shipping_method_name = shipping_method.name
@@ -442,7 +408,6 @@ def order_with_lines(order, product_type, default_category, shipping_method):
order.shipping_method = method
order.shipping_price = method.get_total_price()
order.save()
-
recalculate_order(order)
order.refresh_from_db()
return order
@@ -471,14 +436,11 @@ def draft_order(order_with_lines):
@pytest.fixture()
-def order_with_variant_from_different_stocks(order_with_lines):
+def order_with_lines_and_stock(order_with_lines):
line = OrderLine.objects.get(product_sku='SKU_A')
variant = ProductVariant.objects.get(sku=line.product_sku)
- warehouse_2 = StockLocation.objects.create(name='Warehouse 2')
- stock = Stock.objects.create(
- variant=variant, cost_price=Money(1, 'USD'), quantity=5,
- quantity_allocated=2, location=warehouse_2)
order_with_lines.lines.create(
+ order=order,
product=variant.product,
product_name=variant.product.name,
product_sku=line.product_sku,
@@ -486,12 +448,7 @@ def order_with_variant_from_different_stocks(order_with_lines):
quantity=2,
unit_price_net=Decimal('30.00'),
unit_price_gross=Decimal('30.00'),
- stock=stock,
- stock_location=stock.location.name)
- warehouse_2 = StockLocation.objects.create(name='Warehouse 3')
- Stock.objects.create(
- variant=variant, cost_price=Money(1, 'USD'), quantity=5,
- quantity_allocated=0, location=warehouse_2)
+ quantity_allocated=0)
return order_with_lines
diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.py
index 376b83d84d..abacfb598e 100644
--- a/tests/dashboard/test_order.py
+++ b/tests/dashboard/test_order.py
@@ -19,7 +19,7 @@ from saleor.order.models import Order, OrderLine, OrderNote
from saleor.order.utils import (
add_variant_to_existing_lines, add_variant_to_order,
change_order_line_quantity)
-from saleor.product.models import ProductVariant, Stock, StockLocation
+from saleor.product.models import ProductVariant, Stock
@pytest.mark.integration
@@ -599,10 +599,8 @@ def test_view_change_order_line_stock_valid(admin_client, draft_order):
line = draft_order.lines.last()
old_stock = line.stock
variant = ProductVariant.objects.get(sku=line.product_sku)
- stock_location = StockLocation.objects.create(name='Warehouse 2')
stock = Stock.objects.create(
- variant=variant, cost_price=2, quantity=2, quantity_allocated=0,
- location=stock_location)
+ variant=variant, cost_price=2, quantity=2, quantity_allocated=0)
url = reverse(
'dashboard:orderline-change-stock', kwargs={
@@ -615,7 +613,6 @@ def test_view_change_order_line_stock_valid(admin_client, draft_order):
line.refresh_from_db()
assert line.stock == stock
- assert line.stock_location == stock.location.name
assert line.stock.quantity_allocated == 2
old_stock.refresh_from_db()
@@ -629,10 +626,8 @@ def test_view_change_order_line_stock_insufficient_stock(
line = draft_order.lines.last()
old_stock = line.stock
variant = ProductVariant.objects.get(sku=line.product_sku)
- stock_location = StockLocation.objects.create(name='Warehouse 2')
stock = Stock.objects.create(
- variant=variant, cost_price=2, quantity=2, quantity_allocated=1,
- location=stock_location)
+ variant=variant, cost_price=2, quantity=2, quantity_allocated=1)
url = reverse(
'dashboard:orderline-change-stock', kwargs={
@@ -645,7 +640,6 @@ def test_view_change_order_line_stock_insufficient_stock(
line.refresh_from_db()
assert line.stock == old_stock
- assert line.stock_location == old_stock.location.name
old_stock.refresh_from_db()
assert old_stock.quantity_allocated == 2
@@ -658,20 +652,17 @@ def test_view_change_order_line_stock_merges_lines(admin_client, draft_order):
line = draft_order.lines.first()
old_stock = line.stock
variant = ProductVariant.objects.get(sku=line.product_sku)
- stock_location = StockLocation.objects.create(name='Warehouse 2')
- stock = Stock.objects.create(
- variant=variant, cost_price=2, quantity=2, quantity_allocated=2,
- location=stock_location)
line_2 = draft_order.lines.create(
+ variant=variant,
+ cost_price=2,
+ quantity=2,
+ quantity_allocated=2,
product=line.product,
product_name=line.product.name,
product_sku='SKU_A',
is_shipping_required=line.is_shipping_required,
- quantity=2,
unit_price_net=Decimal('30.00'),
- unit_price_gross=Decimal('30.00'),
- stock=stock,
- stock_location=stock.location.name)
+ unit_price_gross=Decimal('30.00'))
lines_before = draft_order.lines.count()
url = reverse(
@@ -696,7 +687,7 @@ def test_add_variant_to_existing_lines_one_line(
order = order_with_variant_from_different_stocks
lines = order.lines.filter(product_sku='SKU_A')
variant_lines_before = lines.count()
- line = lines.get(stock_location='Warehouse 2')
+ line = lines.first()
variant = ProductVariant.objects.get(sku='SKU_A')
quantity_left = add_variant_to_existing_lines(line.order, variant, 2)
@@ -711,10 +702,10 @@ def test_add_variant_to_existing_lines_one_line(
def test_add_variant_to_existing_lines_multiple_lines(
order_with_variant_from_different_stocks):
order = order_with_variant_from_different_stocks
- lines = order.lines.filter(product_sku='SKU_A')
+ lines = order.lines.filter(product_sku='SKU_A').all()
variant_lines_before = lines.count()
- line_1 = lines.get(stock_location='Warehouse 1')
- line_2 = lines.get(stock_location='Warehouse 2')
+ line_1 = lines[0]
+ line_2 = lines[1]
variant = ProductVariant.objects.get(sku='SKU_A')
quantity_left = add_variant_to_existing_lines(line_1.order, variant, 4)
@@ -731,10 +722,10 @@ def test_add_variant_to_existing_lines_multiple_lines(
def test_add_variant_to_existing_lines_multiple_lines_with_rest(
order_with_variant_from_different_stocks):
order = order_with_variant_from_different_stocks
- lines = order.lines.filter(product_sku='SKU_A')
+ lines = order.lines.filter(product_sku='SKU_A').all()
variant_lines_before = lines.count()
- line_1 = lines.get(stock_location='Warehouse 1')
- line_2 = lines.get(stock_location='Warehouse 2')
+ line_1 = lines[0]
+ line_2 = lines[1]
variant = ProductVariant.objects.get(sku='SKU_A')
quantity_left = add_variant_to_existing_lines(line_1.order, variant, 7)
@@ -754,8 +745,7 @@ def test_view_add_variant_to_order(
order.status = OrderStatus.DRAFT
order.save()
variant = ProductVariant.objects.get(sku='SKU_A')
- line = OrderLine.objects.get(
- product_sku='SKU_A', stock_location='Warehouse 2')
+ line = OrderLine.objects.get(product_sku='SKU_A')
url = reverse(
'dashboard:add-variant-to-order', kwargs={'order_pk': order.pk})
data = {'variant': variant.pk, 'quantity': 2}
diff --git a/tests/dashboard/test_permissions.py b/tests/dashboard/test_permissions.py
index fa0a540380..73bae2ffa6 100644
--- a/tests/dashboard/test_permissions.py
+++ b/tests/dashboard/test_permissions.py
@@ -413,72 +413,6 @@ def test_staff_group_member_can_view_category_delete(
assert response.status_code == 200
-def test_staff_group_member_can_view_stock_location_list(
- staff_client, staff_user, staff_group, permission_view_stock_location):
- assert not staff_user.has_perm("product.view_stock_location")
- response = staff_client.get(reverse(
- 'dashboard:product-stock-location-list'))
- assert response.status_code == 302
- staff_group.permissions.add(permission_view_stock_location)
- staff_user.groups.add(staff_group)
- staff_user = User.objects.get(pk=staff_user.pk)
- assert staff_user.has_perm("product.view_stock_location")
- response = staff_client.get(reverse(
- 'dashboard:product-stock-location-list'))
- assert response.status_code == 200
-
-
-def test_staff_group_member_can_view_stock_location_add(
- staff_client, staff_user, staff_group, permission_edit_stock_location):
- assert not staff_user.has_perm("product.edit_stock_location")
- response = staff_client.get(reverse(
- 'dashboard:product-stock-location-add'))
- assert response.status_code == 302
- staff_group.permissions.add(permission_edit_stock_location)
- staff_user.groups.add(staff_group)
- staff_user = User.objects.get(pk=staff_user.pk)
- assert staff_user.has_perm("product.edit_stock_location")
- response = staff_client.get(reverse(
- 'dashboard:product-stock-location-add'))
- assert response.status_code == 200
-
-
-def test_staff_group_member_can_view_stock_location_edit(
- staff_client, staff_user, staff_group, permission_edit_stock_location,
- default_stock_location):
- assert not staff_user.has_perm("product.edit_stock_location")
- response = staff_client.get(reverse(
- 'dashboard:product-stock-location-edit',
- args=[default_stock_location.pk]))
- assert response.status_code == 302
- staff_group.permissions.add(permission_edit_stock_location)
- staff_user.groups.add(staff_group)
- staff_user = User.objects.get(pk=staff_user.pk)
- assert staff_user.has_perm("product.edit_stock_location")
- response = staff_client.get(reverse(
- 'dashboard:product-stock-location-edit',
- args=[default_stock_location.pk]))
- assert response.status_code == 200
-
-
-def test_staff_group_member_can_view_stock_location_delete(
- staff_client, staff_user, staff_group, permission_edit_stock_location,
- default_stock_location):
- assert not staff_user.has_perm("product.edit_stock_location")
- response = staff_client.get(reverse(
- 'dashboard:product-stock-location-delete',
- args=[default_stock_location.pk]))
- assert response.status_code == 302
- staff_group.permissions.add(permission_edit_stock_location)
- staff_user.groups.add(staff_group)
- staff_user = User.objects.get(pk=staff_user.pk)
- assert staff_user.has_perm("product.edit_stock_location")
- response = staff_client.get(reverse(
- 'dashboard:product-stock-location-delete',
- args=[default_stock_location.pk]))
- assert response.status_code == 200
-
-
def test_staff_group_member_can_view_sale_list(
staff_client, staff_user, staff_group, permission_view_sale):
assert not staff_user.has_perm("discount.view_sale")
diff --git a/tests/dashboard/test_product.py b/tests/dashboard/test_product.py
index 44f544ceda..4a5f464799 100644
--- a/tests/dashboard/test_product.py
+++ b/tests/dashboard/test_product.py
@@ -384,25 +384,6 @@ def test_view_stock_delete(admin_client, product):
assert not Stock.objects.filter(pk=stock.pk)
-def test_view_stock_location_not_deleted_before_confirmation(
- admin_client, stock_location):
- url = reverse(
- 'dashboard:product-stock-location-delete',
- kwargs={'location_pk': stock_location.pk})
- response = admin_client.get(url)
- assert response.status_code == HTTP_STATUS_OK
- assert StockLocation.objects.filter(pk=stock_location.pk)
-
-
-def test_view_stock_location_delete(admin_client, stock_location):
- url = reverse(
- 'dashboard:product-stock-location-delete',
- kwargs={'location_pk': stock_location.pk})
- response = admin_client.post(url)
- assert response.status_code == HTTP_REDIRECTION
- assert not StockLocation.objects.filter(pk=stock_location.pk)
-
-
def test_view_attribute_not_deleted_before_confirmation(
admin_client, color_attribute):
url = reverse(
diff --git a/tests/test_order.py b/tests/test_order.py
index b0d53f6318..8b5252fafd 100644
--- a/tests/test_order.py
+++ b/tests/test_order.py
@@ -192,8 +192,8 @@ def test_restock_fulfillment_lines(fulfilled_order):
fulfillment = fulfilled_order.fulfillments.first()
line_1 = fulfillment.lines.first()
line_2 = fulfillment.lines.last()
- stock_1 = line_1.order_line.stock
- stock_2 = line_2.order_line.stock
+ stock_1 = line_1.order_line.variant
+ stock_2 = line_2.order_line.variant
stock_1_quantity_allocated_before = stock_1.quantity_allocated
stock_2_quantity_allocated_before = stock_2.quantity_allocated
stock_1_quantity_before = stock_1.quantity