mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Move BomItem into the Part app
- Does not make sense to keep these separate - Removed bom app entirely
This commit is contained in:
parent
1da6df0c5e
commit
e30a089c76
@ -46,11 +46,9 @@ INSTALLED_APPS = [
|
||||
|
||||
# InvenTree apps
|
||||
'part.apps.PartConfig',
|
||||
'bom.apps.BomConfig',
|
||||
'supplier.apps.SupplierConfig',
|
||||
'stock.apps.StockConfig',
|
||||
'track.apps.TrackConfig',
|
||||
#'project.apps.ProjectConfig',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
@ -4,8 +4,8 @@ from django.contrib import admin
|
||||
from rest_framework.documentation import include_docs_urls
|
||||
|
||||
from part.urls import part_api_urls, part_cat_api_urls
|
||||
from part.urls import bom_api_urls
|
||||
from part.urls import part_urls
|
||||
from bom.urls import bom_urls
|
||||
from stock.urls import stock_urls, stock_loc_urls
|
||||
from supplier.urls import cust_urls, manu_urls, supplier_part_urls, price_break_urls, supplier_urls
|
||||
|
||||
@ -34,7 +34,7 @@ apipatterns = [
|
||||
#url(r'^part-param-template/', include(part_param_template_urls)),
|
||||
|
||||
# Part BOM URLs
|
||||
url(r'^bom/', include(bom_urls)),
|
||||
url(r'^bom/', include(bom_api_urls)),
|
||||
|
||||
# Supplier URLs
|
||||
url(r'^supplier/', include(supplier_urls)),
|
||||
|
@ -1,8 +0,0 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import BomItem
|
||||
|
||||
class BomItemAdmin(admin.ModelAdmin):
|
||||
list_display=('part', 'sub_part', 'quantity')
|
||||
|
||||
admin.site.register(BomItem, BomItemAdmin)
|
@ -1,6 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
class BomConfig(AppConfig):
|
||||
name = 'bom'
|
@ -1,37 +0,0 @@
|
||||
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)
|
@ -1,13 +0,0 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from .models import BomItem
|
||||
|
||||
|
||||
class BomItemSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = BomItem
|
||||
fields = ('url',
|
||||
'part',
|
||||
'sub_part',
|
||||
'quantity')
|
@ -1,6 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -1,12 +0,0 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
|
||||
bom_urls = [
|
||||
# Bom Item detail
|
||||
url(r'^(?P<pk>[0-9]+)/?$', views.BomItemDetail.as_view(), name='bomitem-detail'),
|
||||
|
||||
# List of top-level categories
|
||||
url(r'^\?*.*/?$', views.BomItemList.as_view()),
|
||||
url(r'^$', views.BomItemList.as_view())
|
||||
]
|
@ -1,35 +0,0 @@
|
||||
from django_filters.rest_framework import FilterSet, DjangoFilterBackend
|
||||
|
||||
from rest_framework import generics, permissions
|
||||
|
||||
from InvenTree.models import FilterChildren
|
||||
|
||||
from .models import BomItem
|
||||
|
||||
from .serializers import BomItemSerializer
|
||||
|
||||
|
||||
class BomItemDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
|
||||
queryset = BomItem.objects.all()
|
||||
serializer_class = BomItemSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
|
||||
|
||||
class BomItemFilter(FilterSet):
|
||||
|
||||
class Meta:
|
||||
model = BomItem
|
||||
fields = ['part', 'sub_part']
|
||||
|
||||
|
||||
class BomItemList(generics.ListCreateAPIView):
|
||||
|
||||
#def get_queryset(self):
|
||||
# params = self.request.
|
||||
|
||||
queryset = BomItem.objects.all()
|
||||
serializer_class = BomItemSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
filter_backends = (DjangoFilterBackend,)
|
||||
filter_class = BomItemFilter
|
@ -1,6 +1,7 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import PartCategory, Part
|
||||
from .models import BomItem
|
||||
|
||||
class PartAdmin(admin.ModelAdmin):
|
||||
|
||||
@ -11,6 +12,9 @@ class PartCategoryAdmin(admin.ModelAdmin):
|
||||
|
||||
list_display = ('name', 'pathstring', 'description')
|
||||
|
||||
class BomItemAdmin(admin.ModelAdmin):
|
||||
list_display=('part', 'sub_part', 'quantity')
|
||||
|
||||
"""
|
||||
class ParameterTemplateAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'units', 'format')
|
||||
@ -22,6 +26,7 @@ class ParameterAdmin(admin.ModelAdmin):
|
||||
|
||||
admin.site.register(Part, PartAdmin)
|
||||
admin.site.register(PartCategory, PartCategoryAdmin)
|
||||
admin.site.register(BomItem, BomItemAdmin)
|
||||
|
||||
#admin.site.register(PartParameter, ParameterAdmin)
|
||||
#admin.site.register(PartParameterTemplate, ParameterTemplateAdmin)
|
||||
|
@ -1,11 +1,12 @@
|
||||
from .serializers import PartSerializer
|
||||
from .serializers import PartCategorySerializer
|
||||
from .serializers import BomItemSerializer
|
||||
|
||||
from rest_framework import generics, permissions
|
||||
|
||||
from django_filters.rest_framework import FilterSet, DjangoFilterBackend
|
||||
|
||||
from .models import PartCategory, Part
|
||||
from .models import PartCategory, Part, BomItem
|
||||
|
||||
class PartDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
"""
|
||||
@ -172,3 +173,28 @@ class PartTemplateList(generics.ListCreateAPIView):
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
|
||||
"""
|
||||
|
||||
class BomItemDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
|
||||
queryset = BomItem.objects.all()
|
||||
serializer_class = BomItemSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
|
||||
|
||||
class BomItemFilter(FilterSet):
|
||||
|
||||
class Meta:
|
||||
model = BomItem
|
||||
fields = ['part', 'sub_part']
|
||||
|
||||
|
||||
class BomItemList(generics.ListCreateAPIView):
|
||||
|
||||
#def get_queryset(self):
|
||||
# params = self.request.
|
||||
|
||||
queryset = BomItem.objects.all()
|
||||
serializer_class = BomItemSerializer
|
||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||
filter_backends = (DjangoFilterBackend,)
|
||||
filter_class = BomItemFilter
|
||||
|
@ -118,3 +118,32 @@ class Part(models.Model):
|
||||
"""
|
||||
|
||||
|
||||
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)
|
||||
|
@ -1,6 +1,16 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from .models import Part, PartCategory
|
||||
from .models import BomItem
|
||||
|
||||
class BomItemSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = BomItem
|
||||
fields = ('url',
|
||||
'part',
|
||||
'sub_part',
|
||||
'quantity')
|
||||
|
||||
"""
|
||||
class PartParameterSerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
@ -29,6 +29,15 @@ part_api_urls = [
|
||||
url(r'^$', api.PartList.as_view()),
|
||||
]
|
||||
|
||||
bom_api_urls = [
|
||||
# Bom Item detail
|
||||
url(r'^(?P<pk>[0-9]+)/?$', api.BomItemDetail.as_view(), name='bomitem-detail'),
|
||||
|
||||
# List of top-level categories
|
||||
url(r'^\?*.*/?$', api.BomItemList.as_view()),
|
||||
url(r'^$', api.BomItemList.as_view())
|
||||
]
|
||||
|
||||
part_detail_urls = [
|
||||
url(r'^track/?', views.track, name='track'),
|
||||
url(r'^bom/?', views.bom, name='bom'),
|
||||
@ -47,6 +56,8 @@ part_urls = [
|
||||
url(r'^.*$', RedirectView.as_view(url='list', permanent=False), name='index'),
|
||||
]
|
||||
|
||||
|
||||
|
||||
"""
|
||||
part_param_urls = [
|
||||
# Detail of a single part parameter
|
||||
|
Loading…
Reference in New Issue
Block a user