mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Item stocktake form
This commit is contained in:
parent
feff4f0ddd
commit
f9138f4997
@ -46,6 +46,16 @@ class MoveStockItemForm(forms.ModelForm):
|
||||
]
|
||||
|
||||
|
||||
class StocktakeForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = StockItem
|
||||
|
||||
fields = [
|
||||
'quantity',
|
||||
]
|
||||
|
||||
|
||||
class EditStockItemForm(HelperForm):
|
||||
|
||||
class Meta:
|
||||
|
@ -15,6 +15,7 @@ class StockItemSerializer(serializers.ModelSerializer):
|
||||
'part',
|
||||
'supplier_part',
|
||||
'location',
|
||||
'in_stock',
|
||||
'belongs_to',
|
||||
'customer',
|
||||
'quantity',
|
||||
|
@ -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 () {
|
||||
|
@ -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'),
|
||||
]
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user