mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
Add ability to create new stock tracking note for a stock item
This commit is contained in:
parent
310d4b5f07
commit
bb799d98be
@ -308,6 +308,10 @@ function loadStockTrackingTable(table, options) {
|
|||||||
html += "<br><i>" + row.notes + "</i>";
|
html += "<br><i>" + row.notes + "</i>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (row.URL) {
|
||||||
|
html += "<br><a href='" + row.URL + "'>" + row.URL + "</a>";
|
||||||
|
}
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -8,7 +8,7 @@ from __future__ import unicode_literals
|
|||||||
from django import forms
|
from django import forms
|
||||||
from InvenTree.forms import HelperForm
|
from InvenTree.forms import HelperForm
|
||||||
|
|
||||||
from .models import StockLocation, StockItem
|
from .models import StockLocation, StockItem, StockItemTracking
|
||||||
|
|
||||||
|
|
||||||
class EditStockLocationForm(HelperForm):
|
class EditStockLocationForm(HelperForm):
|
||||||
@ -104,3 +104,17 @@ class EditStockItemForm(HelperForm):
|
|||||||
'notes',
|
'notes',
|
||||||
'URL',
|
'URL',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class TrackingEntryForm(HelperForm):
|
||||||
|
""" Form for creating / editing a StockItemTracking object.
|
||||||
|
"""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = StockItemTracking
|
||||||
|
|
||||||
|
fields = [
|
||||||
|
'title',
|
||||||
|
'notes',
|
||||||
|
'URL',
|
||||||
|
]
|
||||||
|
@ -298,7 +298,7 @@ class StockItem(models.Model):
|
|||||||
def has_tracking_info(self):
|
def has_tracking_info(self):
|
||||||
return self.tracking_info.count() > 0
|
return self.tracking_info.count() > 0
|
||||||
|
|
||||||
def addTransactionNote(self, title, user, notes='', system=True):
|
def addTransactionNote(self, title, user, notes='', url='', system=True):
|
||||||
""" Generation a stock transaction note for this item.
|
""" Generation a stock transaction note for this item.
|
||||||
|
|
||||||
Brief automated note detailing a movement or quantity change.
|
Brief automated note detailing a movement or quantity change.
|
||||||
@ -310,6 +310,7 @@ class StockItem(models.Model):
|
|||||||
quantity=self.quantity,
|
quantity=self.quantity,
|
||||||
date=datetime.now().date(),
|
date=datetime.now().date(),
|
||||||
notes=notes,
|
notes=notes,
|
||||||
|
URL=url,
|
||||||
system=system
|
system=system
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -149,6 +149,7 @@ class StockTrackingSerializer(InvenTreeModelSerializer):
|
|||||||
'date',
|
'date',
|
||||||
'title',
|
'title',
|
||||||
'notes',
|
'notes',
|
||||||
|
'URL',
|
||||||
'quantity',
|
'quantity',
|
||||||
'user',
|
'user',
|
||||||
'system',
|
'system',
|
||||||
|
@ -125,19 +125,29 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{% if item.has_tracking_info %}
|
|
||||||
<hr>
|
<hr>
|
||||||
<div id='table-toolbar'>
|
<h4>Stock Tracking Information</h4>
|
||||||
<h4>Stock Tracking Information</h4>
|
<div id='table-toolbar'>
|
||||||
|
<div class='btn-group'>
|
||||||
|
<button class='btn btn-success' type='button' title='New tracking entry' id='new-entry'>New Entry</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<table class='table table-condensed table-striped' id='track-table' data-toolbar='#table-toolbar'>
|
<table class='table table-condensed table-striped' id='track-table' data-toolbar='#table-toolbar'>
|
||||||
</table>
|
</table>
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block js_ready %}
|
{% block js_ready %}
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
|
|
||||||
|
$("#new-entry").click(function() {
|
||||||
|
launchModalForm(
|
||||||
|
"{% url 'stock-tracking-create' item.id %}",
|
||||||
|
{
|
||||||
|
reload: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
$("#stock-duplicate").click(function() {
|
$("#stock-duplicate").click(function() {
|
||||||
launchModalForm(
|
launchModalForm(
|
||||||
"{% url 'stock-item-create' %}",
|
"{% url 'stock-item-create' %}",
|
||||||
@ -152,11 +162,12 @@
|
|||||||
|
|
||||||
$("#stock-edit").click(function () {
|
$("#stock-edit").click(function () {
|
||||||
launchModalForm(
|
launchModalForm(
|
||||||
"{% url 'stock-item-edit' item.id %}",
|
"{% url 'stock-item-edit' item.id %}",
|
||||||
{
|
{
|
||||||
reload: true,
|
reload: true,
|
||||||
submit_text: "Save",
|
submit_text: "Save",
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#show-qr-code").click(function() {
|
$("#show-qr-code").click(function() {
|
||||||
|
@ -21,9 +21,19 @@ stock_item_detail_urls = [
|
|||||||
url(r'^delete/?', views.StockItemDelete.as_view(), name='stock-item-delete'),
|
url(r'^delete/?', views.StockItemDelete.as_view(), name='stock-item-delete'),
|
||||||
url(r'^qr_code/?', views.StockItemQRCode.as_view(), name='stock-item-qr'),
|
url(r'^qr_code/?', views.StockItemQRCode.as_view(), name='stock-item-qr'),
|
||||||
|
|
||||||
|
url(r'^add_tracking/?', views.StockItemTrackingCreate.as_view(), name='stock-tracking-create'),
|
||||||
|
|
||||||
url('^.*$', views.StockItemDetail.as_view(), name='stock-item-detail'),
|
url('^.*$', views.StockItemDetail.as_view(), name='stock-item-detail'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
stock_tracking_urls = [
|
||||||
|
|
||||||
|
# edit
|
||||||
|
|
||||||
|
# list
|
||||||
|
url('^.*$', views.StockTrackingIndex.as_view(), name='stock-tracking-list')
|
||||||
|
]
|
||||||
|
|
||||||
stock_urls = [
|
stock_urls = [
|
||||||
# Stock location
|
# Stock location
|
||||||
url(r'^location/(?P<pk>\d+)/', include(stock_location_detail_urls)),
|
url(r'^location/(?P<pk>\d+)/', include(stock_location_detail_urls)),
|
||||||
@ -32,7 +42,7 @@ stock_urls = [
|
|||||||
|
|
||||||
url(r'^item/new/?', views.StockItemCreate.as_view(), name='stock-item-create'),
|
url(r'^item/new/?', views.StockItemCreate.as_view(), name='stock-item-create'),
|
||||||
|
|
||||||
url(r'^track/?', views.StockTrackingIndex.as_view(), name='stock-tracking-list'),
|
url(r'^track/', include(stock_tracking_urls)),
|
||||||
|
|
||||||
url(r'^adjust/?', views.StockAdjust.as_view(), name='stock-adjust'),
|
url(r'^adjust/?', views.StockAdjust.as_view(), name='stock-adjust'),
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ from InvenTree.views import AjaxUpdateView, AjaxDeleteView, AjaxCreateView
|
|||||||
from InvenTree.views import QRCodeView
|
from InvenTree.views import QRCodeView
|
||||||
|
|
||||||
from InvenTree.helpers import str2bool
|
from InvenTree.helpers import str2bool
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from part.models import Part
|
from part.models import Part
|
||||||
from .models import StockItem, StockLocation, StockItemTracking
|
from .models import StockItem, StockLocation, StockItemTracking
|
||||||
@ -25,6 +26,7 @@ from .forms import EditStockLocationForm
|
|||||||
from .forms import CreateStockItemForm
|
from .forms import CreateStockItemForm
|
||||||
from .forms import EditStockItemForm
|
from .forms import EditStockItemForm
|
||||||
from .forms import AdjustStockForm
|
from .forms import AdjustStockForm
|
||||||
|
from .forms import TrackingEntryForm
|
||||||
|
|
||||||
|
|
||||||
class StockIndex(ListView):
|
class StockIndex(ListView):
|
||||||
@ -588,3 +590,48 @@ class StockTrackingIndex(ListView):
|
|||||||
model = StockItemTracking
|
model = StockItemTracking
|
||||||
template_name = 'stock/tracking.html'
|
template_name = 'stock/tracking.html'
|
||||||
context_object_name = 'items'
|
context_object_name = 'items'
|
||||||
|
|
||||||
|
|
||||||
|
class StockItemTrackingCreate(AjaxCreateView):
|
||||||
|
""" View for creating a new StockItemTracking object.
|
||||||
|
"""
|
||||||
|
|
||||||
|
model = StockItemTracking
|
||||||
|
ajax_form_title = "Add Stock Tracking Entry"
|
||||||
|
form_class = TrackingEntryForm
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
|
||||||
|
self.request = request
|
||||||
|
self.form = self.get_form()
|
||||||
|
|
||||||
|
valid = False
|
||||||
|
|
||||||
|
if self.form.is_valid():
|
||||||
|
stock_id = self.kwargs['pk']
|
||||||
|
|
||||||
|
if stock_id:
|
||||||
|
try:
|
||||||
|
stock_item = StockItem.objects.get(id=stock_id)
|
||||||
|
|
||||||
|
# Save new tracking information
|
||||||
|
tracking = self.form.save(commit=False)
|
||||||
|
tracking.item = stock_item
|
||||||
|
tracking.user = self.request.user
|
||||||
|
tracking.quantity = stock_item.quantity
|
||||||
|
tracking.date=datetime.now().date()
|
||||||
|
tracking.system = False
|
||||||
|
|
||||||
|
tracking.save()
|
||||||
|
|
||||||
|
valid = True
|
||||||
|
|
||||||
|
except (StockItem.DoesNotExist, ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'form_valid': valid
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.renderJsonResponse(request, self.form, data=data)
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user