mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 13:28:49 +00:00
- Each part can be made of other parts - Disable tracking and project apps for now - Project will change (eventually) to work order - Part parameters have been disabled (for now)
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
from __future__ import unicode_literals
|
|
from django.utils.translation import ugettext as _
|
|
from django.db import models
|
|
from django.db.models import Sum
|
|
from django.core.validators import MinValueValidator
|
|
|
|
from part.models import Part
|
|
|
|
class BomItem(models.Model):
|
|
""" A BomItem links a part to its component items.
|
|
A part can have a BOM (bill of materials) which defines
|
|
which parts are required (and in what quatity) to make it
|
|
"""
|
|
|
|
# A link to the parent part
|
|
# Each part will get a reverse lookup field 'bom_items'
|
|
part = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='bom_items')
|
|
|
|
# A link to the child item (sub-part)
|
|
# Each part will get a reverse lookup field 'used_in'
|
|
sub_part = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='used_in')
|
|
|
|
# Quantity required
|
|
quantity = models.PositiveIntegerField(default=1, validators=[MinValueValidator(0)])
|
|
|
|
|
|
class Meta:
|
|
verbose_name = "BOM Item"
|
|
|
|
# Prevent duplication of parent/child rows
|
|
unique_together = ('part', 'sub_part')
|
|
|
|
def __str__(self):
|
|
return "{par} -> {child} ({n})".format(
|
|
par=self.part.name,
|
|
child=self.sub_part.name,
|
|
n=self.quantity)
|