mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
List purchase orders for a given part
This commit is contained in:
parent
9b2b2841d9
commit
67248ec4dd
@ -307,6 +307,11 @@ class SupplierPart(models.Model):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def purchase_orders(self):
|
||||||
|
""" Returns a list of purchase orders relating to this supplier part """
|
||||||
|
|
||||||
|
return [line.order for line in self.purchase_order_line_items.all().prefetch_related('order')]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
s = "{supplier} ({sku})".format(
|
s = "{supplier} ({sku})".format(
|
||||||
sku=self.SKU,
|
sku=self.SKU,
|
||||||
|
19
InvenTree/order/migrations/0007_auto_20190605_2138.py
Normal file
19
InvenTree/order/migrations/0007_auto_20190605_2138.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 2.2 on 2019-06-05 11:38
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('order', '0006_auto_20190605_2056'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='purchaseorderlineitem',
|
||||||
|
name='part',
|
||||||
|
field=models.ForeignKey(blank=True, help_text='Supplier part', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='order_line_items', to='company.SupplierPart'),
|
||||||
|
),
|
||||||
|
]
|
19
InvenTree/order/migrations/0008_auto_20190605_2140.py
Normal file
19
InvenTree/order/migrations/0008_auto_20190605_2140.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 2.2 on 2019-06-05 11:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('order', '0007_auto_20190605_2138'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='purchaseorderlineitem',
|
||||||
|
name='part',
|
||||||
|
field=models.ForeignKey(blank=True, help_text='Supplier part', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='purchase_order_line_items', to='company.SupplierPart'),
|
||||||
|
),
|
||||||
|
]
|
@ -124,7 +124,7 @@ class PurchaseOrderLineItem(OrderLineItem):
|
|||||||
part = models.ForeignKey(
|
part = models.ForeignKey(
|
||||||
SupplierPart, on_delete=models.SET_NULL,
|
SupplierPart, on_delete=models.SET_NULL,
|
||||||
blank=True, null=True,
|
blank=True, null=True,
|
||||||
related_name='orders',
|
related_name='purchase_order_line_items',
|
||||||
help_text=_("Supplier part"),
|
help_text=_("Supplier part"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
16
InvenTree/order/templates/order/po_table.html
Normal file
16
InvenTree/order/templates/order/po_table.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<table class='table table-striped table-condensed' id='po-table'>
|
||||||
|
<tr>
|
||||||
|
<th data-field='company'>Company</th>
|
||||||
|
<th data-field='reference'>Order Reference</th>
|
||||||
|
<th data-field='description'>Description</th>
|
||||||
|
<th data-field='status'>Status</th>
|
||||||
|
</tr>
|
||||||
|
{% for order in orders %}
|
||||||
|
<tr>
|
||||||
|
<td>{% include "hover_image.html" with image=order.supplier.image hover=True %}<a href="{{ order.supplier.get_absolute_url }}">{{ order.supplier.name }}</a></td>
|
||||||
|
<td><a href="{% url 'purchase-order-detail' order.id %}">{{ order }}</a></td>
|
||||||
|
<td>{{ order.description }}</td>
|
||||||
|
<td>{% include "order/order_status.html" %}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
@ -10,22 +10,6 @@ InvenTree | Purchase Orders
|
|||||||
|
|
||||||
<h4>Purchase Orders</h4>
|
<h4>Purchase Orders</h4>
|
||||||
|
|
||||||
|
{% include "order/po_table.html" %}
|
||||||
<table class='table table-striped table-condensed' id='po-table'>
|
|
||||||
<tr>
|
|
||||||
<th>Company</th>
|
|
||||||
<th>Order Reference</th>
|
|
||||||
<th>Description</th>
|
|
||||||
<th>Status</th>
|
|
||||||
</tr>
|
|
||||||
{% for order in orders %}
|
|
||||||
<tr>
|
|
||||||
<td>{% include "hover_image.html" with image=order.supplier.image hover=True %}<a href="{{ order.supplier.get_absolute_url }}">{{ order.supplier.name }}</a></td>
|
|
||||||
<td><a href="{% url 'purchase-order-detail' order.id %}">{{ order }}</a></td>
|
|
||||||
<td>{{ order.description }}</td>
|
|
||||||
<td>{% include "order/order_status.html" %}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</table>
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -794,6 +794,18 @@ class Part(models.Model):
|
|||||||
|
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
def purchase_orders(self):
|
||||||
|
""" Return a list of purchase orders which reference this part """
|
||||||
|
|
||||||
|
orders = []
|
||||||
|
|
||||||
|
for part in self.supplier_parts.all().prefetch_related('purchase_order_line_items'):
|
||||||
|
for order in part.purchase_orders():
|
||||||
|
if order not in orders:
|
||||||
|
orders.append(order)
|
||||||
|
|
||||||
|
return orders
|
||||||
|
|
||||||
|
|
||||||
def attach_file(instance, filename):
|
def attach_file(instance, filename):
|
||||||
""" Function for storing a file for a PartAttachment
|
""" Function for storing a file for a PartAttachment
|
||||||
|
18
InvenTree/part/templates/part/orders.html
Normal file
18
InvenTree/part/templates/part/orders.html
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{% extends "part/part_base.html" %}
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
{% block details %}
|
||||||
|
|
||||||
|
{% include 'part/tabs.html' with tab='orders' %}
|
||||||
|
|
||||||
|
<div class='row'>
|
||||||
|
<div class='col-sm-6'>
|
||||||
|
<h4>Part Orders</h4>
|
||||||
|
</div>
|
||||||
|
<div class='col-sm-6'>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% include "order/po_table.html" with orders=part.purchase_orders %}
|
||||||
|
|
||||||
|
{% endblock %}
|
@ -25,11 +25,17 @@
|
|||||||
<li{% ifequal tab 'used' %} class="active"{% endifequal %}>
|
<li{% ifequal tab 'used' %} class="active"{% endifequal %}>
|
||||||
<a href="{% url 'part-used-in' part.id %}">Used In{% if part.used_in_count > 0 %}<span class="badge">{{ part.used_in_count }}</span>{% endif %}</a></li>
|
<a href="{% url 'part-used-in' part.id %}">Used In{% if part.used_in_count > 0 %}<span class="badge">{{ part.used_in_count }}</span>{% endif %}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if part.purchaseable and part.is_template == False %}
|
{% if part.purchaseable %}
|
||||||
|
{% if part.is_template == False %}
|
||||||
<li{% ifequal tab 'suppliers' %} class="active"{% endifequal %}>
|
<li{% ifequal tab 'suppliers' %} class="active"{% endifequal %}>
|
||||||
<a href="{% url 'part-suppliers' part.id %}">Suppliers
|
<a href="{% url 'part-suppliers' part.id %}">Suppliers
|
||||||
<span class="badge">{{ part.supplier_count }}</span>
|
<span class="badge">{{ part.supplier_count }}</span>
|
||||||
</a></li>
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
<li{% ifequal tab 'orders' %} class='active'{% endifequal %}>
|
||||||
|
<a href="{% url 'part-orders' part.id %}">Purchase Orders <span class='badge'>{{ part.purchase_orders|length }}</span></a>
|
||||||
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if part.trackable and 0 %}
|
{% if part.trackable and 0 %}
|
||||||
<li{% ifequal tab 'track' %} class="active"{% endifequal %}>
|
<li{% ifequal tab 'track' %} class="active"{% endifequal %}>
|
||||||
|
@ -34,6 +34,7 @@ part_detail_urls = [
|
|||||||
url(r'^build/?', views.PartDetail.as_view(template_name='part/build.html'), name='part-build'),
|
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'^used/?', views.PartDetail.as_view(template_name='part/used_in.html'), name='part-used-in'),
|
||||||
url(r'^suppliers/?', views.PartDetail.as_view(template_name='part/supplier.html'), name='part-suppliers'),
|
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'^track/?', views.PartDetail.as_view(template_name='part/track.html'), name='part-track'),
|
url(r'^track/?', views.PartDetail.as_view(template_name='part/track.html'), name='part-track'),
|
||||||
url(r'^attachments/?', views.PartDetail.as_view(template_name='part/attachments.html'), name='part-attachments'),
|
url(r'^attachments/?', views.PartDetail.as_view(template_name='part/attachments.html'), name='part-attachments'),
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ from InvenTree.views import AjaxView, AjaxCreateView, AjaxUpdateView, AjaxDelete
|
|||||||
from InvenTree.views import QRCodeView
|
from InvenTree.views import QRCodeView
|
||||||
|
|
||||||
from InvenTree.helpers import DownloadFile, str2bool
|
from InvenTree.helpers import DownloadFile, str2bool
|
||||||
|
from InvenTree.status_codes import OrderStatus
|
||||||
|
|
||||||
|
|
||||||
class PartIndex(ListView):
|
class PartIndex(ListView):
|
||||||
@ -446,6 +447,8 @@ class PartDetail(DetailView):
|
|||||||
|
|
||||||
context['starred'] = part.isStarredBy(self.request.user)
|
context['starred'] = part.isStarredBy(self.request.user)
|
||||||
|
|
||||||
|
context['OrderStatus'] = OrderStatus
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user