Skip to content

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

Move taxes configuration to taxes tab

Anna Siwik7b667e67b023
diff --git a/saleor/dashboard/sites/forms.py b/saleor/dashboard/sites/forms.py
index bba114e2a8..d3ecc35f92 100644
--- a/saleor/dashboard/sites/forms.py
+++ b/saleor/dashboard/sites/forms.py
@@ -27,24 +27,6 @@ class SiteSettingsForm(forms.ModelForm):
'Description', 'Description')}
-class SiteSettingsTaxesForm(forms.ModelForm):
- class Meta:
- model = SiteSettings
- fields = (
- 'include_taxes_in_prices', 'display_gross_prices',
- 'charge_taxes_on_shipping')
- labels = {
- 'include_taxes_in_prices': pgettext_lazy(
- 'Include taxes in prices',
- 'All taxes are included in my prices'),
- 'display_gross_prices': pgettext_lazy(
- 'Display gross prices',
- 'Show customers gross prices in storefront'),
- 'charge_taxes_on_shipping': pgettext_lazy(
- 'Charge taxes on shipping rates',
- 'Charge taxes on shipping rates')}
-
-
class AuthorizationKeyForm(forms.ModelForm):
class Meta:
model = AuthorizationKey
diff --git a/saleor/dashboard/sites/urls.py b/saleor/dashboard/sites/urls.py
index 33fa97e182..717f4e14f7 100644
--- a/saleor/dashboard/sites/urls.py
+++ b/saleor/dashboard/sites/urls.py
@@ -10,8 +10,6 @@ urlpatterns = [
name='site-details'),
url(r'^(?P<pk>\d+)/delete/$', views.site_settings_edit,
name='site-delete'),
- url(r'^(?P<pk>\d+)/configure-taxes/$', views.site_configure_taxes,
- name='site-configure-taxes'),
url(r'^(?P<site_settings_pk>\d+)/authorization_key/add/$',
views.authorization_key_add, name='authorization-key-add'),
diff --git a/saleor/dashboard/sites/views.py b/saleor/dashboard/sites/views.py
index 1ee94facdc..3e69cd5baa 100644
--- a/saleor/dashboard/sites/views.py
+++ b/saleor/dashboard/sites/views.py
@@ -7,8 +7,7 @@ from django.utils.translation import pgettext_lazy
from ...site.models import AuthorizationKey, SiteSettings
from ..views import staff_member_required
-from .forms import (
- AuthorizationKeyForm, SiteForm, SiteSettingsForm, SiteSettingsTaxesForm)
+from .forms import AuthorizationKeyForm, SiteForm, SiteSettingsForm
@staff_member_required
@@ -40,22 +39,6 @@ def site_settings_edit(request, pk):
return TemplateResponse(request, 'dashboard/sites/form.html', ctx)
-@staff_member_required
-@permission_required('site.edit_settings')
-def site_configure_taxes(request, pk):
- site_settings = get_object_or_404(SiteSettings, pk=pk)
- taxes_form = SiteSettingsTaxesForm(
- request.POST or None, instance=site_settings)
-
- if taxes_form.is_valid():
- taxes_form.save()
- msg = pgettext_lazy('Dashboard message', 'Updated taxes settings')
- messages.success(request, msg)
- return redirect('dashboard:site-details', pk=site_settings.id)
- ctx = {'site': site_settings, 'taxes_form': taxes_form}
- return TemplateResponse(request, 'dashboard/sites/taxes_form.html', ctx)
-
-
@staff_member_required
@permission_required('site.edit_settings')
def site_settings_details(request, pk):
diff --git a/saleor/dashboard/taxes/forms.py b/saleor/dashboard/taxes/forms.py
new file mode 100644
index 0000000000..be43f96694
--- /dev/null
+++ b/saleor/dashboard/taxes/forms.py
@@ -0,0 +1,22 @@
+from django import forms
+from django.utils.translation import pgettext_lazy
+
+from ...site.models import SiteSettings
+
+
+class TaxesConfigurationForm(forms.ModelForm):
+ class Meta:
+ model = SiteSettings
+ fields = (
+ 'include_taxes_in_prices', 'display_gross_prices',
+ 'charge_taxes_on_shipping')
+ labels = {
+ 'include_taxes_in_prices': pgettext_lazy(
+ 'Include taxes in prices',
+ 'All taxes are included in my prices'),
+ 'display_gross_prices': pgettext_lazy(
+ 'Display gross prices',
+ 'Show customers gross prices in storefront'),
+ 'charge_taxes_on_shipping': pgettext_lazy(
+ 'Charge taxes on shipping rates',
+ 'Charge taxes on shipping rates')}
diff --git a/saleor/dashboard/taxes/urls.py b/saleor/dashboard/taxes/urls.py
index 0269bdfd14..9b7cdc831e 100644
--- a/saleor/dashboard/taxes/urls.py
+++ b/saleor/dashboard/taxes/urls.py
@@ -6,4 +6,6 @@ urlpatterns = [
url(r'^$', views.tax_list, name='taxes'),
url(r'^(?P<country_code>[A-Z]{2})/details/$', views.tax_details,
name='tax-details'),
+ url(r'^(?P<pk>\d+)/configure-taxes/$', views.configure_taxes,
+ name='configure-taxes'),
]
diff --git a/saleor/dashboard/taxes/views.py b/saleor/dashboard/taxes/views.py
index 46d83a5f49..0fa680f25b 100644
--- a/saleor/dashboard/taxes/views.py
+++ b/saleor/dashboard/taxes/views.py
@@ -1,13 +1,18 @@
from django.conf import settings
-from django.shortcuts import get_object_or_404
+from django.contrib import messages
+from django.contrib.auth.decorators import permission_required
+from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
+from django.utils.translation import pgettext_lazy
from django_countries.fields import Country
from django_prices_vatlayer.models import VAT
from ...core.i18n import VAT_RATE_TYPE_TRANSLATIONS
from ...core.utils import get_paginator_items, get_taxes_for_country
from ...dashboard.taxes.filters import TaxFilter
+from ...dashboard.taxes.forms import TaxesConfigurationForm
from ...dashboard.views import staff_member_required
+from ...site.models import SiteSettings
@staff_member_required
@@ -16,8 +21,9 @@ def tax_list(request):
tax_filter = TaxFilter(request.GET, queryset=taxes)
taxes = get_paginator_items(
tax_filter.qs, settings.DASHBOARD_PAGINATE_BY, request.GET.get('page'))
+ site_settings = request.site.settings
ctx = {
- 'taxes': taxes, 'filter_set': tax_filter,
+ 'taxes': taxes, 'settings': site_settings, 'filter_set': tax_filter,
'is_empty': not tax_filter.queryset.exists()}
return TemplateResponse(request, 'dashboard/taxes/list.html', ctx)
@@ -31,3 +37,18 @@ def tax_details(request, country_code):
for rate_name, tax in tax_rates.items()]
ctx = {'tax': tax, 'tax_rates': sorted(tax_rates)}
return TemplateResponse(request, 'dashboard/taxes/details.html', ctx)
+
+
+@staff_member_required
+@permission_required('site.edit_settings')
+def configure_taxes(request, pk):
+ site_settings = get_object_or_404(SiteSettings, pk=pk)
+ taxes_form = TaxesConfigurationForm(
+ request.POST or None, instance=site_settings)
+ if taxes_form.is_valid():
+ taxes_form.save()
+ msg = pgettext_lazy('Dashboard message', 'Updated taxes settings')
+ messages.success(request, msg)
+ return redirect('dashboard:taxes')
+ ctx = {'site': site_settings, 'taxes_form': taxes_form}
+ return TemplateResponse(request, 'dashboard/sites/taxes_form.html', ctx)
diff --git a/templates/dashboard/sites/detail.html b/templates/dashboard/sites/detail.html
index b24b580623..6df03efc59 100644
--- a/templates/dashboard/sites/detail.html
+++ b/templates/dashboard/sites/detail.html
@@ -65,62 +65,6 @@
</div>
</div>
</div>
- <div class="col s12 l9">
- <div class="card">
- <div class="card-content">
- <span class="card-title">
- {% trans "Taxes" context "Site settings title" %}
- </span>
- <div class="row">
- <div class="col s12 m4 l12">
- <h4>
- {% trans "All taxes are included in my prices" context "Site settings field" %}
- </h4>
- <p>
- {% if site.include_taxes_in_prices %}
- {% trans "Yes" context "Include taxes in prices setting description" %}
- {% else %}
- {% trans "No" context "Include taxes in prices setting description" %}
- {% endif %}
- </p>
- </div>
- </div>
- <div class="row">
- <div class="col s12 m4 l12">
- <h4>
- {% trans "Show customers gross prices in storefront" context "Site settings field" %}
- </h4>
- <p>
- {% if site.display_gross_prices %}
- {% trans "Yes" context "Show customers gross prices setting description" %}
- {% else %}
- {% trans "No" context "Show customers gross prices setting description" %}
- {% endif %}
- </p>
- </div>
- </div>
- <div class="row">
- <div class="col s12 m4 l12">
- <h4>
- {% trans "Charge taxes on shipping rates" context "Site settings field" %}
- </h4>
- <p>
- {% if site.charge_taxes_on_shipping %}
- {% trans "Yes" context "Charge taxes on shipping rates setting description" %}
- {% else %}
- {% trans "No" context "Charge taxes on shipping rates setting description" %}
- {% endif %}
- </p>
- </div>
- </div>
- </div>
- <div class="card-action">
- <a class="btn-flat waves-effect" href="{% url 'dashboard:site-configure-taxes' pk=site.pk %}">
- {% trans "Configure taxes" context "Site settings configure taxes action" %}
- </a>
- </div>
- </div>
- </div>
<div class="col s12 l9">
<div class="card">
<div class="card-content">
diff --git a/templates/dashboard/taxes/list.html b/templates/dashboard/taxes/list.html
index 3777c9270d..b2423b9415 100644
--- a/templates/dashboard/taxes/list.html
+++ b/templates/dashboard/taxes/list.html
@@ -68,5 +68,65 @@
<div class="col s12 l3" id="filters">
{% if not is_empty %}{% filters filter_set %}{% endif %}
</div>
+ {% if perms.site.view_settings %}
+ <div class="col s12 l3">
+ <div class="card">
+ <div class="card-content">
+ <span class="card-title">
+ {% trans "Taxes settings" context "Taxes site settings title" %}
+ </span>
+ <div class="row">
+ <div class="col s12 m4 l12">
+ <h4>
+ {% trans "All taxes are included in my prices" context "Site settings field" %}
+ </h4>
+ <p>
+ {% if settings.include_taxes_in_prices %}
+ {% trans "Yes" context "Include taxes in prices setting description" %}
+ {% else %}
+ {% trans "No" context "Include taxes in prices setting description" %}
+ {% endif %}
+ </p>
+ </div>
+ </div>
+ <div class="row">
+ <div class="col s12 m4 l12">
+ <h4>
+ {% trans "Show customers gross prices in storefront" context "Site settings field" %}
+ </h4>
+ <p>
+ {% if settings.display_gross_prices %}
+ {% trans "Yes" context "Show customers gross prices setting description" %}
+ {% else %}
+ {% trans "No" context "Show customers gross prices setting description" %}
+ {% endif %}
+ </p>
+ </div>
+ </div>
+ <div class="row">
+ <div class="col s12 m4 l12">
+ <h4>
+ {% trans "Charge taxes on shipping rates" context "Site settings field" %}
+ </h4>
+ <p>
+ {% if settings.charge_taxes_on_shipping %}
+ {% trans "Yes" context "Charge taxes on shipping rates setting description" %}
+ {% else %}
+ {% trans "No" context "Charge taxes on shipping rates setting description" %}
+ {% endif %}
+ </p>
+ </div>
+ </div>
+ </div>
+ {% if perms.site.edit_settings %}
+ <div class="card-action">
+ <a class="btn-flat waves-effect" href="{% url 'dashboard:configure-taxes' pk=site.pk %}">
+ {% trans "Configure taxes" context "Site settings configure taxes action" %}
+ </a>
+ </div>
+ {% endif %}
+ </div>
+ </div>
+ {% endif %}
</div>
{% endblock %}
diff --git a/tests/dashboard/test_permissions.py b/tests/dashboard/test_permissions.py
index 329ec84195..4de566c628 100644
--- a/tests/dashboard/test_permissions.py
+++ b/tests/dashboard/test_permissions.py
@@ -900,12 +900,12 @@ def test_staff_group_member_can_view_and_edit_site_settings(
assert response.status_code == 200
-def test_staff_group_member_can_view_and_edit_site_taxes_settings(
+def test_staff_group_member_can_view_and_edit_taxes_settings(
staff_client, staff_user, staff_group, site_settings,
permission_edit_settings):
assert not staff_user.has_perm('site.edit_settings')
url = reverse(
- 'dashboard:site-configure-taxes', kwargs={'pk': site_settings.pk})
+ 'dashboard:configure-taxes', kwargs={'pk': site_settings.pk})
response = staff_client.get(url)
assert response.status_code == 302
staff_group.permissions.add(permission_edit_settings)
diff --git a/tests/dashboard/test_site_settings.py b/tests/dashboard/test_site_settings.py
index b64a78c0aa..ebb3391f0d 100644
--- a/tests/dashboard/test_site_settings.py
+++ b/tests/dashboard/test_site_settings.py
@@ -59,9 +59,9 @@ def test_site_update_view(admin_client, site_settings):
assert site_settings.site.name == 'Mirumee Labs'
-def test_site_configure_taxes(admin_client, site_settings):
+def test_configure_taxes(admin_client, site_settings):
url = reverse(
- 'dashboard:site-configure-taxes', kwargs={'pk': site_settings.pk})
+ 'dashboard:configure-taxes', kwargs={'pk': site_settings.pk})
data = {'include_taxes_in_prices': False}
response = admin_client.post(url, data)