mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #343 from SchrodingersGat/filter-by-supplier
Filter by supplier
This commit is contained in:
commit
283bd0e3ad
@ -7,6 +7,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from django.apps import apps
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -111,6 +112,18 @@ class Company(models.Model):
|
|||||||
""" Return True if this company supplies any parts """
|
""" Return True if this company supplies any parts """
|
||||||
return self.part_count > 0
|
return self.part_count > 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def stock_items(self):
|
||||||
|
""" Return a list of all stock items supplied by this company """
|
||||||
|
stock = apps.get_model('stock', 'StockItem')
|
||||||
|
return stock.objects.filter(supplier_part__supplier=self.id).all()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def stock_count(self):
|
||||||
|
""" Return the number of stock items supplied by this company """
|
||||||
|
stock = apps.get_model('stock', 'StockItem')
|
||||||
|
return stock.objects.filter(supplier_part__supplier=self.id).count()
|
||||||
|
|
||||||
|
|
||||||
class Contact(models.Model):
|
class Contact(models.Model):
|
||||||
""" A Contact represents a person who works at a particular company.
|
""" A Contact represents a person who works at a particular company.
|
||||||
|
@ -72,6 +72,11 @@ InvenTree | Company - {{ company.name }}
|
|||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block js_load %}
|
||||||
|
{{ block.super }}
|
||||||
|
<script type='text/javascript' src="{% static 'script/inventree/stock.js' %}"></script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block js_ready %}
|
{% block js_ready %}
|
||||||
|
|
||||||
enableDragAndDrop(
|
enableDragAndDrop(
|
||||||
|
25
InvenTree/company/templates/company/detail_stock.html
Normal file
25
InvenTree/company/templates/company/detail_stock.html
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{% extends "company/company_base.html" %}
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
{% block details %}
|
||||||
|
|
||||||
|
{% include "company/tabs.html" with tab='stock' %}
|
||||||
|
|
||||||
|
<h3>Supplier Stock</h3>
|
||||||
|
|
||||||
|
<table class='table table-striped table-condensed' id='stock-table'>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
{% block js_ready %}
|
||||||
|
{{ block.super }}
|
||||||
|
|
||||||
|
loadStockTable($('#stock-table'),
|
||||||
|
{
|
||||||
|
url: "{% url 'api-stock-list' %}",
|
||||||
|
params: {
|
||||||
|
supplier: {{ company.id }},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
{% endblock %}
|
@ -6,6 +6,9 @@
|
|||||||
<li{% if tab == 'parts' %} class='active'{% endif %}>
|
<li{% if tab == 'parts' %} class='active'{% endif %}>
|
||||||
<a href="{% url 'company-detail-parts' company.id %}">Supplier Parts <span class='badge'>{{ company.part_count }}</span></a>
|
<a href="{% url 'company-detail-parts' company.id %}">Supplier Parts <span class='badge'>{{ company.part_count }}</span></a>
|
||||||
</li>
|
</li>
|
||||||
|
<li{% if tab == 'stock' %} class='active'{% endif %}>
|
||||||
|
<a href="{% url 'company-detail-stock' company.id %}">Stock <span class='badge'>{{ company.stock_count }}</a>
|
||||||
|
</li>
|
||||||
{% if 0 %}
|
{% if 0 %}
|
||||||
<li{% if tab == 'po' %} class='active'{% endif %}>
|
<li{% if tab == 'po' %} class='active'{% endif %}>
|
||||||
<a href="#">Purchase Orders</a>
|
<a href="#">Purchase Orders</a>
|
||||||
|
@ -16,6 +16,7 @@ company_detail_urls = [
|
|||||||
# url(r'orders/?', views.CompanyDetail.as_view(template_name='company/orders.html'), name='company-detail-orders'),
|
# 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'parts/?', views.CompanyDetail.as_view(template_name='company/detail_part.html'), name='company-detail-parts'),
|
||||||
|
url(r'stock/?', views.CompanyDetail.as_view(template_name='company/detail_stock.html'), name='company-detail-stock'),
|
||||||
|
|
||||||
url(r'thumbnail/?', views.CompanyImage.as_view(), name='company-image'),
|
url(r'thumbnail/?', views.CompanyImage.as_view(), name='company-image'),
|
||||||
|
|
||||||
|
@ -242,6 +242,7 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
Additional query parameters are available:
|
Additional query parameters are available:
|
||||||
- location: Filter stock by location
|
- location: Filter stock by location
|
||||||
- category: Filter by parts belonging to a certain category
|
- category: Filter by parts belonging to a certain category
|
||||||
|
- supplier: Filter by supplier
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
@ -275,6 +276,12 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
except PartCategory.DoesNotExist:
|
except PartCategory.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Filter by supplier
|
||||||
|
supplier_id = self.request.query_params.get('supplier', None)
|
||||||
|
|
||||||
|
if supplier_id:
|
||||||
|
stock_list = stock_list.filter(supplier_part__supplier=supplier_id)
|
||||||
|
|
||||||
return stock_list
|
return stock_list
|
||||||
|
|
||||||
serializer_class = StockItemSerializer
|
serializer_class = StockItemSerializer
|
||||||
|
Loading…
Reference in New Issue
Block a user