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

"Fixes" for completing a build

- This will require a lot of unit testing to get right
This commit is contained in:
Oliver Walters
2020-04-26 00:32:09 +10:00
parent 72c43d0c2d
commit 0892b160c6
6 changed files with 85 additions and 29 deletions

View File

@ -314,7 +314,6 @@ class StockList(generics.ListCreateAPIView):
- POST: Create a new StockItem
Additional query parameters are available:
- aggregate: If 'true' then stock items are aggregated by Part and Location
- location: Filter stock by location
- category: Filter by parts belonging to a certain category
- supplier: Filter by supplier
@ -370,10 +369,10 @@ class StockList(generics.ListCreateAPIView):
if in_stock:
# Filter out parts which are not actually "in stock"
stock_list = stock_list.filter(customer=None, belongs_to=None)
stock_list = stock_list.filter(customer=None, belongs_to=None, build_order=None)
else:
# Only show parts which are not in stock
stock_list = stock_list.exclude(customer=None, belongs_to=None)
stock_list = stock_list.exclude(customer=None, belongs_to=None, build_order=None)
# Filter by 'allocated' patrs?
allocated = self.request.query_params.get('allocated', None)
@ -516,6 +515,7 @@ class StockList(generics.ListCreateAPIView):
'belongs_to',
'build',
'sales_order',
'build_order',
]

View File

@ -0,0 +1,20 @@
# Generated by Django 3.0.5 on 2020-04-25 14:02
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('build', '0015_auto_20200425_1350'),
('stock', '0031_auto_20200422_0209'),
]
operations = [
migrations.AddField(
model_name='stockitem',
name='build_order',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='stock_items', to='build.Build'),
),
]

View File

@ -130,6 +130,7 @@ class StockItem(MPTTModel):
purchase_order: Link to a PurchaseOrder (if this stock item was created from a PurchaseOrder)
infinite: If True this StockItem can never be exhausted
sales_order: Link to a SalesOrder object (if the StockItem has been assigned to a SalesOrder)
build_order: Link to a BuildOrder object (if the StockItem has been assigned to a BuildOrder)
"""
def save(self, *args, **kwargs):
@ -363,6 +364,13 @@ class StockItem(MPTTModel):
related_name='stock_items',
null=True, blank=True)
build_order = models.ForeignKey(
'build.Build',
on_delete=models.SET_NULL,
related_name='stock_items',
null=True, blank=True
)
# last time the stock was checked / counted
stocktake_date = models.DateField(blank=True, null=True)
@ -439,6 +447,8 @@ class StockItem(MPTTModel):
- Has child StockItems
- Has a serial number and is tracked
- Is installed inside another StockItem
- It has been delivered to a customer
- It has been assigned to a BuildOrder
"""
if self.child_count > 0:
@ -447,6 +457,12 @@ class StockItem(MPTTModel):
if self.part.trackable and self.serial is not None:
return False
if self.customer is not None:
return False
if self.build_order is not None:
return False
return True
@property
@ -464,7 +480,16 @@ class StockItem(MPTTModel):
@property
def in_stock(self):
if self.belongs_to or self.customer:
# Not 'in stock' if it has been installed inside another StockItem
if self.belongs_to is not None:
return False
# Not 'in stock' if it has been sent to a customer
if self.customer is not None:
return False
# Not 'in stock' if it has been allocated to a BuildOrder
if self.build_order is not None:
return False
return True
@ -642,6 +667,7 @@ class StockItem(MPTTModel):
self.take_stock(quantity, user, 'Split {n} items into new stock item'.format(n=quantity))
# Return a copy of the "new" stock item
return new_stock
@transaction.atomic
def move(self, location, notes, user, **kwargs):