Skip to content

Commit

Permalink
Updated Part model
Browse files Browse the repository at this point in the history
- Added 'default_location'
- Added 'default_supplier'
  • Loading branch information
SchrodingersGat committed Apr 17, 2018
1 parent 45c5ede commit 982803a
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 1 deletion.
2 changes: 2 additions & 0 deletions InvenTree/part/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Meta:
'description',
'IPN',
'URL',
'default_location',
'default_supplier',
'minimum_stock',
'buildable',
'trackable',
Expand Down
22 changes: 22 additions & 0 deletions InvenTree/part/migrations/0021_part_default_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.12 on 2018-04-17 08:12
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('stock', '0010_stockitem_build'),
('part', '0020_part_salable'),
]

operations = [
migrations.AddField(
model_name='part',
name='default_location',
field=models.ForeignKey(blank=True, help_text='Where is this item normally stored?', null=True, on_delete=django.db.models.deletion.SET_NULL, to='stock.StockLocation'),
),
]
27 changes: 27 additions & 0 deletions InvenTree/part/migrations/0022_auto_20180417_0819.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.12 on 2018-04-17 08:19
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('supplier', '0007_auto_20180416_1253'),
('part', '0021_part_default_location'),
]

operations = [
migrations.AddField(
model_name='part',
name='default_supplier',
field=models.ForeignKey(blank=True, help_text='Default supplier part', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='default_parts', to='supplier.SupplierPart'),
),
migrations.AlterField(
model_name='part',
name='default_location',
field=models.ForeignKey(blank=True, help_text='Where is this item normally stored?', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='default_parts', to='stock.StockLocation'),
),
]
12 changes: 12 additions & 0 deletions InvenTree/part/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ def get_absolute_url(self):

image = models.ImageField(upload_to=rename_part_image, max_length=255, null=True, blank=True)

default_location = models.ForeignKey('stock.StockLocation', on_delete=models.SET_NULL,
blank=True, null=True,
help_text='Where is this item normally stored?',
related_name='default_parts')

# Default supplier part
default_supplier = models.ForeignKey('supplier.SupplierPart',
on_delete=models.SET_NULL,
blank=True, null=True,
help_text='Default supplier part',
related_name='default_parts')

# Minimum "allowed" stock level
minimum_stock = models.PositiveIntegerField(default=0, validators=[MinValueValidator(0)], help_text='Minimum allowed stock level')

Expand Down
12 changes: 12 additions & 0 deletions InvenTree/part/templates/part/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ <h3>Part Details</h3>
{% endif %}
</td>
</tr>
{% if part.default_location %}
<tr>
<td>Default Location</td>
<td>{{ part.default_location.pathstring }}</td>
</tr>
{% endif %}
{% if part.default_supplier %}
<tr>
<td>Default Supplier</td>
<td>{{ part.default_supplier.supplier.name }} | {{ part.default_supplier.SKU }}</td>
</tr>
{% endif %}
<tr>
<td>Units</td>
<td>{{ part.units }}</td>
Expand Down
6 changes: 5 additions & 1 deletion InvenTree/stock/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ def get_initial(self):
loc_id = self.request.GET.get('location', None)

if part_id:
initials['part'] = get_object_or_404(Part, pk=part_id)
part = get_object_or_404(Part, pk=part_id)
if part:
initials['part'] = get_object_or_404(Part, pk=part_id)
initials['location'] = part.default_location
initials['supplier_part'] = part.default_supplier

if loc_id:
initials['location'] = get_object_or_404(StockLocation, pk=loc_id)
Expand Down

0 comments on commit 982803a

Please sign in to comment.