From 50adb2ac61dd7280620c2a62c7b34c13abd29935 Mon Sep 17 00:00:00 2001 From: eeintech Date: Mon, 29 Mar 2021 15:39:25 -0400 Subject: [PATCH] SourceItem only for SupplierPart, added logic to templates --- InvenTree/company/forms.py | 2 + .../migrations/0032_manufacturerpart.py | 16 ++- .../migrations/0033_auto_20210329_1700.py | 33 ----- InvenTree/company/models.py | 14 +- ...art.html => detail_manufacturer_part.html} | 63 ++------- .../company/detail_supplier_part.html | 128 ++++++++++++++++++ .../company/manufacturer_part_base.html | 4 +- .../company/manufacturer_part_detail.html | 2 +- .../company/templates/company/navbar.html | 19 +-- .../templates/company/supplier_part_base.html | 6 +- .../company/supplier_part_detail.html | 2 +- InvenTree/company/urls.py | 3 +- .../part/templates/part/manufacturer.html | 9 ++ InvenTree/users/models.py | 1 + 14 files changed, 187 insertions(+), 115 deletions(-) delete mode 100644 InvenTree/company/migrations/0033_auto_20210329_1700.py rename InvenTree/company/templates/company/{detail_part.html => detail_manufacturer_part.html} (67%) create mode 100644 InvenTree/company/templates/company/detail_supplier_part.html diff --git a/InvenTree/company/forms.py b/InvenTree/company/forms.py index b9e8b607cf..b7d4eb0360 100644 --- a/InvenTree/company/forms.py +++ b/InvenTree/company/forms.py @@ -128,6 +128,8 @@ class EditSupplierPartForm(HelperForm): 'part', 'supplier', 'SKU', + 'manufacturer', + 'MPN', 'description', 'link', 'note', diff --git a/InvenTree/company/migrations/0032_manufacturerpart.py b/InvenTree/company/migrations/0032_manufacturerpart.py index 5547aec36d..0e8ea6d7d4 100644 --- a/InvenTree/company/migrations/0032_manufacturerpart.py +++ b/InvenTree/company/migrations/0032_manufacturerpart.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.7 on 2021-03-24 14:18 +# Generated by Django 3.0.7 on 2021-03-29 18:53 import InvenTree.fields from django.db import migrations, models @@ -9,10 +9,24 @@ class Migration(migrations.Migration): dependencies = [ ('part', '0063_bomitem_inherited'), + ('contenttypes', '0002_remove_content_type_name'), ('company', '0031_auto_20210103_2215'), ] operations = [ + migrations.CreateModel( + name='SourceItem', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('part_id', models.PositiveIntegerField()), + ('part_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')), + ], + ), + migrations.AddField( + model_name='supplierpart', + name='source_item', + field=models.ForeignKey(blank=True, help_text='Select part', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='supplier_parts', to='company.SourceItem', verbose_name='Part'), + ), migrations.CreateModel( name='ManufacturerPart', fields=[ diff --git a/InvenTree/company/migrations/0033_auto_20210329_1700.py b/InvenTree/company/migrations/0033_auto_20210329_1700.py deleted file mode 100644 index 341ac95999..0000000000 --- a/InvenTree/company/migrations/0033_auto_20210329_1700.py +++ /dev/null @@ -1,33 +0,0 @@ -# Generated by Django 3.0.7 on 2021-03-29 17:00 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('contenttypes', '0002_remove_content_type_name'), - ('company', '0032_manufacturerpart'), - ] - - operations = [ - migrations.CreateModel( - name='SourceItem', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('part_id', models.PositiveIntegerField()), - ('part_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')), - ], - ), - migrations.AddField( - model_name='manufacturerpart', - name='source_item', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='manufacturer_parts', to='company.SourceItem', verbose_name='Sourcing Item'), - ), - migrations.AddField( - model_name='supplierpart', - name='source_item', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='supplier_parts', to='company.SourceItem', verbose_name='Sourcing Item'), - ), - ] diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index bd628c64d4..447b55b6b2 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -302,7 +302,6 @@ class ManufacturerPart(models.Model): Attributes: part: Link to the master Part - source_item: The sourcing item linked to this ManufacturerPart instance manufacturer: Company that manufactures the ManufacturerPart MPN: Manufacture part number link: Link to external website for this manufacturer part @@ -311,7 +310,7 @@ class ManufacturerPart(models.Model): class Meta: unique_together = ('part', 'manufacturer', 'MPN') - + part = models.ForeignKey('part.Part', on_delete=models.CASCADE, related_name='manufacturer_parts', verbose_name=_('Base Part'), @@ -321,12 +320,6 @@ class ManufacturerPart(models.Model): help_text=_('Select part'), ) - source_item = models.ForeignKey(SourceItem, on_delete=models.CASCADE, - blank=True, null=True, - related_name='manufacturer_parts', - verbose_name=_('Sourcing Item'), - ) - manufacturer = models.ForeignKey( Company, on_delete=models.CASCADE, @@ -364,7 +357,7 @@ class SupplierPart(models.Model): A Part may be available from multiple suppliers Attributes: - part: Link to the master Part + part: Link to the master Part (Obsolete) source_item: The sourcing item linked to this SupplierPart instance supplier: Company that supplies this SupplierPart object SKU: Stock keeping unit (supplier part number) @@ -398,7 +391,8 @@ class SupplierPart(models.Model): source_item = models.ForeignKey(SourceItem, on_delete=models.CASCADE, blank=True, null=True, related_name='supplier_parts', - verbose_name=_('Sourcing Item'), + verbose_name=_('Part'), + help_text=_('Select part'), ) supplier = models.ForeignKey(Company, on_delete=models.CASCADE, diff --git a/InvenTree/company/templates/company/detail_part.html b/InvenTree/company/templates/company/detail_manufacturer_part.html similarity index 67% rename from InvenTree/company/templates/company/detail_part.html rename to InvenTree/company/templates/company/detail_manufacturer_part.html index 9829213103..8499512b4c 100644 --- a/InvenTree/company/templates/company/detail_part.html +++ b/InvenTree/company/templates/company/detail_manufacturer_part.html @@ -4,31 +4,26 @@ {% load inventree_extras %} {% block menubar %} -{% include 'company/navbar.html' with tab='parts' %} +{% include 'company/navbar.html' with tab='manufacturer_parts' %} {% endblock %} {% block heading %} -{% trans "Supplier Parts" %} +{% trans "Manufacturer Parts" %} {% endblock %} {% block details %} {% setting_object 'PART_ENABLE_MANUFACTURER_PARTS' as manufacturer_parts %} +{% if manufacturer_parts.value == "True" %} {% if roles.purchase_order.change %}
{% if roles.purchase_order.add %} - {% if manufacturer_parts.value == "True" and company.is_manufacturer %} - {% else %} - - {% endif %} {% endif %}
{% endif %} -
+{% else %} +
+ {% trans "Manufactured parts are disabled. Admin users can enable them in the global settings." %} +
+{% endif %} + {% endblock %} {% block js_ready %} {{ block.super }} @@ -86,32 +86,6 @@ }); }); - $("#supplier-part-create").click(function () { - launchModalForm( - "{% url 'supplier-part-create' %}", - { - data: { - supplier: {{ company.id }}, - }, - reload: true, - secondary: [ - { - field: 'part', - label: '{% trans "New Part" %}', - title: '{% trans "Create new Part" %}', - url: "{% url 'part-create' %}" - }, - { - field: 'supplier', - label: "{% trans 'New Supplier' %}", - title: "{% trans 'Create new Supplier' %}", - url: "{% url 'supplier-create' %}", - }, - ] - }); - }); - - {% if manufacturer_parts.value == "True" and company.is_manufacturer %} loadManufacturerPartTable( "#part-table", "{% url 'api-manufacturer-part-list' %}", @@ -123,20 +97,6 @@ }, } ); - {% else %} - loadSupplierPartTable( - "#part-table", - "{% url 'api-supplier-part-list' %}", - { - params: { - part_detail: true, - supplier_detail: true, - manufacturer_detail: true, - company: {{ company.id }}, - }, - } - ); - {% endif %} $("#multi-part-delete").click(function() { var selections = $("#part-table").bootstrapTable("getSelections"); @@ -147,12 +107,7 @@ parts.push(item.pk); }); - {% if company.is_manufacturer %} var url = "{% url 'manufacturer-part-delete' %}" - {% endif %} - {% if company.is_supplier %} - var url = "{% url 'supplier-part-delete' %}" - {% endif %} launchModalForm(url, { data: { diff --git a/InvenTree/company/templates/company/detail_supplier_part.html b/InvenTree/company/templates/company/detail_supplier_part.html new file mode 100644 index 0000000000..0273d0a652 --- /dev/null +++ b/InvenTree/company/templates/company/detail_supplier_part.html @@ -0,0 +1,128 @@ +{% extends "company/company_base.html" %} +{% load static %} +{% load i18n %} +{% load inventree_extras %} + +{% block menubar %} +{% include 'company/navbar.html' with tab='supplier_parts' %} +{% endblock %} + +{% block heading %} +{% trans "Supplier Parts" %} +{% endblock %} + + +{% block details %} +{% if roles.purchase_order.change %} +
+
+
+ {% if roles.purchase_order.add %} + + {% endif %} +
+ +
+
+
+ +
+
+
+{% endif %} + + +
+ +{% endblock %} +{% block js_ready %} +{{ block.super }} + + $("#supplier-part-create").click(function () { + launchModalForm( + "{% url 'supplier-part-create' %}", + { + data: { + supplier: {{ company.id }}, + }, + reload: true, + secondary: [ + { + field: 'part', + label: '{% trans "New Part" %}', + title: '{% trans "Create new Part" %}', + url: "{% url 'part-create' %}" + }, + { + field: 'supplier', + label: "{% trans 'New Supplier' %}", + title: "{% trans 'Create new Supplier' %}", + url: "{% url 'supplier-create' %}", + }, + ] + }); + }); + + loadSupplierPartTable( + "#part-table", + "{% url 'api-supplier-part-list' %}", + { + params: { + part_detail: true, + supplier_detail: true, + manufacturer_detail: true, + company: {{ company.id }}, + }, + } + ); + + $("#multi-part-delete").click(function() { + var selections = $("#part-table").bootstrapTable("getSelections"); + + var parts = []; + + selections.forEach(function(item) { + parts.push(item.pk); + }); + + var url = "{% url 'supplier-part-delete' %}" + + launchModalForm(url, { + data: { + parts: parts, + }, + reload: true, + }); + }); + + $("#multi-part-order").click(function() { + var selections = $("#part-table").bootstrapTable("getSelections"); + + var parts = []; + + selections.forEach(function(item) { + parts.push(item.part); + }); + + launchModalForm("/order/purchase-order/order-parts/", { + data: { + parts: parts, + }, + }); + }); + +{% endblock %} \ No newline at end of file diff --git a/InvenTree/company/templates/company/manufacturer_part_base.html b/InvenTree/company/templates/company/manufacturer_part_base.html index 5c6e6c6b1d..441f1f845b 100644 --- a/InvenTree/company/templates/company/manufacturer_part_base.html +++ b/InvenTree/company/templates/company/manufacturer_part_base.html @@ -83,7 +83,7 @@ src="{% static 'img/blank_image.png' %}" {% trans "Manufacturer" %} - {{ part.manufacturer.name }} + {{ part.manufacturer.name }} {% trans "MPN" %} @@ -125,7 +125,7 @@ $('#delete-part').click(function() { launchModalForm( "{% url 'manufacturer-part-delete' %}?part={{ part.id }}", { - redirect: "{% url 'company-detail-parts' part.manufacturer.id %}" + redirect: "{% url 'company-detail-manufacturer-parts' part.manufacturer.id %}" } ); }); diff --git a/InvenTree/company/templates/company/manufacturer_part_detail.html b/InvenTree/company/templates/company/manufacturer_part_detail.html index f351f955dc..fcb4abbfef 100644 --- a/InvenTree/company/templates/company/manufacturer_part_detail.html +++ b/InvenTree/company/templates/company/manufacturer_part_detail.html @@ -22,7 +22,7 @@ {% endif %} - {% trans "Manufacturer" %}{{ part.manufacturer.name }} + {% trans "Manufacturer" %}{{ part.manufacturer.name }} {% trans "MPN" %}{{ part.MPN }} {% if part.link %} {% trans "External Link" %}{{ part.link }} diff --git a/InvenTree/company/templates/company/navbar.html b/InvenTree/company/templates/company/navbar.html index ed6ff5799b..0e858d02bc 100644 --- a/InvenTree/company/templates/company/navbar.html +++ b/InvenTree/company/templates/company/navbar.html @@ -19,17 +19,18 @@ {% if manufacturer_parts.value == "True" and company.is_manufacturer %} -
  • - - - {% trans "Parts" %} +
  • + + + {% trans "Manufactured Parts" %}
  • - {% else %} -
  • - - - {% trans "Parts" %} + {% endif %} + {% if company.is_supplier or company.is_manufacturer %} +
  • + + + {% trans "Supplied Parts" %}
  • {% endif %} diff --git a/InvenTree/company/templates/company/supplier_part_base.html b/InvenTree/company/templates/company/supplier_part_base.html index 00de1a9fb3..f06c26e20e 100644 --- a/InvenTree/company/templates/company/supplier_part_base.html +++ b/InvenTree/company/templates/company/supplier_part_base.html @@ -81,7 +81,7 @@ src="{% static 'img/blank_image.png' %}" {% trans "Supplier" %} - {{ part.supplier.name }} + {{ part.supplier.name }} {% trans "SKU" %} @@ -91,7 +91,7 @@ src="{% static 'img/blank_image.png' %}" {% trans "Manufacturer" %} - {{ part.manufacturer.name }} + {{ part.manufacturer.name }} {% endif %} {% if part.MPN %} @@ -150,7 +150,7 @@ $('#delete-part').click(function() { launchModalForm( "{% url 'supplier-part-delete' %}?part={{ part.id }}", { - redirect: "{% url 'company-detail-parts' part.supplier.id %}" + redirect: "{% url 'company-detail-supplier-parts' part.supplier.id %}" } ); }); diff --git a/InvenTree/company/templates/company/supplier_part_detail.html b/InvenTree/company/templates/company/supplier_part_detail.html index 7a8ac0dcd3..2938909757 100644 --- a/InvenTree/company/templates/company/supplier_part_detail.html +++ b/InvenTree/company/templates/company/supplier_part_detail.html @@ -22,7 +22,7 @@ {% endif %} - {% trans "Supplier" %}{{ part.supplier.name }} + {% trans "Supplier" %}{{ part.supplier.name }} {% trans "SKU" %}{{ part.SKU }} {% if part.link %} {% trans "External Link" %}{{ part.link }} diff --git a/InvenTree/company/urls.py b/InvenTree/company/urls.py index bb0fd1606a..21d2e37d5a 100644 --- a/InvenTree/company/urls.py +++ b/InvenTree/company/urls.py @@ -13,7 +13,8 @@ company_detail_urls = [ # url(r'orders/?', views.CompanyDetail.as_view(template_name='company/orders.html'), name='company-detail-orders'), - url(r'^parts/', views.CompanyDetail.as_view(template_name='company/detail_part.html'), name='company-detail-parts'), + url(r'^supplier-parts/', views.CompanyDetail.as_view(template_name='company/detail_supplier_part.html'), name='company-detail-supplier-parts'), + url(r'^manufacturer-parts/', views.CompanyDetail.as_view(template_name='company/detail_manufacturer_part.html'), name='company-detail-manufacturer-parts'), url(r'^stock/', views.CompanyDetail.as_view(template_name='company/detail_stock.html'), name='company-detail-stock'), url(r'^purchase-orders/', views.CompanyDetail.as_view(template_name='company/purchase_orders.html'), name='company-detail-purchase-orders'), url(r'^assigned-stock/', views.CompanyDetail.as_view(template_name='company/assigned_stock.html'), name='company-detail-assigned-stock'), diff --git a/InvenTree/part/templates/part/manufacturer.html b/InvenTree/part/templates/part/manufacturer.html index 09793ffc7f..3e17ed9ee4 100644 --- a/InvenTree/part/templates/part/manufacturer.html +++ b/InvenTree/part/templates/part/manufacturer.html @@ -1,6 +1,7 @@ {% extends "part/part_base.html" %} {% load static %} {% load i18n %} +{% load inventree_extras %} {% block menubar %} {% include 'part/navbar.html' with tab='manufacturers' %} @@ -11,6 +12,9 @@ {% endblock %} {% block details %} +{% setting_object 'PART_ENABLE_MANUFACTURER_PARTS' as manufacturer_parts %} + +{% if manufacturer_parts.value == "True" %}