mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 20:45:44 +00:00
Fix deletion of part category and stock location
- Category up part updated to parent - Location of item updated to parent
This commit is contained in:
21
InvenTree/stock/migrations/0004_auto_20180414_1032.py
Normal file
21
InvenTree/stock/migrations/0004_auto_20180414_1032.py
Normal file
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11 on 2018-04-14 10:32
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0003_auto_20180413_1230'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='stockitem',
|
||||
name='location',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='items', to='stock.StockLocation'),
|
||||
),
|
||||
]
|
@ -11,6 +11,8 @@ from InvenTree.models import InvenTreeTree
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from django.db.models.signals import pre_delete
|
||||
from django.dispatch import receiver
|
||||
|
||||
class StockLocation(InvenTreeTree):
|
||||
""" Organization tree for StockItem objects
|
||||
@ -24,12 +26,21 @@ class StockLocation(InvenTreeTree):
|
||||
return stock_list
|
||||
|
||||
|
||||
@receiver(pre_delete, sender=StockLocation, dispatch_uid='stocklocation_delete_log')
|
||||
def before_delete_stock_location(sender, instance, using, **kwargs):
|
||||
|
||||
# Update each part in the stock location
|
||||
for item in instance.items.all():
|
||||
item.location = instance.parent
|
||||
item.save()
|
||||
|
||||
class StockItem(models.Model):
|
||||
part = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='locations')
|
||||
|
||||
supplier_part = models.ForeignKey(SupplierPart, blank=True, null=True, on_delete=models.SET_NULL)
|
||||
|
||||
location = models.ForeignKey(StockLocation, on_delete=models.CASCADE)
|
||||
location = models.ForeignKey(StockLocation, on_delete=models.DO_NOTHING,
|
||||
related_name='items', blank=True, null=True)
|
||||
|
||||
quantity = models.PositiveIntegerField(validators=[MinValueValidator(0)])
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div class="container">
|
||||
<div class="navigation">
|
||||
<a href="/stock/list/">Stock</a> >
|
||||
{% if location %}
|
||||
{% for path_item in location.parentpath %}
|
||||
|
Reference in New Issue
Block a user