mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Fix "supplier parts" tab for Company display
Also PEP fixes
This commit is contained in:
parent
f067eae7d2
commit
a50ecb24c1
@ -72,3 +72,100 @@ function loadCompanyTable(table, url, options={}) {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function loadSupplierPartTable(table, url, options) {
|
||||||
|
/*
|
||||||
|
* Load supplier part table
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Query parameters
|
||||||
|
var params = options.params || {};
|
||||||
|
|
||||||
|
// Load 'user' filters
|
||||||
|
var filters = loadTableFilters("supplier-part");
|
||||||
|
|
||||||
|
for (var key in params) {
|
||||||
|
filters[key] = params[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
setupFilterList("supplier-part", $(table));
|
||||||
|
|
||||||
|
$(table).inventreeTable({
|
||||||
|
url: url,
|
||||||
|
method: 'get',
|
||||||
|
queryParams: filters,
|
||||||
|
groupBy: false,
|
||||||
|
formatNoMatches: function() { return "No supplier parts found"; },
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
checkbox: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sortable: true,
|
||||||
|
field: 'part_detail.full_name',
|
||||||
|
title: 'Part',
|
||||||
|
formatter: function(value, row, index, field) {
|
||||||
|
|
||||||
|
var url = `/part/${row.part}/`;
|
||||||
|
|
||||||
|
var html = imageHoverIcon(row.part_detail.thumbnail) + renderLink(value, url);
|
||||||
|
|
||||||
|
if (row.part_detail.is_template) {
|
||||||
|
html += `<span class='fas fa-clone label-right' title='Template part'></span>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (row.part_detail.assembly) {
|
||||||
|
html += `<span class='fas fa-tools label-right' title='Assembled part'></span>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!row.part_detail.active) {
|
||||||
|
html += `<span class='label label-warning label-right'>INACTIVE</span>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sortable: true,
|
||||||
|
field: 'SKU',
|
||||||
|
title: "Supplier Part",
|
||||||
|
formatter: function(value, row, index, field) {
|
||||||
|
return renderLink(value, row.url);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sortable: true,
|
||||||
|
field: 'manufacturer',
|
||||||
|
title: '"Manufacturer"',
|
||||||
|
formatter: function(value, row, index, field) {
|
||||||
|
if (value) {
|
||||||
|
var name = row.manufacturer_detail.name;
|
||||||
|
var html = imageHoverIcon(row.manufacturer_detail.image) + renderLink(name, '/company/' + value + '/');
|
||||||
|
|
||||||
|
return html;
|
||||||
|
} else {
|
||||||
|
return "-";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sortable: true,
|
||||||
|
field: 'MPN',
|
||||||
|
title: 'MPN',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'link',
|
||||||
|
title: 'Link',
|
||||||
|
formatter: function(value, row, index, field) {
|
||||||
|
if (value) {
|
||||||
|
return renderLink(value, value);
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
@ -10,6 +10,7 @@ from rest_framework import filters
|
|||||||
from rest_framework import generics, permissions
|
from rest_framework import generics, permissions
|
||||||
|
|
||||||
from django.conf.urls import url, include
|
from django.conf.urls import url, include
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
from InvenTree.helpers import str2bool
|
from InvenTree.helpers import str2bool
|
||||||
|
|
||||||
@ -95,6 +96,8 @@ class SupplierPartList(generics.ListCreateAPIView):
|
|||||||
if company is not None:
|
if company is not None:
|
||||||
queryset = queryset.filter(Q(manufacturer=company) | Q(supplier=company))
|
queryset = queryset.filter(Q(manufacturer=company) | Q(supplier=company))
|
||||||
|
|
||||||
|
return queryset
|
||||||
|
|
||||||
def get_serializer(self, *args, **kwargs):
|
def get_serializer(self, *args, **kwargs):
|
||||||
|
|
||||||
# Do we wish to include extra detail?
|
# Do we wish to include extra detail?
|
||||||
@ -177,15 +180,15 @@ supplier_part_api_urls = [
|
|||||||
url(r'^(?P<pk>\d+)/?', SupplierPartDetail.as_view(), name='api-supplier-part-detail'),
|
url(r'^(?P<pk>\d+)/?', SupplierPartDetail.as_view(), name='api-supplier-part-detail'),
|
||||||
|
|
||||||
# Catch anything else
|
# Catch anything else
|
||||||
url(r'^.*$', SupplierPartList.as_view(), name='api-part-supplier-list'),
|
url(r'^.*$', SupplierPartList.as_view(), name='api-supplier-part-list'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
company_api_urls = [
|
company_api_urls = [
|
||||||
|
|
||||||
url(r'^part/?', include(supplier_part_api_urls)),
|
url(r'^part/', include(supplier_part_api_urls)),
|
||||||
|
|
||||||
url(r'^price-break/?', SupplierPriceBreakList.as_view(), name='api-part-supplier-price'),
|
url(r'^price-break/', SupplierPriceBreakList.as_view(), name='api-part-supplier-price'),
|
||||||
|
|
||||||
url(r'^(?P<pk>\d+)/?', CompanyDetail.as_view(), name='api-company-detail'),
|
url(r'^(?P<pk>\d+)/?', CompanyDetail.as_view(), name='api-company-detail'),
|
||||||
|
|
||||||
|
@ -280,7 +280,9 @@ class SupplierPart(models.Model):
|
|||||||
|
|
||||||
SKU = models.CharField(max_length=100, help_text=_('Supplier stock keeping unit'))
|
SKU = models.CharField(max_length=100, help_text=_('Supplier stock keeping unit'))
|
||||||
|
|
||||||
manufacturer = models.ForeignKey(Company, on_delete=models.SET_NULL,
|
manufacturer = models.ForeignKey(
|
||||||
|
Company,
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
related_name='manufactured_parts',
|
related_name='manufactured_parts',
|
||||||
limit_choices_to={'is_manufacturer': True},
|
limit_choices_to={'is_manufacturer': True},
|
||||||
help_text=_('Select manufacturer'),
|
help_text=_('Select manufacturer'),
|
||||||
|
@ -47,85 +47,18 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#part-table").inventreeTable({
|
loadSupplierPartTable(
|
||||||
formatNoMatches: function() { return "No supplier parts found for {{ company.name }}"; },
|
"#part-table",
|
||||||
queryParams: function(p) {
|
"{% url 'api-supplier-part-list' %}",
|
||||||
return {
|
{
|
||||||
supplier: {{ company.id }},
|
params: {
|
||||||
part_detail: true,
|
part_detail: true,
|
||||||
supplier_detail: true,
|
supplier_detail: true,
|
||||||
manufacturer_detail: true,
|
manufacturer_detail: true,
|
||||||
}
|
company: {{ company.id }},
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
checkbox: true,
|
|
||||||
},
|
},
|
||||||
{
|
}
|
||||||
sortable: true,
|
);
|
||||||
field: 'part_detail.full_name',
|
|
||||||
title: '{% trans "Part" %}',
|
|
||||||
formatter: function(value, row, index, field) {
|
|
||||||
|
|
||||||
var html = imageHoverIcon(row.part_detail.thumbnail) + renderLink(value, '/part/' + row.part + '/suppliers/');
|
|
||||||
|
|
||||||
if (row.part_detail.is_template) {
|
|
||||||
html += `<span class='fas fa-clone label-right' title='Template part'></span>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (row.part_detail.assembly) {
|
|
||||||
html += `<span class='fas fa-tools label-right' title='Assembled part'></span>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!row.part_detail.active) {
|
|
||||||
html += `<span class='label label-warning label-right'>INACTIVE</span>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return html;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
sortable: true,
|
|
||||||
field: 'SKU',
|
|
||||||
title: '{% trans "SKU" %}',
|
|
||||||
formatter: function(value, row, index, field) {
|
|
||||||
return renderLink(value, row.url);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
sortable: true,
|
|
||||||
field: 'manufacturer',
|
|
||||||
title: '{% trans "Manufacturer" %}',
|
|
||||||
formatter: function(value, row, index, field) {
|
|
||||||
if (value) {
|
|
||||||
var name = row.manufacturer_detail.name;
|
|
||||||
var html = imageHoverIcon(row.manufacturer_detail.image) + renderLink(name, '/company/' + value + '/');
|
|
||||||
|
|
||||||
return html;
|
|
||||||
} else {
|
|
||||||
return "-";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
sortable: true,
|
|
||||||
field: 'MPN',
|
|
||||||
title: 'MPN',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
field: 'link',
|
|
||||||
title: '{% trans "Link" %}',
|
|
||||||
formatter: function(value, row, index, field) {
|
|
||||||
if (value) {
|
|
||||||
return renderLink(value, value);
|
|
||||||
} else {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
],
|
|
||||||
url: "{% url 'api-part-supplier-list' %}"
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#multi-part-delete").click(function() {
|
$("#multi-part-delete").click(function() {
|
||||||
var selections = $("#part-table").bootstrapTable("getSelections");
|
var selections = $("#part-table").bootstrapTable("getSelections");
|
||||||
|
@ -2,9 +2,7 @@
|
|||||||
URL lookup for Company app
|
URL lookup for Company app
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from django.conf.urls import url, include
|
from django.conf.urls import url, include
|
||||||
from django.views.generic.base import RedirectView
|
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
|
@ -85,12 +85,11 @@ class CompanyIndex(ListView):
|
|||||||
if context is None:
|
if context is None:
|
||||||
context = default
|
context = default
|
||||||
|
|
||||||
for key,value in context.items():
|
for key, value in context.items():
|
||||||
ctx[key] = value
|
ctx[key] = value
|
||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
""" Retrieve the Company queryset based on HTTP request parameters.
|
""" Retrieve the Company queryset based on HTTP request parameters.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user