mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Create BOM export form
- Select output format
This commit is contained in:
parent
14de111130
commit
b58c49e066
@ -127,7 +127,7 @@ class AjaxCreateView(AjaxMixin, CreateView):
|
|||||||
if request.is_ajax():
|
if request.is_ajax():
|
||||||
form = self.form_class(initial=self.get_initial())
|
form = self.form_class(initial=self.get_initial())
|
||||||
|
|
||||||
return self.renderJsonResponse(request, form=form, data=data, **kwargs)
|
return self.renderJsonResponse(request, form=form, **kwargs)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return response
|
return response
|
||||||
|
@ -3,6 +3,8 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from InvenTree.forms import HelperForm
|
from InvenTree.forms import HelperForm
|
||||||
|
|
||||||
|
from django import forms
|
||||||
|
|
||||||
from .models import Part, PartCategory, BomItem
|
from .models import Part, PartCategory, BomItem
|
||||||
from .models import SupplierPart
|
from .models import SupplierPart
|
||||||
|
|
||||||
@ -16,6 +18,24 @@ class PartImageForm(HelperForm):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class BomExportForm(HelperForm):
|
||||||
|
|
||||||
|
# TODO - Define these choices somewhere else, and import them here
|
||||||
|
format_choices = (
|
||||||
|
('csv', 'CSV'),
|
||||||
|
('xlsx', 'XLSX'),
|
||||||
|
('pdf', 'PDF'),
|
||||||
|
)
|
||||||
|
|
||||||
|
# Select export type
|
||||||
|
format = forms.CharField(label='Format', widget=forms.Select(choices=format_choices), required='true', help_text='Select export format')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Part
|
||||||
|
fields = [
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class EditPartForm(HelperForm):
|
class EditPartForm(HelperForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
Export BOM for {{ part.name }}
|
Export BOM (Bill of Materials) for {{ part.name }}
|
||||||
|
|
||||||
{% include "modal_csrf.html" %}
|
<form method="post" action='' class='js-modal-form' enctype="multipart/form-data">
|
||||||
|
{% csrf_token %}
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
{% crispy form %}
|
||||||
|
</form>
|
@ -15,6 +15,7 @@ from .forms import PartImageForm
|
|||||||
from .forms import EditPartForm
|
from .forms import EditPartForm
|
||||||
from .forms import EditCategoryForm
|
from .forms import EditCategoryForm
|
||||||
from .forms import EditBomItemForm
|
from .forms import EditBomItemForm
|
||||||
|
from .forms import BomExportForm
|
||||||
|
|
||||||
from .forms import EditSupplierPartForm
|
from .forms import EditSupplierPartForm
|
||||||
|
|
||||||
@ -110,7 +111,7 @@ class PartEdit(AjaxUpdateView):
|
|||||||
ajax_form_title = 'Edit Part Properties'
|
ajax_form_title = 'Edit Part Properties'
|
||||||
|
|
||||||
|
|
||||||
class BomExport(AjaxView):
|
class BomExport(AjaxUpdateView):
|
||||||
|
|
||||||
model = Part
|
model = Part
|
||||||
form_class = BomExportForm
|
form_class = BomExportForm
|
||||||
@ -118,19 +119,26 @@ class BomExport(AjaxView):
|
|||||||
ajax_form_title = 'Export Bill of Materials'
|
ajax_form_title = 'Export Bill of Materials'
|
||||||
ajax_submit_text = 'Export'
|
ajax_submit_text = 'Export'
|
||||||
context_object_name = 'part'
|
context_object_name = 'part'
|
||||||
fields = []
|
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
|
||||||
part = get_object_or_404(Part, pk=self.kwargs['pk'])
|
part = get_object_or_404(Part, pk=self.kwargs['pk'])
|
||||||
|
form = self.form_class(instance=part, data=request.POST, files=request.FILES)
|
||||||
|
|
||||||
return self.renderJsonResponse(request, context={'part': part})
|
return self.renderJsonResponse(request, form=form, context={'part': part})
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
|
|
||||||
part = get_object_or_404(Part, pk=self.kwargs['pk'])
|
part = get_object_or_404(Part, pk=self.kwargs['pk'])
|
||||||
|
form = self.form_class(instance=part, data=request.POST, files=request.FILES)
|
||||||
|
|
||||||
return self.renderJsonResponse(request, context={'part': part})
|
export_format = request.POST.get('format', None)
|
||||||
|
|
||||||
|
if not export_format:
|
||||||
|
# TODO
|
||||||
|
pass
|
||||||
|
|
||||||
|
return self.renderJsonResponse(request, form=form, context={'part': part})
|
||||||
|
|
||||||
def get_data(self):
|
def get_data(self):
|
||||||
return {
|
return {
|
||||||
@ -227,6 +235,7 @@ class BomItemCreate(AjaxCreateView):
|
|||||||
template_name = 'part/bom-create.html'
|
template_name = 'part/bom-create.html'
|
||||||
ajax_template_name = 'modal_form.html'
|
ajax_template_name = 'modal_form.html'
|
||||||
ajax_form_title = 'Create BOM item'
|
ajax_form_title = 'Create BOM item'
|
||||||
|
ajax_submit_text = 'Create'
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
# Look for initial values
|
# Look for initial values
|
||||||
|
Loading…
Reference in New Issue
Block a user