mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +00:00
Merge pull request #2 from SchrodingersGat/part-quantity
Started work on cross-referencing
This commit is contained in:
commit
457d72a3e4
@ -4,7 +4,7 @@ from .models import PartCategory, Part
|
|||||||
|
|
||||||
class PartAdmin(admin.ModelAdmin):
|
class PartAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
list_display = ('name', 'IPN', 'category')
|
list_display = ('name', 'IPN', 'quantity', 'category')
|
||||||
|
|
||||||
# Custom form for PartCategory
|
# Custom form for PartCategory
|
||||||
class PartCategoryAdmin(admin.ModelAdmin):
|
class PartCategoryAdmin(admin.ModelAdmin):
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.models import Sum
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
|
||||||
from InvenTree.models import InvenTreeTree
|
from InvenTree.models import InvenTreeTree
|
||||||
@ -36,6 +37,43 @@ class Part(models.Model):
|
|||||||
verbose_name = "Part"
|
verbose_name = "Part"
|
||||||
verbose_name_plural = "Parts"
|
verbose_name_plural = "Parts"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def stock_list(self):
|
||||||
|
""" Return a list of all stock objects associated with this part
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self.stockitem_set.all()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def quantity(self):
|
||||||
|
""" Return the total stock quantity for this part.
|
||||||
|
Part may be stored in multiple locations
|
||||||
|
"""
|
||||||
|
|
||||||
|
stocks = self.stock_list
|
||||||
|
if len(stocks) == 0:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
result = stocks.aggregate(total=Sum('quantity'))
|
||||||
|
return result['total']
|
||||||
|
|
||||||
|
@property
|
||||||
|
def projects(self):
|
||||||
|
""" Return a list of unique projects that this part is associated with
|
||||||
|
"""
|
||||||
|
|
||||||
|
project_ids = set()
|
||||||
|
project_parts = self.projectpart_set.all()
|
||||||
|
|
||||||
|
projects = []
|
||||||
|
|
||||||
|
for pp in project_parts:
|
||||||
|
if pp.project.id not in project_ids:
|
||||||
|
project_ids.add(pp.project.id)
|
||||||
|
projects.append(pp.project)
|
||||||
|
|
||||||
|
return projects
|
||||||
|
|
||||||
class PartRevision(models.Model):
|
class PartRevision(models.Model):
|
||||||
""" A PartRevision represents a change-notification to a Part
|
""" A PartRevision represents a change-notification to a Part
|
||||||
A Part may go through several revisions in its lifetime,
|
A Part may go through several revisions in its lifetime,
|
||||||
|
@ -27,6 +27,11 @@ class Project(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def projectParts(self):
|
||||||
|
""" Return a list of all project parts associated with this project
|
||||||
|
"""
|
||||||
|
return self.projectpart_set.all()
|
||||||
|
|
||||||
class ProjectPart(models.Model):
|
class ProjectPart(models.Model):
|
||||||
""" A project part associates a single part with a project
|
""" A project part associates a single part with a project
|
||||||
@ -40,9 +45,10 @@ class ProjectPart(models.Model):
|
|||||||
|
|
||||||
part = models.ForeignKey(Part, on_delete=models.CASCADE)
|
part = models.ForeignKey(Part, on_delete=models.CASCADE)
|
||||||
project = models.ForeignKey(Project, on_delete=models.CASCADE)
|
project = models.ForeignKey(Project, on_delete=models.CASCADE)
|
||||||
quantity = models.IntegerField()
|
quantity = models.IntegerField(default=1)
|
||||||
overage = models.FloatField()
|
overage = models.FloatField(default=0)
|
||||||
overage_type = models.IntegerField(
|
overage_type = models.IntegerField(
|
||||||
|
default=1,
|
||||||
choices=[
|
choices=[
|
||||||
(OVERAGE_PERCENT, "Percent"),
|
(OVERAGE_PERCENT, "Percent"),
|
||||||
(OVERAGE_ABSOLUTE, "Absolute")
|
(OVERAGE_ABSOLUTE, "Absolute")
|
||||||
|
@ -9,7 +9,8 @@ class Warehouse(InvenTreeTree):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class StockItem(models.Model):
|
class StockItem(models.Model):
|
||||||
part = models.ForeignKey(Part, on_delete=models.CASCADE)
|
part = models.ForeignKey(Part,
|
||||||
|
on_delete=models.CASCADE)
|
||||||
location = models.ForeignKey(Warehouse, on_delete=models.CASCADE)
|
location = models.ForeignKey(Warehouse, on_delete=models.CASCADE)
|
||||||
quantity = models.IntegerField()
|
quantity = models.IntegerField()
|
||||||
updated = models.DateField(auto_now=True)
|
updated = models.DateField(auto_now=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user