From 31562826f4c8959fc641f85326f831c8d199b3de Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 7 Sep 2019 20:06:04 +1000 Subject: [PATCH] Add modal form for creating a new currency --- InvenTree/InvenTree/urls.py | 3 +++ InvenTree/common/forms.py | 24 +++++++++++++++++++ InvenTree/common/urls.py | 15 ++++++++++++ InvenTree/common/views.py | 20 +++++++++++++++- .../InvenTree/settings/currency.html | 13 +++++++++- 5 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 InvenTree/common/forms.py create mode 100644 InvenTree/common/urls.py diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index bb400af615..d811c0165e 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -14,6 +14,7 @@ from company.urls import company_urls from company.urls import supplier_part_urls from company.urls import price_break_urls +from common.urls import common_urls from part.urls import part_urls from stock.urls import stock_urls from build.urls import build_urls @@ -70,6 +71,8 @@ urlpatterns = [ url(r'^supplier-part/', include(supplier_part_urls)), url(r'^price-break/', include(price_break_urls)), + url(r'^common/', include(common_urls)), + url(r'^stock/', include(stock_urls)), url(r'^company/', include(company_urls)), diff --git a/InvenTree/common/forms.py b/InvenTree/common/forms.py new file mode 100644 index 0000000000..00e6c15c7f --- /dev/null +++ b/InvenTree/common/forms.py @@ -0,0 +1,24 @@ +""" +Django forms for interacting with common objects +""" + +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from InvenTree.forms import HelperForm + +from .models import Currency + + +class CurrencyEditForm(HelperForm): + """ Form for creating / editing a currency object """ + + class Meta: + model = Currency + fields = [ + 'symbol', + 'suffix', + 'description', + 'value', + 'base' + ] diff --git a/InvenTree/common/urls.py b/InvenTree/common/urls.py new file mode 100644 index 0000000000..648e65b919 --- /dev/null +++ b/InvenTree/common/urls.py @@ -0,0 +1,15 @@ +""" +URL lookup for common views +""" + +from django.conf.urls import url, include + +from . import views + +currency_urls = [ + url(r'^new/', views.CurrencyCreate.as_view(), name='currency-create'), +] + +common_urls = [ + url(r'currency/', include(currency_urls)), +] diff --git a/InvenTree/common/views.py b/InvenTree/common/views.py index 60f00ef0ef..ee1164006e 100644 --- a/InvenTree/common/views.py +++ b/InvenTree/common/views.py @@ -1 +1,19 @@ -# Create your views here. +""" +Django views for interacting with common models +""" + +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from InvenTree.views import AjaxCreateView + +from .models import Currency +from .forms import CurrencyEditForm + + +class CurrencyCreate(AjaxCreateView): + """ View for creating a new Currency object """ + + model = Currency + form_class = CurrencyEditForm + ajax_form_title = 'Create new Currency' diff --git a/InvenTree/templates/InvenTree/settings/currency.html b/InvenTree/templates/InvenTree/settings/currency.html index 0fde7c5c26..e91d8456ad 100644 --- a/InvenTree/templates/InvenTree/settings/currency.html +++ b/InvenTree/templates/InvenTree/settings/currency.html @@ -8,7 +8,11 @@

Currencies

- +
+ +
+ +
{% endblock %} @@ -58,5 +62,12 @@ ] }); + $("#new-currency").click(function() { + launchModalForm("{% url 'currency-create' %}", { + success: function() { + $("#currency-table").bootstrapTable('refresh'); + }, + }); + }); {% endblock %} \ No newline at end of file