Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add/edit stock location view
Mira Szewczyk681ff35c57c8
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.pyindex ccbc704804..6f69662042 100644--- a/saleor/dashboard/product/forms.py+++ b/saleor/dashboard/product/forms.py@@ -7,7 +7,7 @@ from django.utils.translation import pgettext_lazyfrom ...product.models import (AttributeChoiceValue, Product, ProductAttribute,ProductImage, ProductVariant, Stock,- VariantImage)+ VariantImage, StockLocation)from .widgets import ImagePreviewWidgetPRODUCT_CLASSES = {Product: 'Default'}@@ -173,5 +173,11 @@ class ProductAttributeForm(forms.ModelForm):exclude = []+class StockLocationForm(forms.ModelForm):+ class Meta:+ model = StockLocation+ fields = '__all__'++AttributeChoiceValueFormset = inlineformset_factory(ProductAttribute, AttributeChoiceValue, exclude=(), extra=1)diff --git a/saleor/dashboard/product/urls.py b/saleor/dashboard/product/urls.pyindex 279af8859b..9ecd22cac6 100644--- a/saleor/dashboard/product/urls.py+++ b/saleor/dashboard/product/urls.py@@ -54,4 +54,8 @@ urlpatterns = [url(r'stocklocations/$', views.stock_location_list,name='product-stock-location-list'),+ url(r'stocklocations/add/$', views.stock_location_edit,+ name='product-stock-location-add'),+ url(r'stocklocations/(?P<location_pk>[0-9]+)/$', views.stock_location_edit,+ name='product-stock-location-edit'),]diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.pyindex f1010dbf74..b8e13dfcdb 100644--- a/saleor/dashboard/product/views.py+++ b/saleor/dashboard/product/views.py@@ -282,3 +282,20 @@ def stock_location_list(request):ctx = {'locations': stock_locations}return TemplateResponse(request, 'dashboard/product/stock_locations/list.html', ctx)+++@staff_member_required+def stock_location_edit(request, location_pk=None):+ if location_pk:+ location = get_object_or_404(StockLocation, pk=location_pk)+ else:+ location = StockLocation()+ form = forms.StockLocationForm(request.POST or None, instance=location)+ if form.is_valid():+ location = form.save()+ msg = _('Updated location') if location_pk else _('Added location')+ messages.success(request, msg)+ return redirect('dashboard:product-stock-location-list')+ ctx = {'form': form, 'location': location}+ return TemplateResponse(+ request, 'dashboard/product/stock_locations/form.html', ctx)diff --git a/saleor/product/models/__init__.py b/saleor/product/models/__init__.pyindex f8607236a1..af03fa8824 100644--- a/saleor/product/models/__init__.py+++ b/saleor/product/models/__init__.py@@ -3,4 +3,5 @@ from .base import (AttributeChoiceValue, Category, Product, ProductAttribute,from .images import ProductImage, VariantImage__all__ = ['AttributeChoiceValue', 'Category', 'Product', 'ProductAttribute',- 'ProductImage', 'ProductVariant', 'Stock', 'VariantImage', 'StockLocation']+ 'ProductImage', 'ProductVariant', 'Stock', 'VariantImage',+ 'StockLocation']diff --git a/templates/dashboard/product/stock_locations/form.html b/templates/dashboard/product/stock_locations/form.htmlnew file mode 100644index 0000000000..6a26c06f2e--- /dev/null+++ b/templates/dashboard/product/stock_locations/form.html@@ -0,0 +1,59 @@+{% extends 'dashboard/base.html' %}++{% load i18n %}+{% load materializecss %}+{% load static %}++{% block title %}{% if location.pk %}{{ location }}{% else %}{% trans 'Add new stock location' %}{% endif %} - {% trans "Stock location" %} - {{ block.super }}{% endblock %}++{% block body_class %}body-locations{% endblock %}++{% block header_extra %}+ {% if location.pk %}+ <a class="dropdown-button" href="#" data-activates="attribute-delete" data-constrainwidth="false">+ <i class="material-icons">more_vert</i>+ </a>+ <ul id="attribute-delete" class="dropdown-content">+ <li>+ <a class="modal-trigger-custom" href="#base-modal"+ data-href="{% url 'dashboard:product-attribute-delete' pk=location.pk %}">+ {% trans "Remove stock location" %}+ </a>+ </li>+ </ul>+ {% endif %}+{% endblock %}++{% block breadcrumbs %}+ <ul class="breadcrumbs breadcrumbs--with-menu">+ <li><a href="{% url 'dashboard:product-stock-location-list' %}" class="breadcrumbs--ellipsed-item">{% trans "Stock location" %}</a></li>+ <li><span class="breadcrumbs--ellipsed-item">{% if location.pk %}{{ location }}{% else %}{% trans 'Add new stock location' %}{% endif %}</span></li>+ </ul>+{% endblock %}++{% block menu_catalogue_class %} active{% endblock %}+++{% block content %}+ <div class="row tab-content" id="details">+ <form method="post" id="form-product" novalidate>+ {% csrf_token %}++ <div class="col s12 l4">+ <div class="row">+ {{ form.location|materializecss:"input-field s12" }}+ </div>+ </div>++ <div class="col s12 right-align">+ <div class="row">+ {% if location.pk %}+ <button type="submit" class="btn">{% trans "Update" %}</button>+ {% else %}+ <button type="submit" class="btn">{% trans "Create" %}</button>+ {% endif %}+ </div>+ </div>+ </form>+ </div>+{% endblock %}diff --git a/templates/dashboard/product/stock_locations/list.html b/templates/dashboard/product/stock_locations/list.htmlindex eca4cf71b9..b96e1302f3 100644--- a/templates/dashboard/product/stock_locations/list.html+++ b/templates/dashboard/product/stock_locations/list.html@@ -10,7 +10,7 @@{% block header_extra %}<div class="fixed-action-btn"><a class="btn-fab btn-floating btn-large waves-effect waves-light teal"- href="{% url 'dashboard:product-attribute-add' %}" title="{% trans "Add stock location" %}">+ href="{% url 'dashboard:product-stock-location-add' %}" title="{% trans "Add stock location" %}"><i class="material-icons">add</i></a></div>@@ -32,7 +32,7 @@<ul class="collection list list--attributes">{% for location in locations %}<li class="collection-item list-item list--attributes-item list-item--two-lines">- <a class="list-item-name" href="">{{ location }}</a>+ <a class="list-item-name" href="{% url 'dashboard:product-stock-location-edit' location.pk %}">{{ location }}</a></li>{% endfor %}</ul>