mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Prevent stock adjustments for serialized stock items
This commit is contained in:
parent
94c0102742
commit
fe7392f152
@ -122,6 +122,11 @@ class StockItem(models.Model):
|
|||||||
system=True
|
system=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def serialized(self):
|
||||||
|
""" Return True if this StockItem is serialized """
|
||||||
|
return self.serial is not None and self.quantity == 1
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def check_serial_number(cls, part, serial_number):
|
def check_serial_number(cls, part, serial_number):
|
||||||
""" Check if a new stock item can be created with the provided part_id
|
""" Check if a new stock item can be created with the provided part_id
|
||||||
@ -358,6 +363,14 @@ class StockItem(models.Model):
|
|||||||
|
|
||||||
track.save()
|
track.save()
|
||||||
|
|
||||||
|
@transaction.atomic
|
||||||
|
def serializeStock(self, serials, user):
|
||||||
|
""" Split this stock item into unique serial numbers.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
pass
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def splitStock(self, quantity, user):
|
def splitStock(self, quantity, user):
|
||||||
""" Split this stock item into two items, in the same location.
|
""" Split this stock item into two items, in the same location.
|
||||||
@ -372,6 +385,10 @@ class StockItem(models.Model):
|
|||||||
The new item will have a different StockItem ID, while this will remain the same.
|
The new item will have a different StockItem ID, while this will remain the same.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Do not split a serialized part
|
||||||
|
if self.serialized:
|
||||||
|
return
|
||||||
|
|
||||||
# Doesn't make sense for a zero quantity
|
# Doesn't make sense for a zero quantity
|
||||||
if quantity <= 0:
|
if quantity <= 0:
|
||||||
return
|
return
|
||||||
@ -461,6 +478,10 @@ class StockItem(models.Model):
|
|||||||
- False if the StockItem was deleted
|
- False if the StockItem was deleted
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Do not adjust quantity of a serialized part
|
||||||
|
if self.serialized:
|
||||||
|
return
|
||||||
|
|
||||||
if quantity < 0:
|
if quantity < 0:
|
||||||
quantity = 0
|
quantity = 0
|
||||||
|
|
||||||
@ -504,6 +525,10 @@ class StockItem(models.Model):
|
|||||||
or by manually adding the items to the stock location
|
or by manually adding the items to the stock location
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Cannot add items to a serialized part
|
||||||
|
if self.serialized:
|
||||||
|
return False
|
||||||
|
|
||||||
quantity = int(quantity)
|
quantity = int(quantity)
|
||||||
|
|
||||||
# Ignore amounts that do not make sense
|
# Ignore amounts that do not make sense
|
||||||
@ -524,6 +549,10 @@ class StockItem(models.Model):
|
|||||||
""" Remove items from stock
|
""" Remove items from stock
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Cannot remove items from a serialized part
|
||||||
|
if self.serialized:
|
||||||
|
return False
|
||||||
|
|
||||||
quantity = int(quantity)
|
quantity = int(quantity)
|
||||||
|
|
||||||
if quantity <= 0 or self.infinite:
|
if quantity <= 0 or self.infinite:
|
||||||
|
@ -5,11 +5,16 @@
|
|||||||
<div class='row'>
|
<div class='row'>
|
||||||
<div class='col-sm-6'>
|
<div class='col-sm-6'>
|
||||||
<h3>Stock Item Details</h3>
|
<h3>Stock Item Details</h3>
|
||||||
|
{% if item.serialized %}
|
||||||
|
<p><i>{{ item.part.full_name}} # {{ item.serial }}</i></p>
|
||||||
|
{% else %}
|
||||||
<p><i>{{ item.quantity }} × {{ item.part.full_name }}</i></p>
|
<p><i>{{ item.quantity }} × {{ item.part.full_name }}</i></p>
|
||||||
|
{% endif %}
|
||||||
<p>
|
<p>
|
||||||
<div class='btn-group'>
|
<div class='btn-group'>
|
||||||
{% include "qr_button.html" %}
|
{% include "qr_button.html" %}
|
||||||
{% if item.in_stock %}
|
{% if item.in_stock %}
|
||||||
|
{% if not item.serialized %}
|
||||||
<button type='button' class='btn btn-default btn-glyph' id='stock-add' title='Add to stock'>
|
<button type='button' class='btn btn-default btn-glyph' id='stock-add' title='Add to stock'>
|
||||||
<span class='glyphicon glyphicon-plus-sign' style='color: #1a1;'/>
|
<span class='glyphicon glyphicon-plus-sign' style='color: #1a1;'/>
|
||||||
</button>
|
</button>
|
||||||
@ -19,6 +24,7 @@
|
|||||||
<button type='button' class='btn btn-default btn-glyph' id='stock-count' title='Count stock'>
|
<button type='button' class='btn btn-default btn-glyph' id='stock-count' title='Count stock'>
|
||||||
<span class='glyphicon glyphicon-ok-circle'/>
|
<span class='glyphicon glyphicon-ok-circle'/>
|
||||||
</button>
|
</button>
|
||||||
|
{% endif %}
|
||||||
<button type='button' class='btn btn-default btn-glyph' id='stock-move' title='Transfer stock'>
|
<button type='button' class='btn btn-default btn-glyph' id='stock-move' title='Transfer stock'>
|
||||||
<span class='glyphicon glyphicon-transfer' style='color: #11a;'/>
|
<span class='glyphicon glyphicon-transfer' style='color: #11a;'/>
|
||||||
</button>
|
</button>
|
||||||
@ -34,6 +40,11 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</p>
|
</p>
|
||||||
|
{% if item.serialized %}
|
||||||
|
<div class='alert alert-block alert-info'>
|
||||||
|
This stock item is serialized - it has a unique serial number and the quantity cannot be adjusted.
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class='row'>
|
<div class='row'>
|
||||||
@ -54,9 +65,9 @@
|
|||||||
<td><a href="{% url 'stock-location-detail' item.location.id %}">{{ item.location.name }}</a></td>
|
<td><a href="{% url 'stock-location-detail' item.location.id %}">{{ item.location.name }}</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if item.serial %}
|
{% if item.serialized %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>Serial</td>
|
<td>Serial Number</td>
|
||||||
<td>{{ item.serial }}</td>
|
<td>{{ item.serial }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -429,6 +429,9 @@ class StockItemEdit(AjaxUpdateView):
|
|||||||
query = query.filter(part=item.part.id)
|
query = query.filter(part=item.part.id)
|
||||||
form.fields['supplier_part'].queryset = query
|
form.fields['supplier_part'].queryset = query
|
||||||
|
|
||||||
|
if not item.part.trackable:
|
||||||
|
form.fields.pop('serial')
|
||||||
|
|
||||||
return form
|
return form
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user