2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 19:20:55 +00:00

Merge remote-tracking branch 'inventree/master'

This commit is contained in:
Oliver Walters
2020-04-06 16:25:48 +10:00
40 changed files with 297 additions and 94 deletions

View File

@ -59,6 +59,22 @@ class StockDetail(generics.RetrieveUpdateDestroyAPIView):
serializer_class = StockItemSerializer
permission_classes = (permissions.IsAuthenticated,)
def get_serializer(self, *args, **kwargs):
try:
kwargs['part_detail'] = str2bool(self.request.GET.get('part_detail', False))
except AttributeError:
pass
try:
kwargs['location_detail'] = str2bool(self.request.GET.get('location_detail', False))
except AttributeError:
pass
kwargs['context'] = self.get_serializer_context()
return self.serializer_class(*args, **kwargs)
class StockFilter(FilterSet):
""" FilterSet for advanced stock filtering.
@ -317,6 +333,7 @@ class StockList(generics.ListCreateAPIView):
'batch',
'status',
'notes',
'link',
'location',
'location__name',
'location__description',
@ -340,12 +357,17 @@ class StockList(generics.ListCreateAPIView):
img = item['part__image']
# Use the thumbnail image instead
fn, ext = os.path.splitext(img)
if img:
# Use the thumbnail image instead
fn, ext = os.path.splitext(img)
thumb = "{fn}.thumbnail{ext}".format(fn=fn, ext=ext)
thumb = "{fn}.thumbnail{ext}".format(fn=fn, ext=ext)
item['part__thumbnail'] = os.path.join(settings.MEDIA_URL, thumb)
thumb = os.path.join(settings.MEDIA_URL, thumb)
else:
thumb = ''
item['part__thumbnail'] = thumb
del item['part__image']

View File

@ -42,9 +42,9 @@ class CreateStockItemForm(HelperForm):
'quantity',
'batch',
'serial_numbers',
'link',
'delete_on_deplete',
'status',
'URL',
]
# Custom clean to prevent complex StockItem.clean() logic from running (yet)
@ -161,7 +161,7 @@ class EditStockItemForm(HelperForm):
'serial',
'batch',
'status',
'URL',
'link',
'delete_on_deplete',
]
@ -176,5 +176,5 @@ class TrackingEntryForm(HelperForm):
fields = [
'title',
'notes',
'URL',
'link',
]

View File

@ -0,0 +1,19 @@
# Generated by Django 2.2.10 on 2020-04-05 22:39
import InvenTree.fields
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('stock', '0023_auto_20200318_1027'),
]
operations = [
migrations.AlterField(
model_name='stockitem',
name='URL',
field=InvenTree.fields.InvenTreeURLField(blank=True, help_text='Link to external URL', max_length=125),
),
]

View File

@ -0,0 +1,23 @@
# Generated by Django 2.2.10 on 2020-04-05 22:43
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('stock', '0024_auto_20200405_2239'),
]
operations = [
migrations.RenameField(
model_name='stockitem',
old_name='URL',
new_name='link',
),
migrations.RenameField(
model_name='stockitemtracking',
old_name='URL',
new_name='link',
),
]

View File

@ -114,7 +114,7 @@ class StockItem(MPTTModel):
quantity: Number of stocked units
batch: Batch number for this StockItem
serial: Unique serial number for this StockItem
URL: Optional URL to link to external resource
link: Optional URL to link to external resource
updated: Date that this stock item was last updated (auto)
stocktake_date: Date of last stocktake for this item
stocktake_user: User that performed the most recent stocktake
@ -328,7 +328,7 @@ class StockItem(MPTTModel):
serial = models.PositiveIntegerField(blank=True, null=True,
help_text=_('Serial number for this item'))
URL = InvenTreeURLField(max_length=125, blank=True)
link = InvenTreeURLField(max_length=125, blank=True, help_text=_("Link to external URL"))
batch = models.CharField(max_length=100, blank=True, null=True,
help_text=_('Batch code for this stock item'))
@ -427,7 +427,7 @@ class StockItem(MPTTModel):
quantity=self.quantity,
date=datetime.now().date(),
notes=notes,
URL=url,
link=url,
system=system
)
@ -793,7 +793,7 @@ class StockItemTracking(models.Model):
date: Date that this tracking info was created
title: Title of this tracking info (generated by system)
notes: Associated notes (input by user)
URL: Optional URL to external page
link: Optional URL to external page
user: The user associated with this tracking info
quantity: The StockItem quantity at this point in time
"""
@ -811,7 +811,7 @@ class StockItemTracking(models.Model):
notes = models.CharField(blank=True, max_length=512, help_text=_('Entry notes'))
URL = InvenTreeURLField(blank=True, help_text=_('Link to external page for further information'))
link = InvenTreeURLField(blank=True, help_text=_('Link to external page for further information'))
user = models.ForeignKey(User, on_delete=models.SET_NULL, blank=True, null=True)

View File

@ -59,6 +59,8 @@ class StockItemSerializer(InvenTreeModelSerializer):
part_name = serializers.CharField(source='get_part_name', read_only=True)
part_image = serializers.CharField(source='part__image', read_only=True)
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
location_detail = LocationBriefSerializer(source='location', many=False, read_only=True)
@ -78,21 +80,23 @@ class StockItemSerializer(InvenTreeModelSerializer):
class Meta:
model = StockItem
fields = [
'pk',
'url',
'part',
'part_name',
'part_detail',
'supplier_part',
'batch',
'in_stock',
'link',
'location',
'location_detail',
'in_stock',
'notes',
'part',
'part_detail',
'part_name',
'part_image',
'pk',
'quantity',
'serial',
'batch',
'supplier_part',
'status',
'status_text',
'notes',
'url',
]
""" These fields are read-only in this context.
@ -152,7 +156,7 @@ class StockTrackingSerializer(InvenTreeModelSerializer):
'date',
'title',
'notes',
'URL',
'link',
'quantity',
'user',
'system',

View File

@ -74,6 +74,7 @@
<div class='col-sm-6'>
<table class="table table-striped">
<tr>
<td><span class='fas fa-shapes'></span></td>
<td>Part</td>
<td>
{% include "hover_image.html" with image=item.part.image hover=True %}
@ -82,71 +83,84 @@
</tr>
{% if item.belongs_to %}
<tr>
<td></td>
<td>{% trans "Belongs To" %}</td>
<td><a href="{% url 'stock-item-detail' item.belongs_to.id %}">{{ item.belongs_to }}</a></td>
</tr>
{% elif item.location %}
<tr>
<td><span class='fas fa-map-marker-alt'></span></td>
<td>{% trans "Location" %}</td>
<td><a href="{% url 'stock-location-detail' item.location.id %}">{{ item.location.name }}</a></td>
</tr>
{% endif %}
{% if item.serialized %}
<tr>
<td></td>
<td>{% trans "Serial Number" %}</td>
<td>{{ item.serial }}</td>
</tr>
{% else %}
<tr>
<td></td>
<td>{% trans "Quantity" %}</td>
<td>{% decimal item.quantity %} {% if item.part.units %}{{ item.part.units }}{% endif %}</td>
</tr>
{% endif %}
{% if item.batch %}
<tr>
<td></td>
<td>{% trans "Batch" %}</td>
<td>{{ item.batch }}</td>
</tr>
{% endif %}
{% if item.build %}
<tr>
<td><span class='fas fa-tools'></span></td>
<td>{% trans "Build" %}</td>
<td><a href="{% url 'build-detail' item.build.id %}">{{ item.build }}</a></td>
</tr>
{% endif %}
{% if item.purchase_order %}
<tr>
<td></td>
<td>{% trans "Purchase Order" %}</td>
<td><a href="{% url 'po-detail' item.purchase_order.id %}">{{ item.purchase_order }}</a></td>
</tr>
{% endif %}
{% if item.customer %}
<tr>
<td></td>
<td>{% trans "Customer" %}</td>
<td>{{ item.customer.name }}</td>
</tr>
{% endif %}
{% if item.URL %}
{% if item.link %}
<tr>
<td>{% trans "URL" %}</td>
<td><a href="{{ item.URL }}">{{ item.URL }}</a></td>
<td><span class='fas fa-link'></span>
<td>{% trans "External Link" %}</td>
<td><a href="{{ item.link }}">{{ item.link }}</a></td>
</tr>
{% endif %}
{% if item.supplier_part %}
<tr>
<td><span class='fas fa-industry'></span></td>
<td>{% trans "Supplier" %}</td>
<td><a href="{% url 'company-detail' item.supplier_part.supplier.id %}">{{ item.supplier_part.supplier.name }}</a></td>
</tr>
<tr>
<td><span class='fas fa-shapes'></span></td>
<td>{% trans "Supplier Part" %}</td>
<td><a href="{% url 'supplier-part-detail' item.supplier_part.id %}">{{ item.supplier_part.SKU }}</a></td>
</tr>
{% endif %}
<tr>
<td><span class='fas fa-calendar-alt'></span></td>
<td>{% trans "Last Updated" %}</td>
<td>{{ item.updated }}</td>
</tr>
<tr>
<td><span class='fas fa-calendar-alt'></span></td>
<td>{% trans "Last Stocktake" %}</td>
{% if item.stocktake_date %}
<td>{{ item.stocktake_date }} <span class='badge'>{{ item.stocktake_user }}</span></td>
@ -155,6 +169,7 @@
{% endif %}
</tr>
<tr>
<td><span class='fas fa-info'></span></td>
<td>{% trans "Status" %}</td>
<td>{{ item.get_status_display }}</td>
</tr>

View File

@ -934,7 +934,7 @@ class StockItemCreate(AjaxCreateView):
batch=form_data.get('batch'),
delete_on_deplete=False,
status=form_data.get('status'),
URL=form_data.get('URL'),
link=form_data.get('link'),
)
item.save(user=request.user)