Merge pull request #459 from SchrodingersGat/build-tracking

Add a reference to a build for a stock item
This commit is contained in:
Oliver 2019-09-01 23:31:08 +10:00 committed by GitHub
commit 0be54a762f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 12 deletions

View File

@ -237,6 +237,7 @@ class Build(models.Model):
for serial in serial_numbers: for serial in serial_numbers:
item = StockItem.objects.create( item = StockItem.objects.create(
part=self.part, part=self.part,
build=self,
location=location, location=location,
quantity=1, quantity=1,
serial=serial, serial=serial,
@ -250,6 +251,7 @@ class Build(models.Model):
# Add stock of the newly created item # Add stock of the newly created item
item = StockItem.objects.create( item = StockItem.objects.create(
part=self.part, part=self.part,
build=self,
location=location, location=location,
quantity=self.quantity, quantity=self.quantity,
batch=str(self.batch) if self.batch else '', batch=str(self.batch) if self.batch else '',

View File

@ -0,0 +1,20 @@
# Generated by Django 2.2.4 on 2019-09-01 13:08
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('build', '0005_auto_20190604_2217'),
('stock', '0009_auto_20190715_2351'),
]
operations = [
migrations.AddField(
model_name='stockitem',
name='build',
field=models.ForeignKey(blank=True, help_text='Build for this stock item', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='build_outputs', to='build.Build'),
),
]

View File

@ -101,6 +101,7 @@ class StockItem(models.Model):
delete_on_deplete: If True, StockItem will be deleted when the stock level gets to zero delete_on_deplete: If True, StockItem will be deleted when the stock level gets to zero
status: Status of this StockItem (ref: InvenTree.status_codes.StockStatus) status: Status of this StockItem (ref: InvenTree.status_codes.StockStatus)
notes: Extra notes field notes: Extra notes field
build: Link to a Build (if this stock item was created from a build)
purchase_order: Link to a PurchaseOrder (if this stock item was created from a PurchaseOrder) purchase_order: Link to a PurchaseOrder (if this stock item was created from a PurchaseOrder)
infinite: If True this StockItem can never be exhausted infinite: If True this StockItem can never be exhausted
""" """
@ -300,6 +301,13 @@ class StockItem(models.Model):
updated = models.DateField(auto_now=True, null=True) updated = models.DateField(auto_now=True, null=True)
build = models.ForeignKey(
'build.Build', on_delete=models.SET_NULL,
blank=True, null=True,
help_text='Build for this stock item',
related_name='build_outputs',
)
purchase_order = models.ForeignKey( purchase_order = models.ForeignKey(
'order.PurchaseOrder', 'order.PurchaseOrder',
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
@ -484,20 +492,13 @@ class StockItem(models.Model):
return return
# Create a new StockItem object, duplicating relevant fields # Create a new StockItem object, duplicating relevant fields
new_stock = StockItem.objects.create( # Nullify the PK so a new record is created
part=self.part, new_stock = StockItem.objects.get(pk=self.pk)
quantity=quantity, new_stock.pk = None
supplier_part=self.supplier_part, new_stock.quantity = quantity
location=self.location,
notes=self.notes,
URL=self.URL,
batch=self.batch,
delete_on_deplete=self.delete_on_deplete
)
new_stock.save() new_stock.save()
# Copy the transaction history # Copy the transaction history of this part into the new one
new_stock.copyHistoryFrom(self) new_stock.copyHistoryFrom(self)
# Add a new tracking item for the new stock item # Add a new tracking item for the new stock item

View File

@ -90,6 +90,12 @@
<td>{{ item.batch }}</td> <td>{{ item.batch }}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if item.build %}
<tr>
<td>Build</td>
<td><a href="{% url 'build-detail' item.build.id %}">{{ item.build }}</a></td>
</tr>
{% endif %}
{% if item.purchase_order %} {% if item.purchase_order %}
<tr> <tr>
<td>Purchase Order</td> <td>Purchase Order</td>

View File

@ -14,6 +14,7 @@ migrate:
python3 InvenTree/manage.py makemigrations stock python3 InvenTree/manage.py makemigrations stock
python3 InvenTree/manage.py makemigrations build python3 InvenTree/manage.py makemigrations build
python3 InvenTree/manage.py makemigrations order python3 InvenTree/manage.py makemigrations order
python3 InvenTree/manage.py migrate
python3 InvenTree/manage.py migrate --run-syncdb python3 InvenTree/manage.py migrate --run-syncdb
python3 InvenTree/manage.py check python3 InvenTree/manage.py check