Item stocktake form

This commit is contained in:
Oliver 2018-04-30 21:03:25 +10:00
parent feff4f0ddd
commit f9138f4997
5 changed files with 52 additions and 0 deletions

View File

@ -46,6 +46,16 @@ class MoveStockItemForm(forms.ModelForm):
]
class StocktakeForm(forms.ModelForm):
class Meta:
model = StockItem
fields = [
'quantity',
]
class EditStockItemForm(HelperForm):
class Meta:

View File

@ -15,6 +15,7 @@ class StockItemSerializer(serializers.ModelSerializer):
'part',
'supplier_part',
'location',
'in_stock',
'belongs_to',
'customer',
'quantity',

View File

@ -97,6 +97,7 @@
<button class='btn btn-info' id='edit-item'>Edit Stock Item</button>
{% if item.in_stock %}
<button class='btn btn-primary' id='move-item'>Move Stock Item</button>
<button class='btn btn-primary' id='stocktake'>Stocktake</button>
{% endif %}
<button class='btn btn-danger' id='delete-item'>Delete Stock Item</button>
</div>
@ -127,6 +128,15 @@
reload: true,
});
});
$("#stocktake").click(function() {
launchModalForm("#modal-form",
"{% url 'stock-item-stocktake' item.id %}",
{
reload: true
});
});
{% endif %}
$("#delete-item").click(function () {

View File

@ -15,6 +15,8 @@ stock_item_detail_urls = [
url(r'^edit/?', views.StockItemEdit.as_view(), name='stock-item-edit'),
url(r'^delete/?', views.StockItemDelete.as_view(), name='stock-item-delete'),
url(r'^move/?', views.StockItemMove.as_view(), name='stock-item-move'),
url(r'^stocktake/?', views.StockItemStocktake.as_view(), name='stock-item-stocktake'),
url('^.*$', views.StockItemDetail.as_view(), name='stock-item-detail'),
]

View File

@ -10,10 +10,13 @@ from InvenTree.views import AjaxUpdateView, AjaxDeleteView, AjaxCreateView
from part.models import Part
from .models import StockItem, StockLocation
import datetime
from .forms import EditStockLocationForm
from .forms import CreateStockItemForm
from .forms import EditStockItemForm
from .forms import MoveStockItemForm
from .forms import StocktakeForm
class StockIndex(ListView):
model = StockItem
@ -135,3 +138,29 @@ class StockItemMove(AjaxUpdateView):
form_class = MoveStockItemForm
class StockItemStocktake(AjaxUpdateView):
model = StockItem
template_name = 'modal_form.html'
context_object_name = 'item'
ajax_form_title = 'Item stocktake'
form_class = StocktakeForm
def post(self, request, *args, **kwargs):
form = self.form_class(request.POST, instance=self.get_object())
if form.is_valid():
obj = form.save()
obj.stocktake_date = datetime.datetime.now()
obj.stocktake_user = request.user
obj.save()
data = {
'form_valid': form.is_valid()
}
return self.renderJsonResponse(request, form, data)