From e6dfb7da524073753506632e6b0b1ee14c21068b Mon Sep 17 00:00:00 2001 From: eeintech Date: Mon, 29 Mar 2021 13:22:15 -0400 Subject: [PATCH] Added global setting to enable manufacturer parts Created SourceItem model Updated templates --- InvenTree/common/models.py | 7 ++++ InvenTree/company/api.py | 2 +- .../migrations/0033_auto_20210329_1700.py | 33 +++++++++++++++++++ InvenTree/company/models.py | 33 +++++++++++++++++-- .../templates/company/detail_part.html | 15 +++++---- .../company/templates/company/navbar.html | 8 ++--- InvenTree/part/templates/part/navbar.html | 3 ++ .../templates/InvenTree/settings/part.html | 2 ++ 8 files changed, 89 insertions(+), 14 deletions(-) create mode 100644 InvenTree/company/migrations/0033_auto_20210329_1700.py diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index df8e3b2d37..a785e944bc 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -202,6 +202,13 @@ class InvenTreeSetting(models.Model): 'validator': bool, }, + 'PART_ENABLE_MANUFACTURER_PARTS': { + 'name': _('Enable Manufacturer Parts'), + 'description': _('Enable the use of manufacturer parts for purchasing'), + 'default': False, + 'validator': bool, + }, + 'REPORT_DEBUG_MODE': { 'name': _('Debug Mode'), 'description': _('Generate reports in debug mode (HTML output)'), diff --git a/InvenTree/company/api.py b/InvenTree/company/api.py index b0962afbc4..e0ac1b804a 100644 --- a/InvenTree/company/api.py +++ b/InvenTree/company/api.py @@ -130,7 +130,7 @@ class ManufacturerPartList(generics.ListCreateAPIView): params = self.request.query_params # Filter by manufacturer - manufacturer = params.get('manufacturer', None) + manufacturer = params.get('company', None) if manufacturer is not None: queryset = queryset.filter(manufacturer=manufacturer) diff --git a/InvenTree/company/migrations/0033_auto_20210329_1700.py b/InvenTree/company/migrations/0033_auto_20210329_1700.py new file mode 100644 index 0000000000..341ac95999 --- /dev/null +++ b/InvenTree/company/migrations/0033_auto_20210329_1700.py @@ -0,0 +1,33 @@ +# 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 05421c54bc..bd628c64d4 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -13,6 +13,8 @@ from django.utils.translation import gettext_lazy as _ from django.core.validators import MinValueValidator from django.db import models from django.db.models import Sum, Q, UniqueConstraint +from django.contrib.contenttypes.fields import GenericForeignKey +from django.contrib.contenttypes.models import ContentType from django.apps import apps from django.urls import reverse @@ -278,6 +280,20 @@ class Contact(models.Model): on_delete=models.CASCADE) +class SourceItem(models.Model): + """ This model allows flexibility for sourcing of InvenTree parts. + Each SourceItem instance represents a single ManufacturerPart or + SupplierPart instance. + SourceItem can be linked to either Part or ManufacturerPart instances. + """ + + part_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) + + part_id = models.PositiveIntegerField() + + part = GenericForeignKey('part_type', 'part_id') + + class ManufacturerPart(models.Model): """ Represents a unique part as provided by a Manufacturer Each ManufacturerPart is identified by a MPN (Manufacturer Part Number) @@ -286,6 +302,7 @@ 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 @@ -303,6 +320,12 @@ 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, @@ -341,8 +364,8 @@ class SupplierPart(models.Model): A Part may be available from multiple suppliers Attributes: - part_type: Part or ManufacturerPart - part_id: Part or ManufacturerPart ID + part: Link to the master Part + source_item: The sourcing item linked to this SupplierPart instance supplier: Company that supplies this SupplierPart object SKU: Stock keeping unit (supplier part number) link: Link to external website for this supplier part @@ -372,6 +395,12 @@ class SupplierPart(models.Model): help_text=_('Select part'), ) + source_item = models.ForeignKey(SourceItem, on_delete=models.CASCADE, + blank=True, null=True, + related_name='supplier_parts', + verbose_name=_('Sourcing Item'), + ) + supplier = models.ForeignKey(Company, on_delete=models.CASCADE, related_name='supplied_parts', limit_choices_to={'is_supplier': True}, diff --git a/InvenTree/company/templates/company/detail_part.html b/InvenTree/company/templates/company/detail_part.html index 65362521cd..9829213103 100644 --- a/InvenTree/company/templates/company/detail_part.html +++ b/InvenTree/company/templates/company/detail_part.html @@ -1,6 +1,7 @@ {% extends "company/company_base.html" %} {% load static %} {% load i18n %} +{% load inventree_extras %} {% block menubar %} {% include 'company/navbar.html' with tab='parts' %} @@ -12,17 +13,18 @@ {% block details %} +{% setting_object 'PART_ENABLE_MANUFACTURER_PARTS' as manufacturer_parts %} + {% if roles.purchase_order.change %}
{% if roles.purchase_order.add %} - {% if company.is_manufacturer %} + {% if manufacturer_parts.value == "True" and company.is_manufacturer %} - {% endif %} - {% if company.is_supplier %} + {% else %} @@ -57,6 +59,7 @@ {% endblock %} {% block js_ready %} {{ block.super }} +{% setting_object 'PART_ENABLE_MANUFACTURER_PARTS' as manufacturer_parts %} $("#manufacturer-part-create").click(function () { launchModalForm( @@ -108,7 +111,7 @@ }); }); - {% if company.is_manufacturer %} + {% if manufacturer_parts.value == "True" and company.is_manufacturer %} loadManufacturerPartTable( "#part-table", "{% url 'api-manufacturer-part-list' %}", @@ -120,9 +123,7 @@ }, } ); - {% endif %} - - {% if company.is_supplier %} + {% else %} loadSupplierPartTable( "#part-table", "{% url 'api-supplier-part-list' %}", diff --git a/InvenTree/company/templates/company/navbar.html b/InvenTree/company/templates/company/navbar.html index 0527eb925e..ed6ff5799b 100644 --- a/InvenTree/company/templates/company/navbar.html +++ b/InvenTree/company/templates/company/navbar.html @@ -2,6 +2,8 @@ {% load static %} {% load inventree_extras %} +{% setting_object 'PART_ENABLE_MANUFACTURER_PARTS' as manufacturer_parts %} +