First step into managing Category Parameters to InvenTree settings

This commit is contained in:
eeintech 2020-10-30 17:17:18 -05:00
parent 34ff05d66e
commit 5310ce8465
7 changed files with 106 additions and 0 deletions

View File

@ -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'),

View File

@ -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 """

View File

@ -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<pk>\d+)/edit/', views.PartParameterTemplateEdit.as_view(), name='category-param-template-edit'),
# url(r'^(?P<pk>\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'),
]

View File

@ -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'

View File

@ -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 %}
<h4>{% trans "Category Parameter Templates" %}</h4>
<h5>{% trans "Category: XXX (id = 1)" %}</h5>
<div id='param-buttons'>
<button class='btn btn-success' id='new-param'>
<span class='fas fa-plus-circle'></span> {% trans "New Parameter" %}
</button>
</div>
<table class='table table-striped table-condensed' id='param-table' data-toolbar='#param-buttons'>
</table>
{% endblock %}
{% block js_ready %}
{{ block.super }}
$("#new-param").click(function() {
launchModalForm("{% url 'category-param-template-create' 1 %}", {
success: function() {
$("#param-table").bootstrapTable('refresh');
},
});
});
{% endblock %}

View File

@ -18,6 +18,9 @@
<li{% ifequal tab 'currency' %} class='active'{% endifequal %}>
<a href="{% url 'settings-currency' %}"><span class='fas fa-dollar-sign'></span> {% trans "Currency" %}</a>
</li>
<li{% ifequal tab 'category' %} class='active'{% endifequal %}>
<a href="{% url 'settings-category' %}"><span class='fa fa-sitemap'></span> {% trans "Categories" %}</a>
</li>
<li{% ifequal tab 'part' %} class='active'{% endifequal %}>
<a href="{% url 'settings-part' %}"><span class='fas fa-shapes'></span> {% trans "Parts" %}</a>
</li>

View File

@ -57,6 +57,7 @@ class RuleSet(models.Model):
'part_parttesttemplate',
'part_partparametertemplate',
'part_partparameter',
'part_partcategoryparametertemplate',
],
'stock': [
'stock_stockitem',