mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Added setting, checkbox (PartCreateView only) and hook to create part parameters from category templates
This commit is contained in:
parent
978b5f869d
commit
34b784d1e4
@ -85,6 +85,13 @@ class InvenTreeSetting(models.Model):
|
||||
'validator': bool
|
||||
},
|
||||
|
||||
'PART_CATEGORY_PARAMETERS': {
|
||||
'name': _('Create Parameters From Category Templates'),
|
||||
'description': _('Automatically create part parameters from category templates'),
|
||||
'default': False,
|
||||
'validator': bool
|
||||
},
|
||||
|
||||
'BUILDORDER_REFERENCE_PREFIX': {
|
||||
'name': _('Build Order Reference Prefix'),
|
||||
'description': _('Prefix value for build order reference'),
|
||||
|
@ -186,6 +186,11 @@ class EditPartForm(HelperForm):
|
||||
help_text=_('Confirm part creation'),
|
||||
widget=forms.HiddenInput())
|
||||
|
||||
category_templates = forms.BooleanField(required=False,
|
||||
initial=False,
|
||||
help_text=_('Create parameters from category templates'),
|
||||
widget=forms.HiddenInput())
|
||||
|
||||
class Meta:
|
||||
model = Part
|
||||
fields = [
|
||||
@ -193,6 +198,7 @@ class EditPartForm(HelperForm):
|
||||
'parameters_copy',
|
||||
'confirm_creation',
|
||||
'category',
|
||||
'category_templates',
|
||||
'name',
|
||||
'IPN',
|
||||
'description',
|
||||
|
@ -555,6 +555,9 @@ class PartCreate(AjaxCreateView):
|
||||
# Hide the default_supplier field (there are no matching supplier parts yet!)
|
||||
form.fields['default_supplier'].widget = HiddenInput()
|
||||
|
||||
# Force display of the 'category_templates' widget
|
||||
form.fields['category_templates'].widget = CheckboxInput()
|
||||
|
||||
return form
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
@ -607,6 +610,18 @@ class PartCreate(AjaxCreateView):
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
# Create part parameters
|
||||
category_templates = form.cleaned_data['category_templates']
|
||||
if category_templates:
|
||||
# Get category parent
|
||||
category = form.cleaned_data['category'].get_root()
|
||||
|
||||
for template in category.get_parameter_templates():
|
||||
PartParameter.create(part=part,
|
||||
template=template.parameter_template,
|
||||
data=template.default_value,
|
||||
save=True)
|
||||
|
||||
return self.renderJsonResponse(request, form, data, context=context)
|
||||
|
||||
def get_initial(self):
|
||||
@ -630,6 +645,9 @@ class PartCreate(AjaxCreateView):
|
||||
if label in self.request.GET:
|
||||
initials[label] = self.request.GET.get(label)
|
||||
|
||||
# Automatically create part parameters from category templates
|
||||
initials['category_templates'] = str2bool(InvenTreeSetting.get_setting('PART_CATEGORY_PARAMETERS', False))
|
||||
|
||||
return initials
|
||||
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
{% include "InvenTree/settings/setting.html" with key="PART_COPY_BOM" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="PART_COPY_PARAMETERS" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="PART_COPY_TESTS" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="PART_CATEGORY_PARAMETERS" %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user