Allow selection of bom_copy and parameter_copy when making a new variant

This commit is contained in:
Oliver Walters 2020-09-05 20:10:18 +10:00
parent 6ef4390e29
commit c4989e59b2
2 changed files with 11 additions and 2 deletions

View File

@ -137,7 +137,7 @@ class EditPartForm(HelperForm):
parameters_copy = forms.BooleanField(required=False,
initial=True,
help_text=_("Duplicate all parameters data for this part"),
help_text=_("Duplicate all parameter data for this part"),
label=_('Copy Parameters'),
widget=forms.HiddenInput())

View File

@ -303,6 +303,12 @@ class MakePartVariant(AjaxCreateView):
# Hide some variant-related fields
# form.fields['variant_of'].widget = HiddenInput()
# Force display of the 'bom_copy' widget
form.fields['bom_copy'].widget = CheckboxInput()
# Force display of the 'parameters_copy' widget
form.fields['parameters_copy'].widget = CheckboxInput()
return form
def post(self, request, *args, **kwargs):
@ -329,8 +335,11 @@ class MakePartVariant(AjaxCreateView):
data['text'] = str(part)
data['url'] = part.get_absolute_url()
bom_copy = str2bool(request.POST.get('bom_copy', False))
parameters_copy = str2bool(request.POST.get('parameters_copy', False))
# Copy relevent information from the template part
part.deepCopy(part_template, bom=True, parameters=True)
part.deepCopy(part_template, bom=bom_copy, parameters=parameters_copy)
return self.renderJsonResponse(request, form, data, context=context)