mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge branch 'stock-improvements'
This commit is contained in:
commit
1dcbff9bcd
@ -38,6 +38,8 @@ class CreateStockItemForm(HelperForm):
|
||||
|
||||
class MoveStockItemForm(forms.ModelForm):
|
||||
|
||||
note = forms.CharField(label='Notes', required=True)
|
||||
|
||||
class Meta:
|
||||
model = StockItem
|
||||
|
||||
@ -62,7 +64,7 @@ class EditStockItemForm(HelperForm):
|
||||
model = StockItem
|
||||
|
||||
fields = [
|
||||
'quantity',
|
||||
'batch',
|
||||
'status',
|
||||
'notes'
|
||||
]
|
@ -0,0 +1,19 @@
|
||||
# Generated by Django 2.2 on 2019-04-12 14:09
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0004_auto_20190412_2030'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='stockitemtracking',
|
||||
name='quantity',
|
||||
field=models.PositiveIntegerField(default=1, validators=[django.core.validators.MinValueValidator(0)]),
|
||||
),
|
||||
]
|
@ -209,6 +209,7 @@ class StockItem(models.Model):
|
||||
item=self,
|
||||
title=title,
|
||||
user=user,
|
||||
quantity=self.quantity,
|
||||
date=datetime.now().date(),
|
||||
notes=notes,
|
||||
system=system
|
||||
@ -217,21 +218,24 @@ class StockItem(models.Model):
|
||||
track.save()
|
||||
|
||||
@transaction.atomic
|
||||
def move(self, location, user):
|
||||
def move(self, location, notes, user):
|
||||
|
||||
if location == self.location:
|
||||
return
|
||||
if location.pk == self.location.pk:
|
||||
return False # raise forms.ValidationError("Cannot move item to its current location")
|
||||
|
||||
note = "Moved to {loc}".format(loc=location.name)
|
||||
msg = "Moved to {loc} (from {src})".format(loc=location.name,
|
||||
src=self.location.name)
|
||||
|
||||
self.location = location
|
||||
self.save()
|
||||
|
||||
self.add_transaction_note('Transfer',
|
||||
self.add_transaction_note(msg,
|
||||
user,
|
||||
notes=note,
|
||||
notes=notes,
|
||||
system=True)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
def stocktake(self, count, user, notes=''):
|
||||
@ -343,6 +347,9 @@ class StockItemTracking(models.Model):
|
||||
# Was this tracking note auto-generated by the system?
|
||||
system = models.BooleanField(default=False)
|
||||
|
||||
# Keep track of the StockItem quantity throughout the tracking history
|
||||
quantity = models.PositiveIntegerField(validators=[MinValueValidator(0)], default=1)
|
||||
|
||||
# TODO
|
||||
# image = models.ImageField(upload_to=func, max_length=255, null=True, blank=True)
|
||||
|
||||
|
@ -35,6 +35,7 @@ class StockTrackingSerializer(serializers.ModelSerializer):
|
||||
'date',
|
||||
'title',
|
||||
'notes',
|
||||
'quantity',
|
||||
'user',
|
||||
'system',
|
||||
]
|
||||
@ -43,6 +44,7 @@ class StockTrackingSerializer(serializers.ModelSerializer):
|
||||
'date',
|
||||
'user',
|
||||
'system',
|
||||
'quantity',
|
||||
]
|
||||
|
||||
|
||||
|
@ -15,11 +15,11 @@
|
||||
<span class="caret"></span></button>
|
||||
<ul class="dropdown-menu">
|
||||
{% if item.in_stock %}
|
||||
<li><a href='#' id='stock-stocktake' title='Count stock'>Stocktake</a></li>
|
||||
<li><a href='#' id='stock-add' title='Add stock'>Add to stock</a></li>
|
||||
<li><a href='#' id='stock-remove' title='Remove stock'>Remove from stock</a></li>
|
||||
<li><a href="#" id='stock-edit' title='Edit stock item'>Edit stock item</a></li>
|
||||
<li><a href="#" id='stock-move' title='Move stock item'>Move stock item</a></li>
|
||||
<li><a href='#' id='stock-add' title='Add stock'>Add to stock</a></li>
|
||||
<li><a href='#' id='stock-remove' title='Remove stock'>Remove from stock</a></li>
|
||||
<li><a href='#' id='stock-stocktake' title='Count stock'>Stocktake</a></li>
|
||||
{% endif %}
|
||||
<li><a href="#" id='stock-delete' title='Delete stock item'>Delete stock item</a></li>
|
||||
</ul>
|
||||
@ -215,12 +215,24 @@
|
||||
return html;
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'quantity',
|
||||
title: 'Quantity',
|
||||
},
|
||||
{
|
||||
sortable: true,
|
||||
field: 'user',
|
||||
title: 'User',
|
||||
formatter: function(value, row, index, field) {
|
||||
return value.username;
|
||||
if (value)
|
||||
{
|
||||
// TODO - Format the user's first and last names
|
||||
return value.username;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "No user information";
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -142,20 +142,26 @@ class StockItemMove(AjaxUpdateView):
|
||||
|
||||
if form.is_valid():
|
||||
|
||||
obj = form.save()
|
||||
obj = self.get_object()
|
||||
|
||||
try:
|
||||
loc = StockLocation.objects.get(pk=form['location'].value())
|
||||
loc_path = loc.pathstring
|
||||
loc_id = form['location'].value()
|
||||
|
||||
if loc_id:
|
||||
loc = StockLocation.objects.get(pk=form['location'].value())
|
||||
if str(loc.pk) == str(obj.pk):
|
||||
form.errors['location'] = ['Item is already in this location']
|
||||
else:
|
||||
obj.move(loc, form['note'].value(), request.user)
|
||||
else:
|
||||
form.errors['location'] = ['Cannot move to an empty location']
|
||||
|
||||
except StockLocation.DoesNotExist:
|
||||
loc_path = ''
|
||||
|
||||
obj.add_transaction_note("Moved item to '{where}'".format(where=loc_path),
|
||||
request.user,
|
||||
system=True)
|
||||
form.errors['location'] = ['Location does not exist']
|
||||
|
||||
data = {
|
||||
'form_valid': form.is_valid(),
|
||||
'form_valid': form.is_valid() and len(form.errors) == 0,
|
||||
}
|
||||
|
||||
return self.renderJsonResponse(request, form, data)
|
||||
|
Loading…
Reference in New Issue
Block a user