Add a 'sales order' view for each part

This commit is contained in:
Oliver Walters 2020-04-21 09:15:01 +10:00
parent b204618e79
commit 3d2e907d5e
7 changed files with 81 additions and 4 deletions

View File

@ -0,0 +1,20 @@
# Generated by Django 3.0.5 on 2020-04-20 23:09
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('part', '0035_auto_20200406_0045'),
('order', '0022_salesorderlineitem_part'),
]
operations = [
migrations.AlterField(
model_name='salesorderlineitem',
name='part',
field=models.ForeignKey(help_text='Part', limit_choices_to={'salable': True}, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='sales_order_line_items', to='part.Part'),
),
]

View File

@ -370,5 +370,5 @@ class SalesOrderLineItem(OrderLineItem):
order = models.ForeignKey(SalesOrder, on_delete=models.CASCADE, related_name='lines', help_text=_('Sales Order'))
part = models.ForeignKey(Part, on_delete=models.SET_NULL, related_name='sales_orders', null=True, help_text=_('Part'), limit_choices_to={'salable': True})
part = models.ForeignKey(Part, on_delete=models.SET_NULL, related_name='sales_order_line_items', null=True, help_text=_('Part'), limit_choices_to={'salable': True})

View File

@ -924,6 +924,17 @@ class Part(models.Model):
return n
def sales_orders(self):
""" Return a list of sales orders which reference this part """
orders = []
for line in self.sales_order_line_items.all().prefetch_related('order'):
if line.order not in orders:
orders.append(line.order)
return orders
def purchase_orders(self):
""" Return a list of purchase orders which reference this part """

View File

@ -1,16 +1,17 @@
{% extends "part/part_base.html" %}
{% load static %}
{% load i18n %}
{% block details %}
{% include 'part/tabs.html' with tab='orders' %}
<h4>Part Orders</h4>
<h4>{% trans "Purchase Orders" %}</h4>
<hr>
<div id='button-bar'>
<div class='button-toolbar container-fluid' style='float: right;'>
<button class='btn btn-primary' type='button' id='part-order2' title='Order part'>Order Part</button>
<button class='btn btn-primary' type='button' id='part-order2' title='{% trans "Order part" %}'>{% trans "Order Part" %}</button>
<div class='filter-list' id='filter-list-order'>
<!-- An empty div in which the filter list will be constructed -->
</div>
@ -27,7 +28,10 @@
{{ block.super }}
loadPurchaseOrderTable($("#purchase-order-table"), {
url: "{% url 'api-po-list' %}?part={{ part.id }}",
url: "{% url 'api-po-list' %}",
params: {
part: {{ part.id }},
},
});
$("#part-order2").click(function() {

View File

@ -0,0 +1,36 @@
{% extends "part/part_base.html" %}
{% load static %}
{% load i18n %}
{% block details %}
{% include 'part/tabs.html' with tab='sales-orders' %}
<h4>{% trans "Sales Orders" %}</h4>
<hr>
<div id='button-bar'>
<div class='button-toolbar container-fluid' style='float: right;'>
<button class='btn btn-primary' type='button' id='part-order2' title='{% trans "New sales order" %}'>{% trans "New Order" %}</button>
<div class='filter-list' id='filter-list-order'>
<!-- An empty div in which the filter list will be constructed -->
</div>
</div>
</div>
<table class='table table-striped table-condensed po-table' id='sales-order-table' data-toolbar='#button-bar'>
</table>
{% endblock %}
{% block js_ready %}
{{ block.super }}
loadSalesOrderTable($("#sales-order-table"), {
url: "{% url 'api-so-list' %}",
params: {
part: {{ part.id }},
},
});
{% endblock %}

View File

@ -43,6 +43,11 @@
<a href="{% url 'part-orders' part.id %}">{% trans "Purchase Orders" %} <span class='badge'>{{ part.purchase_orders|length }}</span></a>
</li>
{% endif %}
{% if part.salable %}
<li{% ifequal tab 'sales-orders' %} class='active'{% endifequal %}>
<a href="{% url 'part-sales-orders' part.id %}">{% trans "Sales Orders" %} <span class='badge'>{{ part.sales_orders|length }}</span></a>
</li>
{% endif %}
{% if part.trackable and 0 %}
<li{% ifequal tab 'track' %} class="active"{% endifequal %}>
<a href="{% url 'part-track' part.id %}">{% trans "Tracking" %}

View File

@ -51,6 +51,7 @@ part_detail_urls = [
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'^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'),
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'^notes/?', views.PartNotes.as_view(), name='part-notes'),