From 5310ce84654102a0a1f1fe89420d0756f2966b64 Mon Sep 17 00:00:00 2001 From: eeintech Date: Fri, 30 Oct 2020 17:17:18 -0500 Subject: [PATCH] First step into managing Category Parameters to InvenTree settings --- InvenTree/InvenTree/urls.py | 1 + InvenTree/part/forms.py | 13 ++++++ InvenTree/part/urls.py | 8 ++++ InvenTree/part/views.py | 40 +++++++++++++++++++ .../InvenTree/settings/category.html | 40 +++++++++++++++++++ .../templates/InvenTree/settings/tabs.html | 3 ++ InvenTree/users/models.py | 1 + 7 files changed, 106 insertions(+) create mode 100644 InvenTree/templates/InvenTree/settings/category.html diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index d729210235..9b74aabe5f 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -75,6 +75,7 @@ settings_urls = [ url(r'^global/?', SettingsView.as_view(template_name='InvenTree/settings/global.html'), name='settings-global'), url(r'^currency/?', SettingsView.as_view(template_name='InvenTree/settings/currency.html'), name='settings-currency'), + url(r'^category/?', SettingsView.as_view(template_name='InvenTree/settings/category.html'), name='settings-category'), url(r'^part/?', SettingsView.as_view(template_name='InvenTree/settings/part.html'), name='settings-part'), url(r'^stock/?', SettingsView.as_view(template_name='InvenTree/settings/stock.html'), name='settings-stock'), url(r'^build/?', SettingsView.as_view(template_name='InvenTree/settings/build.html'), name='settings-build'), diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index 52c39bf3ba..d1a3dcd74e 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -16,6 +16,7 @@ from django.utils.translation import ugettext as _ from .models import Part, PartCategory, PartAttachment from .models import BomItem from .models import PartParameterTemplate, PartParameter +from .models import PartCategoryParameterTemplate from .models import PartTestTemplate from .models import PartSellPriceBreak @@ -247,6 +248,18 @@ class EditCategoryForm(HelperForm): ] +class EditCategoryParameterTemplateForm(HelperForm): + """ Form for editing a PartParameterTemplate object """ + + class Meta: + model = PartCategoryParameterTemplate + fields = [ + 'category', + 'parameter_template', + 'default_value', + ] + + class EditBomItemForm(HelperForm): """ Form for editing a BomItem object """ diff --git a/InvenTree/part/urls.py b/InvenTree/part/urls.py index 4d81faa2d6..b5881fd0b4 100644 --- a/InvenTree/part/urls.py +++ b/InvenTree/part/urls.py @@ -74,10 +74,18 @@ part_detail_urls = [ url(r'^.*$', views.PartDetail.as_view(), name='part-detail'), ] +category_parameter_urls = [ + url(r'^new/', views.CategoryParameterTemplateCreate.as_view(), name='category-param-template-create'), + # url(r'^(?P\d+)/edit/', views.PartParameterTemplateEdit.as_view(), name='category-param-template-edit'), + # url(r'^(?P\d+)/delete/', views.PartParameterTemplateDelete.as_view(), name='category-param-template-edit'), +] + part_category_urls = [ url(r'^edit/?', views.CategoryEdit.as_view(), name='category-edit'), url(r'^delete/?', views.CategoryDelete.as_view(), name='category-delete'), + url(r'^template/', include(category_parameter_urls)), + url(r'^parametric/?', views.CategoryParametric.as_view(), name='category-parametric'), url(r'^.*$', views.CategoryDetail.as_view(), name='category-detail'), ] diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 0b96addc84..d13f2223b1 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -23,6 +23,7 @@ from decimal import Decimal, InvalidOperation from .models import PartCategory, Part, PartAttachment from .models import PartParameterTemplate, PartParameter +from .models import PartCategoryParameterTemplate from .models import BomItem from .models import match_part_names from .models import PartTestTemplate @@ -2137,6 +2138,45 @@ class CategoryCreate(AjaxCreateView): return initials +class CategoryParameterTemplateCreate(AjaxCreateView): + """ View for creating a new PartCategoryParameterTemplate """ + + role_required = 'part.add' + + model = PartCategoryParameterTemplate + form_class = part_forms.EditCategoryParameterTemplateForm + ajax_form_title = _('Create Category Parameter Template') + + def get_initial(self): + """ Get initial data for Category """ + initials = super().get_initial().copy() + + category_id = self.kwargs.get('pk', None) + + if category_id: + try: + initials['category'] = PartCategory.objects.get(pk=category_id) + except (PartCategory.DoesNotExist, ValueError): + pass + + return initials + + def get_form(self): + """ Create a form to upload a new CategoryParameterTemplate + - Hide the 'category' field (parent part) + - Display parameter templates which are not yet related + """ + + form = super(AjaxCreateView, self).get_form() + + form.fields['category'].widget = HiddenInput() + + if form.is_valid(): + form.cleaned_data['category'] = self.kwargs.get('pk', None) + + return form + + class BomItemDetail(InvenTreeRoleMixin, DetailView): """ Detail view for BomItem """ context_object_name = 'item' diff --git a/InvenTree/templates/InvenTree/settings/category.html b/InvenTree/templates/InvenTree/settings/category.html new file mode 100644 index 0000000000..b643af53dd --- /dev/null +++ b/InvenTree/templates/InvenTree/settings/category.html @@ -0,0 +1,40 @@ +{% extends "InvenTree/settings/settings.html" %} +{% load i18n %} + +{% block tabs %} +{% include "InvenTree/settings/tabs.html" with tab='part' %} +{% endblock %} + +{% block subtitle %} +{% trans "Category Settings" %} +{% endblock %} + +{% block settings %} + +

{% trans "Category Parameter Templates" %}

+ +
{% trans "Category: XXX (id = 1)" %}
+ +
+ +
+ + +
+ +{% endblock %} + +{% block js_ready %} +{{ block.super }} + + $("#new-param").click(function() { + launchModalForm("{% url 'category-param-template-create' 1 %}", { + success: function() { + $("#param-table").bootstrapTable('refresh'); + }, + }); + }); + +{% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/InvenTree/settings/tabs.html b/InvenTree/templates/InvenTree/settings/tabs.html index d104908c49..6991b54b95 100644 --- a/InvenTree/templates/InvenTree/settings/tabs.html +++ b/InvenTree/templates/InvenTree/settings/tabs.html @@ -18,6 +18,9 @@ {% trans "Currency" %} + + {% trans "Categories" %} + {% trans "Parts" %} diff --git a/InvenTree/users/models.py b/InvenTree/users/models.py index d3c713d07d..7e65ba248e 100644 --- a/InvenTree/users/models.py +++ b/InvenTree/users/models.py @@ -57,6 +57,7 @@ class RuleSet(models.Model): 'part_parttesttemplate', 'part_partparametertemplate', 'part_partparameter', + 'part_partcategoryparametertemplate', ], 'stock': [ 'stock_stockitem',