Add API interface for SupplierPriceBreak

This commit is contained in:
Oliver Walters 2019-04-17 00:35:49 +10:00
parent a3b544e2a4
commit 150bc1e674
3 changed files with 38 additions and 3 deletions

View File

@ -10,10 +10,10 @@ from django.conf.urls import url, include
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from .models import Part, PartCategory, BomItem from .models import Part, PartCategory, BomItem
from .models import SupplierPart from .models import SupplierPart, SupplierPriceBreak
from .serializers import PartSerializer, BomItemSerializer from .serializers import PartSerializer, BomItemSerializer
from .serializers import SupplierPartSerializer from .serializers import SupplierPartSerializer, SupplierPriceBreakSerializer
from .serializers import CategorySerializer from .serializers import CategorySerializer
from InvenTree.views import TreeSerializer from InvenTree.views import TreeSerializer
@ -168,6 +168,24 @@ class SupplierPartList(generics.ListAPIView):
] ]
class SupplierPriceBreakList(generics.ListCreateAPIView):
queryset = SupplierPriceBreak.objects.all()
serializer_class = SupplierPriceBreakSerializer
permission_classes = [
permissions.IsAuthenticatedOrReadOnly,
]
filter_backends = [
DjangoFilterBackend,
]
filter_fields = [
'part',
]
cat_api_urls = [ cat_api_urls = [
url(r'^$', CategoryList.as_view(), name='api-part-category-list'), url(r'^$', CategoryList.as_view(), name='api-part-category-list'),
] ]
@ -177,6 +195,7 @@ part_api_urls = [
url(r'^category/', include(cat_api_urls)), url(r'^category/', include(cat_api_urls)),
url(r'^price-break/?', SupplierPriceBreakList.as_view(), name='api-part-supplier-price'),
url(r'^supplier/?', SupplierPartList.as_view(), name='api-part-supplier-list'), url(r'^supplier/?', SupplierPartList.as_view(), name='api-part-supplier-list'),
url(r'^bom/?', BomList.as_view(), name='api-bom-list'), url(r'^bom/?', BomList.as_view(), name='api-bom-list'),

View File

@ -508,6 +508,10 @@ class SupplierPart(models.Model):
return ' | '.join(items) return ' | '.join(items)
@property
def has_price_breaks(self):
return self.price_breaks.count() > 0
def get_price(self, quantity, moq=True, multiples=True): def get_price(self, quantity, moq=True, multiples=True):
""" Calculate the supplier price based on quantity price breaks. """ Calculate the supplier price based on quantity price breaks.
- If no price breaks available, use the single_price field - If no price breaks available, use the single_price field

View File

@ -1,7 +1,7 @@
from rest_framework import serializers from rest_framework import serializers
from .models import Part, PartCategory, BomItem from .models import Part, PartCategory, BomItem
from .models import SupplierPart from .models import SupplierPart, SupplierPriceBreak
from company.serializers import CompanyBriefSerializer from company.serializers import CompanyBriefSerializer
@ -104,3 +104,15 @@ class SupplierPartSerializer(serializers.ModelSerializer):
'manufacturer', 'manufacturer',
'MPN', 'MPN',
] ]
class SupplierPriceBreakSerializer(serializers.ModelSerializer):
class Meta:
model = SupplierPriceBreak
fields = [
'pk',
'part',
'quantity',
'cost'
]