2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 20:16:44 +00:00

Consolidated form/view into single 'stock-adjust' endpoint

This commit is contained in:
Oliver Walters 2019-06-02 11:37:04 +10:00
parent fe31205017
commit c7503b4f9f
5 changed files with 29 additions and 13 deletions

View File

@ -572,11 +572,15 @@ function loadStockTable(table, options) {
stock.push(item.pk); stock.push(item.pk);
}); });
launchModalForm("/stock/move/", launchModalForm("/stock/adjust/",
{ {
data: { data: {
action: 'move',
stock: stock, stock: stock,
}, },
success: function() {
$("#stock-table").bootstrapTable('refresh');
},
} }
); );

View File

@ -55,7 +55,7 @@ class MoveStockItemForm(HelperForm):
'note' 'note'
] ]
class MoveMultipleStockItemsForm(forms.ModelForm): class AdjustStockForm(forms.ModelForm):
def get_location_choices(self): def get_location_choices(self):
locs = StockLocation.objects.all() locs = StockLocation.objects.all()

View File

@ -36,7 +36,7 @@ stock_urls = [
url(r'^track/?', views.StockTrackingIndex.as_view(), name='stock-tracking-list'), url(r'^track/?', views.StockTrackingIndex.as_view(), name='stock-tracking-list'),
url(r'^move/?', views.StockItemMoveMultiple.as_view(), name='stock-item-move-multiple'), url(r'^adjust/?', views.StockAdjust.as_view(), name='stock-adjust'),
# Individual stock items # Individual stock items
url(r'^item/(?P<pk>\d+)/', include(stock_item_detail_urls)), url(r'^item/(?P<pk>\d+)/', include(stock_item_detail_urls)),

View File

@ -27,7 +27,7 @@ from .forms import EditStockItemForm
from .forms import MoveStockItemForm from .forms import MoveStockItemForm
from .forms import StocktakeForm from .forms import StocktakeForm
from .forms import MoveStockItemForm from .forms import MoveStockItemForm
from .forms import MoveMultipleStockItemsForm from .forms import AdjustStockForm
class StockIndex(ListView): class StockIndex(ListView):
@ -130,12 +130,19 @@ class StockItemQRCode(QRCodeView):
return None return None
class StockItemMoveMultiple(AjaxView, FormMixin): class StockAdjust(AjaxView, FormMixin):
""" Move multiple stock items """ """ View for enacting simple stock adjustments:
- Take items from stock
- Add items to stock
- Count items
- Move stock
"""
ajax_template_name = 'stock/stock_move.html' ajax_template_name = 'stock/stock_adjust.html'
ajax_form_title = 'Move Stock' ajax_form_title = 'Adjust Stock'
form_class = MoveMultipleStockItemsForm form_class = AdjustStockForm
stock_items = [] stock_items = []
def get_GET_items(self): def get_GET_items(self):
@ -203,7 +210,8 @@ class StockItemMoveMultiple(AjaxView, FormMixin):
context = super().get_context_data() context = super().get_context_data()
context['stock_items'] = self.stock_items context['stock_items'] = self.stock_items
context['stock_action'] = 'Move'
context['stock_action'] = self.stock_action
return context return context
@ -211,6 +219,9 @@ class StockItemMoveMultiple(AjaxView, FormMixin):
self.request = request self.request = request
# Action
self.stock_action = request.GET.get('action').lower()
# Save list of items! # Save list of items!
self.stock_items = self.get_GET_items() self.stock_items = self.get_GET_items()
@ -255,10 +266,11 @@ class StockItemMoveMultiple(AjaxView, FormMixin):
'form_valid': valid, 'form_valid': valid,
} }
if valid: self.stock_action = request.POST.get('stock_action').lower()
action = request.POST.get('stock_action').lower()
if action == 'move': if valid:
if self.stock_action == 'move':
destination = None destination = None