mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
New Form and View to create a new BuildItem object
- Allocates stock to a build
This commit is contained in:
parent
1b32f9d650
commit
0208c6efe6
@ -7,7 +7,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from InvenTree.forms import HelperForm
|
from InvenTree.forms import HelperForm
|
||||||
|
|
||||||
from .models import Build
|
from .models import Build, BuildItem
|
||||||
|
|
||||||
|
|
||||||
class EditBuildForm(HelperForm):
|
class EditBuildForm(HelperForm):
|
||||||
@ -26,3 +26,15 @@ class EditBuildForm(HelperForm):
|
|||||||
'status',
|
'status',
|
||||||
# 'completion_date',
|
# 'completion_date',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class EditBuildItemForm(HelperForm):
|
||||||
|
""" Form for adding a new BuildItem to a Build """
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = BuildItem
|
||||||
|
fields = [
|
||||||
|
'build',
|
||||||
|
'stock_item',
|
||||||
|
'quantity',
|
||||||
|
]
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
{
|
{
|
||||||
build: {{ build.pk }},
|
build: {{ build.pk }},
|
||||||
part: {{ build.part.pk }},
|
part: {{ build.part.pk }},
|
||||||
|
new_item_url: "{% url 'build-item-create' %}",
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -6,6 +6,10 @@ from django.conf.urls import url, include
|
|||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
|
build_item_urls = [
|
||||||
|
url('^new/', views.BuildItemCreate.as_view(), name='build-item-create'),
|
||||||
|
]
|
||||||
|
|
||||||
build_detail_urls = [
|
build_detail_urls = [
|
||||||
url(r'^edit/?', views.BuildUpdate.as_view(), name='build-edit'),
|
url(r'^edit/?', views.BuildUpdate.as_view(), name='build-edit'),
|
||||||
url(r'^allocate/?', views.BuildAllocate.as_view(), name='build-allocate'),
|
url(r'^allocate/?', views.BuildAllocate.as_view(), name='build-allocate'),
|
||||||
@ -15,7 +19,9 @@ build_detail_urls = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
build_urls = [
|
build_urls = [
|
||||||
url(r'new/?', views.BuildCreate.as_view(), name='build-create'),
|
url(r'item/', include(build_item_urls)),
|
||||||
|
|
||||||
|
url(r'new/', views.BuildCreate.as_view(), name='build-create'),
|
||||||
|
|
||||||
url(r'^(?P<pk>\d+)/', include(build_detail_urls)),
|
url(r'^(?P<pk>\d+)/', include(build_detail_urls)),
|
||||||
|
|
||||||
|
@ -10,8 +10,8 @@ from django.shortcuts import get_object_or_404
|
|||||||
from django.views.generic import DetailView, ListView
|
from django.views.generic import DetailView, ListView
|
||||||
|
|
||||||
from part.models import Part
|
from part.models import Part
|
||||||
from .models import Build
|
from .models import Build, BuildItem
|
||||||
from .forms import EditBuildForm
|
from .forms import EditBuildForm, EditBuildItemForm
|
||||||
|
|
||||||
from InvenTree.views import AjaxView, AjaxUpdateView, AjaxCreateView
|
from InvenTree.views import AjaxView, AjaxUpdateView, AjaxCreateView
|
||||||
|
|
||||||
@ -127,3 +127,30 @@ class BuildUpdate(AjaxUpdateView):
|
|||||||
return {
|
return {
|
||||||
'info': 'Edited build',
|
'info': 'Edited build',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class BuildItemCreate(AjaxCreateView):
|
||||||
|
""" View for allocating a new part to a build """
|
||||||
|
|
||||||
|
model = BuildItem
|
||||||
|
form_class = EditBuildItemForm
|
||||||
|
ajax_template_name = 'modal_form.html'
|
||||||
|
ajax_form_title = 'Allocate new Part'
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
""" Provide initial data for BomItem. Look for the folllowing in the GET data:
|
||||||
|
|
||||||
|
- build: pk of the Build object
|
||||||
|
"""
|
||||||
|
|
||||||
|
initials = super(AjaxCreateView, self).get_initial().copy()
|
||||||
|
|
||||||
|
build_id = self.get_param('build')
|
||||||
|
|
||||||
|
if build_id:
|
||||||
|
try:
|
||||||
|
initials['build'] = Build.objects.get(pk=build_id)
|
||||||
|
except Build.DoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return initials
|
@ -6,6 +6,7 @@ function makeBuildTable(table, options) {
|
|||||||
* options:
|
* options:
|
||||||
* build - ID of the build object
|
* build - ID of the build object
|
||||||
* part - ID of the part object for the build
|
* part - ID of the part object for the build
|
||||||
|
* new_item_url - URL to create a new BuildItem
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -20,17 +21,28 @@ function makeBuildTable(table, options) {
|
|||||||
onExpandRow: function(index, row, $detail) {
|
onExpandRow: function(index, row, $detail) {
|
||||||
fillAllocationTable(
|
fillAllocationTable(
|
||||||
$("#part-table-" + row.pk),
|
$("#part-table-" + row.pk),
|
||||||
|
index,
|
||||||
row,
|
row,
|
||||||
|
table,
|
||||||
{
|
{
|
||||||
build: options.build
|
build: options.build
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
columns: [
|
columns: [
|
||||||
|
{
|
||||||
|
field: 'pk',
|
||||||
|
title: 'ID',
|
||||||
|
visible: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
field: 'sub_part_detail.name',
|
field: 'sub_part_detail.name',
|
||||||
title: 'Part',
|
title: 'Part',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
field: 'note',
|
||||||
|
title: 'Note',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
field: 'quantity',
|
field: 'quantity',
|
||||||
title: 'Required',
|
title: 'Required',
|
||||||
@ -38,7 +50,28 @@ function makeBuildTable(table, options) {
|
|||||||
{
|
{
|
||||||
field: 'allocated',
|
field: 'allocated',
|
||||||
title: 'Allocated',
|
title: 'Allocated',
|
||||||
}
|
formatter: function(value, row, index, field) {
|
||||||
|
var html = "";
|
||||||
|
|
||||||
|
var url = options.new_item_url;
|
||||||
|
|
||||||
|
url += "?build=" + options.build + "&part=" + row.sub_part;
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
html = value;
|
||||||
|
} else {
|
||||||
|
html = "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
html += "<div class='btn-group' style='float: right;'>";
|
||||||
|
|
||||||
|
html += "<button class='btn btn-success btn-sm new-item-button' type='button' url='" + url + "'>Allocate</button>";
|
||||||
|
|
||||||
|
html += "</div>";
|
||||||
|
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -48,6 +81,16 @@ function makeBuildTable(table, options) {
|
|||||||
}).then(function(response) {
|
}).then(function(response) {
|
||||||
table.bootstrapTable('load', response)
|
table.bootstrapTable('load', response)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Button callbacks
|
||||||
|
table.on('click', '.new-item-button', function() {
|
||||||
|
var button = $(this);
|
||||||
|
|
||||||
|
launchModalForm(button.attr('url'), {
|
||||||
|
success: function() {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -68,12 +111,14 @@ function makeAllocationTable(options) {
|
|||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillAllocationTable(table, parent_row, options) {
|
function fillAllocationTable(table, index, parent_row, parent_table, options) {
|
||||||
/* Load data into an allocation table,
|
/* Load data into an allocation table,
|
||||||
* and update the total stock allocation count in the parent row.
|
* and update the total stock allocation count in the parent row.
|
||||||
*
|
*
|
||||||
* table - the part allocation table
|
* table - the part allocation table
|
||||||
* row - parent row in the build allocation table
|
* index - row index in the parent table
|
||||||
|
* parent_row - parent row data in the build allocation table
|
||||||
|
* parent_table - the parent build table
|
||||||
*
|
*
|
||||||
* options:
|
* options:
|
||||||
* build - pk of the Build object
|
* build - pk of the Build object
|
||||||
@ -113,5 +158,15 @@ function fillAllocationTable(table, parent_row, options) {
|
|||||||
for (var i = 0; i < allocationData.length; i++) {
|
for (var i = 0; i < allocationData.length; i++) {
|
||||||
allocated += allocationData[i].quantity;
|
allocated += allocationData[i].quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the parent_row data
|
||||||
|
parent_row.quantity = allocated;
|
||||||
|
|
||||||
|
/*parent_table.bootstrapTable('updateRow',
|
||||||
|
{
|
||||||
|
index: index,
|
||||||
|
row: parent_row
|
||||||
|
}
|
||||||
|
);*/
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user