mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-20 22:06:28 +00:00
Merge branch 'master' of https://github.com/inventree/InvenTree into price-history
This commit is contained in:
@ -8,6 +8,7 @@ from __future__ import unicode_literals
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from django.http import JsonResponse
|
||||
from django.db.models import Q, F, Count, Prefetch, Sum
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from rest_framework import status
|
||||
from rest_framework.response import Response
|
||||
@ -36,7 +37,7 @@ from InvenTree.status_codes import BuildStatus
|
||||
|
||||
class PartCategoryTree(TreeSerializer):
|
||||
|
||||
title = "Parts"
|
||||
title = _("Parts")
|
||||
model = PartCategory
|
||||
|
||||
queryset = PartCategory.objects.all()
|
||||
|
@ -16,7 +16,7 @@ from InvenTree.helpers import DownloadFile, GetExportFormats
|
||||
|
||||
from .admin import BomItemResource
|
||||
from .models import BomItem
|
||||
from company.models import SupplierPart
|
||||
from company.models import ManufacturerPart, SupplierPart
|
||||
|
||||
|
||||
def IsValidBOMFormat(fmt):
|
||||
@ -49,7 +49,7 @@ def MakeBomTemplate(fmt):
|
||||
return DownloadFile(data, filename)
|
||||
|
||||
|
||||
def ExportBom(part, fmt='csv', cascade=False, max_levels=None, parameter_data=False, stock_data=False, supplier_data=False):
|
||||
def ExportBom(part, fmt='csv', cascade=False, max_levels=None, parameter_data=False, stock_data=False, supplier_data=False, manufacturer_data=False):
|
||||
""" Export a BOM (Bill of Materials) for a given part.
|
||||
|
||||
Args:
|
||||
@ -160,7 +160,123 @@ def ExportBom(part, fmt='csv', cascade=False, max_levels=None, parameter_data=Fa
|
||||
# Add stock columns to dataset
|
||||
add_columns_to_dataset(stock_cols, len(bom_items))
|
||||
|
||||
if supplier_data:
|
||||
if manufacturer_data and supplier_data:
|
||||
"""
|
||||
If requested, add extra columns for each SupplierPart and ManufacturerPart associated with each line item
|
||||
"""
|
||||
|
||||
# Expand dataset with manufacturer parts
|
||||
manufacturer_headers = [
|
||||
_('Manufacturer'),
|
||||
_('MPN'),
|
||||
]
|
||||
|
||||
supplier_headers = [
|
||||
_('Supplier'),
|
||||
_('SKU'),
|
||||
]
|
||||
|
||||
manufacturer_cols = {}
|
||||
|
||||
for b_idx, bom_item in enumerate(bom_items):
|
||||
# Get part instance
|
||||
b_part = bom_item.sub_part
|
||||
|
||||
# Filter manufacturer parts
|
||||
manufacturer_parts = ManufacturerPart.objects.filter(part__pk=b_part.pk)
|
||||
manufacturer_parts = manufacturer_parts.prefetch_related('supplier_parts')
|
||||
|
||||
# Process manufacturer part
|
||||
for manufacturer_idx, manufacturer_part in enumerate(manufacturer_parts):
|
||||
|
||||
if manufacturer_part:
|
||||
manufacturer_name = manufacturer_part.manufacturer.name
|
||||
else:
|
||||
manufacturer_name = ''
|
||||
|
||||
manufacturer_mpn = manufacturer_part.MPN
|
||||
|
||||
# Generate column names for this manufacturer
|
||||
k_man = manufacturer_headers[0] + "_" + str(manufacturer_idx)
|
||||
k_mpn = manufacturer_headers[1] + "_" + str(manufacturer_idx)
|
||||
|
||||
try:
|
||||
manufacturer_cols[k_man].update({b_idx: manufacturer_name})
|
||||
manufacturer_cols[k_mpn].update({b_idx: manufacturer_mpn})
|
||||
except KeyError:
|
||||
manufacturer_cols[k_man] = {b_idx: manufacturer_name}
|
||||
manufacturer_cols[k_mpn] = {b_idx: manufacturer_mpn}
|
||||
|
||||
# Process supplier parts
|
||||
for supplier_idx, supplier_part in enumerate(manufacturer_part.supplier_parts.all()):
|
||||
|
||||
if supplier_part.supplier:
|
||||
supplier_name = supplier_part.supplier.name
|
||||
else:
|
||||
supplier_name = ''
|
||||
|
||||
supplier_sku = supplier_part.SKU
|
||||
|
||||
# Generate column names for this supplier
|
||||
k_sup = str(supplier_headers[0]) + "_" + str(manufacturer_idx) + "_" + str(supplier_idx)
|
||||
k_sku = str(supplier_headers[1]) + "_" + str(manufacturer_idx) + "_" + str(supplier_idx)
|
||||
|
||||
try:
|
||||
manufacturer_cols[k_sup].update({b_idx: supplier_name})
|
||||
manufacturer_cols[k_sku].update({b_idx: supplier_sku})
|
||||
except KeyError:
|
||||
manufacturer_cols[k_sup] = {b_idx: supplier_name}
|
||||
manufacturer_cols[k_sku] = {b_idx: supplier_sku}
|
||||
|
||||
# Add manufacturer columns to dataset
|
||||
add_columns_to_dataset(manufacturer_cols, len(bom_items))
|
||||
|
||||
elif manufacturer_data:
|
||||
"""
|
||||
If requested, add extra columns for each ManufacturerPart associated with each line item
|
||||
"""
|
||||
|
||||
# Expand dataset with manufacturer parts
|
||||
manufacturer_headers = [
|
||||
_('Manufacturer'),
|
||||
_('MPN'),
|
||||
]
|
||||
|
||||
manufacturer_cols = {}
|
||||
|
||||
for b_idx, bom_item in enumerate(bom_items):
|
||||
# Get part instance
|
||||
b_part = bom_item.sub_part
|
||||
|
||||
# Filter supplier parts
|
||||
manufacturer_parts = ManufacturerPart.objects.filter(part__pk=b_part.pk)
|
||||
|
||||
for idx, manufacturer_part in enumerate(manufacturer_parts):
|
||||
|
||||
if manufacturer_part:
|
||||
manufacturer_name = manufacturer_part.manufacturer.name
|
||||
else:
|
||||
manufacturer_name = ''
|
||||
|
||||
manufacturer_mpn = manufacturer_part.MPN
|
||||
|
||||
# Add manufacturer data to the manufacturer columns
|
||||
|
||||
# Generate column names for this manufacturer
|
||||
k_man = manufacturer_headers[0] + "_" + str(idx)
|
||||
k_mpn = manufacturer_headers[1] + "_" + str(idx)
|
||||
|
||||
try:
|
||||
manufacturer_cols[k_man].update({b_idx: manufacturer_name})
|
||||
manufacturer_cols[k_mpn].update({b_idx: manufacturer_mpn})
|
||||
except KeyError:
|
||||
manufacturer_cols[k_man] = {b_idx: manufacturer_name}
|
||||
manufacturer_cols[k_mpn] = {b_idx: manufacturer_mpn}
|
||||
|
||||
# Add manufacturer columns to dataset
|
||||
add_columns_to_dataset(manufacturer_cols, len(bom_items))
|
||||
|
||||
elif supplier_data:
|
||||
"""
|
||||
If requested, add extra columns for each SupplierPart associated with each line item
|
||||
"""
|
||||
@ -169,8 +285,6 @@ def ExportBom(part, fmt='csv', cascade=False, max_levels=None, parameter_data=Fa
|
||||
manufacturer_headers = [
|
||||
_('Supplier'),
|
||||
_('SKU'),
|
||||
_('Manufacturer'),
|
||||
_('MPN'),
|
||||
]
|
||||
|
||||
manufacturer_cols = {}
|
||||
@ -191,31 +305,18 @@ def ExportBom(part, fmt='csv', cascade=False, max_levels=None, parameter_data=Fa
|
||||
|
||||
supplier_sku = supplier_part.SKU
|
||||
|
||||
if supplier_part.manufacturer:
|
||||
manufacturer_name = supplier_part.manufacturer.name
|
||||
else:
|
||||
manufacturer_name = ''
|
||||
|
||||
manufacturer_mpn = supplier_part.MPN
|
||||
|
||||
# Add manufacturer data to the manufacturer columns
|
||||
|
||||
# Generate column names for this supplier
|
||||
k_sup = manufacturer_headers[0] + "_" + str(idx)
|
||||
k_sku = manufacturer_headers[1] + "_" + str(idx)
|
||||
k_man = manufacturer_headers[2] + "_" + str(idx)
|
||||
k_mpn = manufacturer_headers[3] + "_" + str(idx)
|
||||
|
||||
try:
|
||||
manufacturer_cols[k_sup].update({b_idx: supplier_name})
|
||||
manufacturer_cols[k_sku].update({b_idx: supplier_sku})
|
||||
manufacturer_cols[k_man].update({b_idx: manufacturer_name})
|
||||
manufacturer_cols[k_mpn].update({b_idx: manufacturer_mpn})
|
||||
except KeyError:
|
||||
manufacturer_cols[k_sup] = {b_idx: supplier_name}
|
||||
manufacturer_cols[k_sku] = {b_idx: supplier_sku}
|
||||
manufacturer_cols[k_man] = {b_idx: manufacturer_name}
|
||||
manufacturer_cols[k_mpn] = {b_idx: manufacturer_mpn}
|
||||
|
||||
# Add manufacturer columns to dataset
|
||||
add_columns_to_dataset(manufacturer_cols, len(bom_items))
|
||||
|
@ -95,9 +95,11 @@ class BomExportForm(forms.Form):
|
||||
parameter_data = forms.BooleanField(label=_("Include Parameter Data"), required=False, initial=False, help_text=_("Include part parameters data in exported BOM"))
|
||||
|
||||
stock_data = forms.BooleanField(label=_("Include Stock Data"), required=False, initial=False, help_text=_("Include part stock data in exported BOM"))
|
||||
|
||||
manufacturer_data = forms.BooleanField(label=_("Include Manufacturer Data"), required=False, initial=True, help_text=_("Include part manufacturer data in exported BOM"))
|
||||
|
||||
supplier_data = forms.BooleanField(label=_("Include Supplier Data"), required=False, initial=True, help_text=_("Include part supplier data in exported BOM"))
|
||||
|
||||
|
||||
def get_choices(self):
|
||||
""" BOM export format choices """
|
||||
|
||||
|
92
InvenTree/part/templates/part/manufacturer.html
Normal file
92
InvenTree/part/templates/part/manufacturer.html
Normal file
@ -0,0 +1,92 @@
|
||||
{% extends "part/part_base.html" %}
|
||||
{% load static %}
|
||||
{% load i18n %}
|
||||
{% load inventree_extras %}
|
||||
|
||||
{% block menubar %}
|
||||
{% include 'part/navbar.html' with tab='manufacturers' %}
|
||||
{% endblock %}
|
||||
|
||||
{% block heading %}
|
||||
{% trans "Part Manufacturers" %}
|
||||
{% endblock %}
|
||||
|
||||
{% block details %}
|
||||
|
||||
<div id='button-toolbar'>
|
||||
<div class='btn-group'>
|
||||
<button class="btn btn-success" id='manufacturer-create'>
|
||||
<span class='fas fa-plus-circle'></span> {% trans "New Manufacturer Part" %}
|
||||
</button>
|
||||
<div id='opt-dropdown' class="btn-group">
|
||||
<button id='manufacturer-part-options' class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">{% trans "Options" %}<span class="caret"></span></button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href='#' id='manufacturer-part-delete' title='{% trans "Delete manufacturer parts" %}'>{% trans "Delete" %}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table class="table table-striped table-condensed" id='manufacturer-table' data-toolbar='#button-toolbar'>
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block js_load %}
|
||||
{{ block.super }}
|
||||
{% endblock %}
|
||||
{% block js_ready %}
|
||||
{{ block.super }}
|
||||
|
||||
$('#manufacturer-create').click(function () {
|
||||
launchModalForm(
|
||||
"{% url 'manufacturer-part-create' %}",
|
||||
{
|
||||
reload: true,
|
||||
data: {
|
||||
part: {{ part.id }}
|
||||
},
|
||||
secondary: [
|
||||
{
|
||||
field: 'manufacturer',
|
||||
label: '{% trans "New Manufacturer" %}',
|
||||
title: '{% trans "Create new manufacturer" %}',
|
||||
url: "{% url 'manufacturer-create' %}",
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
$("#manufacturer-part-delete").click(function() {
|
||||
|
||||
var selections = $("#manufacturer-table").bootstrapTable("getSelections");
|
||||
|
||||
var parts = [];
|
||||
|
||||
selections.forEach(function(item) {
|
||||
parts.push(item.pk);
|
||||
});
|
||||
|
||||
launchModalForm("{% url 'manufacturer-part-delete' %}", {
|
||||
data: {
|
||||
parts: parts,
|
||||
},
|
||||
reload: true,
|
||||
});
|
||||
});
|
||||
|
||||
loadManufacturerPartTable(
|
||||
"#manufacturer-table",
|
||||
"{% url 'api-manufacturer-part-list' %}",
|
||||
{
|
||||
params: {
|
||||
part: {{ part.id }},
|
||||
part_detail: false,
|
||||
manufacturer_detail: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
linkButtonsToSelection($("#manufacturer-table"), ['#manufacturer-part-options'])
|
||||
|
||||
{% endblock %}
|
@ -69,6 +69,12 @@
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if part.purchaseable and roles.purchase_order.view %}
|
||||
<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-industry'></span>
|
||||
{% trans "Manufacturers" %}
|
||||
</a>
|
||||
</li>
|
||||
<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-building'></span>
|
||||
|
@ -1,14 +1,15 @@
|
||||
{% extends "modal_form.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block pre_form_content %}
|
||||
|
||||
<div class='alert alert-block alert-danger'>
|
||||
Are you sure you want to delete part '<b>{{ part.full_name }}</b>'?
|
||||
{% trans "Are you sure you want to delete part" %} '<b>{{ part.full_name }}</b>'?
|
||||
</div>
|
||||
|
||||
{% if part.used_in_count %}
|
||||
<hr>
|
||||
<p>This part is used in BOMs for {{ part.used_in_count }} other parts. If you delete this part, the BOMs for the following parts will be updated:
|
||||
<p>{% trans "This part is used in BOMs for" %} {{ part.used_in_count }} {% trans "other parts. If you delete this part, the BOMs for the following parts will be updated" %}:
|
||||
<ul class="list-group">
|
||||
{% for child in part.used_in.all %}
|
||||
<li class='list-group-item'>{{ child.part.full_name }} - {{ child.part.description }}</li>
|
||||
@ -18,7 +19,7 @@
|
||||
|
||||
{% if part.stock_items.all|length > 0 %}
|
||||
<hr>
|
||||
<p>There are {{ part.stock_items.all|length }} stock entries defined for this part. If you delete this part, the following stock entries will also be deleted:
|
||||
<p>{% trans "There are" %} {{ part.stock_items.all|length }} {% trans "stock entries defined for this part. If you delete this part, the following stock entries will also be deleted" %}:
|
||||
<ul class='list-group'>
|
||||
{% for stock in part.stock_items.all %}
|
||||
<li class='list-group-item'>{{ stock }}</li>
|
||||
@ -27,9 +28,20 @@
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if part.manufacturer_parts.all|length > 0 %}
|
||||
<hr>
|
||||
<p>{% trans "There are" %} {{ part.manufacturer_parts.all|length }} {% trans "manufacturers defined for this part. If you delete this part, the following manufacturer parts will also be deleted" %}:
|
||||
<ul class='list-group'>
|
||||
{% for spart in part.manufacturer_parts.all %}
|
||||
<li class='list-group-item'>{{ spart.manufacturer.name }} - {{ spart.MPN }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if part.supplier_parts.all|length > 0 %}
|
||||
<hr>
|
||||
<p>There are {{ part.supplier_parts.all|length }} suppliers defined for this part. If you delete this part, the following supplier parts will also be deleted.
|
||||
<p>{% trans "There are" %} {{ part.supplier_parts.all|length }} {% trans "suppliers defined for this part. If you delete this part, the following supplier parts will also be deleted" %}:
|
||||
<ul class='list-group'>
|
||||
{% for spart in part.supplier_parts.all %}
|
||||
<li class='list-group-item'>{{ spart.supplier.name }} - {{ spart.SKU }}</li>
|
||||
@ -40,7 +52,7 @@
|
||||
|
||||
{% if part.serials.all|length > 0 %}
|
||||
<hr>
|
||||
<p>There are {{ part.serials.all|length }} unique parts tracked for '{{ part.full_name }}'. Deleting this part will permanently remove this tracking information.</p>
|
||||
<p>{% trans "There are" %} {{ part.serials.all|length }} {% trans "unique parts tracked for" %} '{{ part.full_name }}'. {% trans "Deleting this part will permanently remove this tracking information" %}.</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
@ -85,7 +85,7 @@
|
||||
{
|
||||
params: {
|
||||
part: {{ part.id }},
|
||||
part_detail: true,
|
||||
part_detail: false,
|
||||
supplier_detail: true,
|
||||
manufacturer_detail: true,
|
||||
},
|
||||
|
@ -60,6 +60,7 @@ part_detail_urls = [
|
||||
url(r'^bom/?', views.PartDetail.as_view(template_name='part/bom.html'), name='part-bom'),
|
||||
url(r'^build/?', views.PartDetail.as_view(template_name='part/build.html'), name='part-build'),
|
||||
url(r'^used/?', views.PartDetail.as_view(template_name='part/used_in.html'), name='part-used-in'),
|
||||
url(r'^manufacturers/?', views.PartDetail.as_view(template_name='part/manufacturer.html'), name='part-manufacturers'),
|
||||
url(r'^suppliers/?', views.PartDetail.as_view(template_name='part/supplier.html'), name='part-suppliers'),
|
||||
url(r'^orders/?', views.PartDetail.as_view(template_name='part/orders.html'), name='part-orders'),
|
||||
url(r'^sales-orders/', views.PartDetail.as_view(template_name='part/sales_orders.html'), name='part-sales-orders'),
|
||||
|
@ -1845,6 +1845,8 @@ class BomDownload(AjaxView):
|
||||
|
||||
supplier_data = str2bool(request.GET.get('supplier_data', False))
|
||||
|
||||
manufacturer_data = str2bool(request.GET.get('manufacturer_data', False))
|
||||
|
||||
levels = request.GET.get('levels', None)
|
||||
|
||||
if levels is not None:
|
||||
@ -1866,7 +1868,9 @@ class BomDownload(AjaxView):
|
||||
max_levels=levels,
|
||||
parameter_data=parameter_data,
|
||||
stock_data=stock_data,
|
||||
supplier_data=supplier_data)
|
||||
supplier_data=supplier_data,
|
||||
manufacturer_data=manufacturer_data,
|
||||
)
|
||||
|
||||
def get_data(self):
|
||||
return {
|
||||
@ -1896,6 +1900,7 @@ class BomExport(AjaxView):
|
||||
parameter_data = str2bool(request.POST.get('parameter_data', False))
|
||||
stock_data = str2bool(request.POST.get('stock_data', False))
|
||||
supplier_data = str2bool(request.POST.get('supplier_data', False))
|
||||
manufacturer_data = str2bool(request.POST.get('manufacturer_data', False))
|
||||
|
||||
try:
|
||||
part = Part.objects.get(pk=self.kwargs['pk'])
|
||||
@ -1913,6 +1918,7 @@ class BomExport(AjaxView):
|
||||
url += '¶meter_data=' + str(parameter_data)
|
||||
url += '&stock_data=' + str(stock_data)
|
||||
url += '&supplier_data=' + str(supplier_data)
|
||||
url += '&manufacturer_data=' + str(manufacturer_data)
|
||||
|
||||
if levels:
|
||||
url += '&levels=' + str(levels)
|
||||
|
Reference in New Issue
Block a user