mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Part stuff
This commit is contained in:
parent
4a2b6a5674
commit
b24ddac0b8
@ -12,7 +12,6 @@ from .serializers import PartSerializer
|
|||||||
|
|
||||||
from InvenTree.views import TreeSerializer
|
from InvenTree.views import TreeSerializer
|
||||||
|
|
||||||
|
|
||||||
class PartCategoryTree(TreeSerializer):
|
class PartCategoryTree(TreeSerializer):
|
||||||
|
|
||||||
title = "Parts"
|
title = "Parts"
|
||||||
|
@ -82,7 +82,7 @@ class Part(models.Model):
|
|||||||
""" Represents an abstract part
|
""" Represents an abstract part
|
||||||
Parts can be "stocked" in multiple warehouses,
|
Parts can be "stocked" in multiple warehouses,
|
||||||
and can be combined to form other parts
|
and can be combined to form other parts
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return '/part/{id}/'.format(id=self.id)
|
return '/part/{id}/'.format(id=self.id)
|
||||||
@ -256,18 +256,19 @@ class Part(models.Model):
|
|||||||
self.allocated_build_count,
|
self.allocated_build_count,
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def stock_entries(self):
|
||||||
|
return [loc for loc in self.locations.all() if loc.in_stock]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def total_stock(self):
|
def total_stock(self):
|
||||||
""" Return the total stock quantity for this part.
|
""" Return the total stock quantity for this part.
|
||||||
Part may be stored in multiple locations
|
Part may be stored in multiple locations
|
||||||
"""
|
"""
|
||||||
|
|
||||||
stocks = self.locations.all()
|
return sum([loc.quantity for loc in self.stock_entries])
|
||||||
if len(stocks) == 0:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
result = stocks.aggregate(total=Sum('quantity'))
|
|
||||||
return result['total']
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def has_bom(self):
|
def has_bom(self):
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for stock in part.locations.all %}
|
{% for stock in part.stock_entries %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{% url 'stock-item-detail' stock.id %}">Click</a></td>
|
<td><a href="{% url 'stock-item-detail' stock.id %}">Click</a></td>
|
||||||
<td>
|
<td>
|
||||||
|
21
InvenTree/stock/migrations/0002_auto_20180430_1218.py
Normal file
21
InvenTree/stock/migrations/0002_auto_20180430_1218.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.12 on 2018-04-30 12:18
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('stock', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='stockitem',
|
||||||
|
name='quantity',
|
||||||
|
field=models.PositiveIntegerField(default=1, validators=[django.core.validators.MinValueValidator(0)]),
|
||||||
|
),
|
||||||
|
]
|
@ -130,7 +130,7 @@ class StockItem(models.Model):
|
|||||||
# build = models.ForeignKey('build.Build', on_delete=models.SET_NULL, blank=True, null=True)
|
# build = models.ForeignKey('build.Build', on_delete=models.SET_NULL, blank=True, null=True)
|
||||||
|
|
||||||
# Quantity of this stock item. Value may be overridden by other settings
|
# Quantity of this stock item. Value may be overridden by other settings
|
||||||
quantity = models.PositiveIntegerField(validators=[MinValueValidator(0)])
|
quantity = models.PositiveIntegerField(validators=[MinValueValidator(0)], default=1)
|
||||||
|
|
||||||
# Last time this item was updated (set automagically)
|
# Last time this item was updated (set automagically)
|
||||||
updated = models.DateField(auto_now=True)
|
updated = models.DateField(auto_now=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user