From 9c8817d73b10640e957ff26bca241430321a6160 Mon Sep 17 00:00:00 2001 From: eeintech Date: Tue, 30 Mar 2021 16:48:16 -0400 Subject: [PATCH] Fixed serializers and started update of templates --- InvenTree/company/api.py | 6 +- InvenTree/company/models.py | 2 +- InvenTree/company/serializers.py | 8 +- .../company/manufacturer_part_navbar.html | 7 ++ .../company/manufacturer_part_suppliers.html | 94 +++++++++++++++++++ InvenTree/company/urls.py | 4 +- 6 files changed, 112 insertions(+), 9 deletions(-) create mode 100644 InvenTree/company/templates/company/manufacturer_part_suppliers.html diff --git a/InvenTree/company/api.py b/InvenTree/company/api.py index a5f3361d38..eb0d7fc4e6 100644 --- a/InvenTree/company/api.py +++ b/InvenTree/company/api.py @@ -215,7 +215,7 @@ class SupplierPartList(generics.ListCreateAPIView): manufacturer = params.get('manufacturer', None) if manufacturer is not None: - queryset = queryset.filter(manufacturer=manufacturer) + queryset = queryset.filter(manufacturer_part__manufacturer=manufacturer) # Filter by supplier supplier = params.get('supplier', None) @@ -227,7 +227,7 @@ class SupplierPartList(generics.ListCreateAPIView): company = params.get('company', None) if company is not None: - queryset = queryset.filter(Q(manufacturer=company) | Q(supplier=company)) + queryset = queryset.filter(Q(manufacturer_part__manufacturer=company) | Q(supplier=company)) # Filter by parent part? part = params.get('part', None) @@ -298,7 +298,7 @@ class SupplierPartDetail(generics.RetrieveUpdateDestroyAPIView): - GET: Retrieve detail view - PATCH: Update object - - DELETE: Delete objec + - DELETE: Delete object """ queryset = SupplierPart.objects.all() diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index a2e5abdd9e..b904912cb2 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -400,7 +400,7 @@ class SupplierPart(models.Model): manufacturer_part = models.ForeignKey(ManufacturerPart, on_delete=models.CASCADE, blank=True, null=True, - related_name='manufacturer_parts', + related_name='supplier_parts', verbose_name=_('Manufacturer Part'), help_text=_('Select manufacturer part'), ) diff --git a/InvenTree/company/serializers.py b/InvenTree/company/serializers.py index 80734d2225..164f36a33d 100644 --- a/InvenTree/company/serializers.py +++ b/InvenTree/company/serializers.py @@ -82,7 +82,7 @@ class CompanySerializer(InvenTreeModelSerializer): class ManufacturerPartSerializer(InvenTreeModelSerializer): - """ Serializer for SupplierPart object """ + """ Serializer for ManufacturerPart object """ part_detail = PartBriefSerializer(source='part', many=False, read_only=True) @@ -131,7 +131,7 @@ class SupplierPartSerializer(InvenTreeModelSerializer): supplier_detail = CompanyBriefSerializer(source='supplier', many=False, read_only=True) - manufacturer_detail = ManufacturerPartSerializer(source='manufacturer_part', many=False, read_only=True) + manufacturer_detail = CompanyBriefSerializer(source='manufacturer_part.manufacturer', many=False, read_only=True) pretty_name = serializers.CharField(read_only=True) @@ -158,9 +158,9 @@ class SupplierPartSerializer(InvenTreeModelSerializer): supplier = serializers.PrimaryKeyRelatedField(queryset=Company.objects.filter(is_supplier=True)) - manufacturer = ManufacturerPartSerializer(many=False, read_only=True) + manufacturer = serializers.PrimaryKeyRelatedField(source='manufacturer_part.manufacturer', queryset=Company.objects.filter(is_manufacturer=True)) - MPN = ManufacturerPartSerializer(many=False, read_only=True) + MPN = serializers.StringRelatedField(source='manufacturer_part.MPN', read_only=True) class Meta: model = SupplierPart diff --git a/InvenTree/company/templates/company/manufacturer_part_navbar.html b/InvenTree/company/templates/company/manufacturer_part_navbar.html index 31430e7e6e..07489d65ea 100644 --- a/InvenTree/company/templates/company/manufacturer_part_navbar.html +++ b/InvenTree/company/templates/company/manufacturer_part_navbar.html @@ -8,6 +8,13 @@ +
  • + + + {% trans "Suppliers" %} + +
  • + {% comment "for later" %}
  • diff --git a/InvenTree/company/templates/company/manufacturer_part_suppliers.html b/InvenTree/company/templates/company/manufacturer_part_suppliers.html new file mode 100644 index 0000000000..60f01f7bf2 --- /dev/null +++ b/InvenTree/company/templates/company/manufacturer_part_suppliers.html @@ -0,0 +1,94 @@ +{% extends "company/manufacturer_part_base.html" %} +{% load static %} +{% load i18n %} + +{% block menubar %} +{% include "company/manufacturer_part_navbar.html" with tab='suppliers' %} +{% endblock %} + +{% block heading %} +{% trans "Supplier Parts" %} +{% endblock %} + +{% block details %} + + + +
    + +{% endblock %} + +{% block js_ready %} +{{ block.super }} + +$('#supplier-create').click(function () { + launchModalForm( + "{% url 'supplier-part-create' %}", + { + reload: true, + data: { + part: {{ part.id }} + }, + secondary: [ + { + field: 'supplier', + label: '{% trans "New Supplier" %}', + title: '{% trans "Create new supplier" %}', + url: "{% url 'supplier-create' %}" + }, + { + field: 'manufacturer', + label: '{% trans "New Manufacturer" %}', + title: '{% trans "Create new manufacturer" %}', + url: "{% url 'manufacturer-create' %}", + } + ] + }); +}); + +$("#supplier-part-delete").click(function() { + + var selections = $("#supplier-table").bootstrapTable("getSelections"); + + var parts = []; + + selections.forEach(function(item) { + parts.push(item.pk); + }); + + launchModalForm("{% url 'supplier-part-delete' %}", { + data: { + parts: parts, + }, + reload: true, + }); +}); + +loadSupplierPartTable( + "#supplier-table", + "{% url 'api-supplier-part-list' %}", + { + params: { + part: {{ part.part.id }}, + part_detail: true, + supplier_detail: true, + manufacturer_detail: true, + }, + } +); + +linkButtonsToSelection($("#supplier-table"), ['#supplier-part-options']) + +{% endblock %} \ No newline at end of file diff --git a/InvenTree/company/urls.py b/InvenTree/company/urls.py index 21d2e37d5a..939515eabc 100644 --- a/InvenTree/company/urls.py +++ b/InvenTree/company/urls.py @@ -55,8 +55,10 @@ price_break_urls = [ manufacturer_part_detail_urls = [ url(r'^edit/?', views.ManufacturerPartEdit.as_view(), name='manufacturer-part-edit'), + + url(r'^suppliers/', views.ManufacturerPartDetail.as_view(template_name='company/manufacturer_part_suppliers.html'), name='manufacturer-part-suppliers'), - url('^.*$', views.ManufacturerPartDetail.as_view(template_name='company/manufacturer_part_detail.html'), name='manufacturer-part-detail'), + url('^.*$', views.ManufacturerPartDetail.as_view(template_name='company/manufacturer_part_suppliers.html'), name='manufacturer-part-detail'), ] manufacturer_part_urls = [