Added global setting to enable manufacturer parts

Created SourceItem model
Updated templates
This commit is contained in:
eeintech 2021-03-29 13:22:15 -04:00
parent cbb887ae79
commit e6dfb7da52
8 changed files with 89 additions and 14 deletions

View File

@ -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)'),

View File

@ -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)

View File

@ -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'),
),
]

View File

@ -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
@ -304,6 +321,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,
on_delete=models.CASCADE,
@ -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},

View File

@ -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 %}
<div id='button-toolbar'>
<div class='button-toolbar container-fluid'>
<div class='btn-group role='group'>
{% if roles.purchase_order.add %}
{% if company.is_manufacturer %}
{% if manufacturer_parts.value == "True" and company.is_manufacturer %}
<button class="btn btn-success" id='manufacturer-part-create' title='{% trans "Create new manufacturer part" %}'>
<span class='fas fa-plus-circle'></span> {% trans "New Manufacturer Part" %}
</button>
{% endif %}
{% if company.is_supplier %}
{% else %}
<button class="btn btn-success" id='supplier-part-create' title='{% trans "Create new supplier part" %}'>
<span class='fas fa-plus-circle'></span> {% trans "New Supplier Part" %}
</button>
@ -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' %}",

View File

@ -2,6 +2,8 @@
{% load static %}
{% load inventree_extras %}
{% setting_object 'PART_ENABLE_MANUFACTURER_PARTS' as manufacturer_parts %}
<ul class='list-group'>
<li class='list-group-item'>
<a href='#' id='company-menu-toggle'>
@ -16,16 +18,14 @@
</a>
</li>
{% if company.is_manufacturer %}
{% if manufacturer_parts.value == "True" and company.is_manufacturer %}
<li class='list-group-item {% if tab == "parts" %}active{% endif %}' title='{% trans "Manufactured Parts" %}'>
<a href='{% url "company-detail-parts" company.id %}'>
<span class='fas fa-shapes'></span>
{% trans "Parts" %}
</a>
</li>
{% endif %}
{% if company.is_supplier %}
{% else %}
<li class='list-group-item {% if tab == "parts" %}active{% endif %}' title='{% trans "Supplied Parts" %}'>
<a href='{% url "company-detail-parts" company.id %}'>
<span class='fas fa-shapes'></span>

View File

@ -68,13 +68,16 @@
</a>
</li>
{% endif %}
{% setting_object 'PART_ENABLE_MANUFACTURER_PARTS' as manufacturer_parts %}
{% if part.purchaseable and roles.purchase_order.view %}
{% if manufacturer_parts.value == "True" %}
<li class='list-group-item {% if tab == "manufacturers" %}active{% endif %}' title='{% trans "Manufacturers" %}'>
<a href='{% url "part-manufacturers" part.id %}'>
<span class='menu-tab-icon fas fa-building'></span>
{% trans "Manufacturers" %}
</a>
</li>
{% endif %}
<li class='list-group-item {% if tab == "suppliers" %}active{% endif %}' title='{% trans "Suppliers" %}'>
<a href='{% url "part-suppliers" part.id %}'>
<span class='menu-tab-icon fas fa-warehouse'></span>

View File

@ -34,6 +34,8 @@
{% include "InvenTree/settings/setting.html" with key="PART_COPY_PARAMETERS" %}
{% include "InvenTree/settings/setting.html" with key="PART_COPY_TESTS" %}
{% include "InvenTree/settings/setting.html" with key="PART_CATEGORY_PARAMETERS" %}
<tr><td colspan='5'></td></tr>
{% include "InvenTree/settings/setting.html" with key="PART_ENABLE_MANUFACTURER_PARTS" %}
</tbody>
</table>