Company index / detail / edit pages working

This commit is contained in:
Oliver 2018-04-22 22:21:50 +10:00
parent 4bedf0ed4c
commit ee2f262e19
10 changed files with 112 additions and 93 deletions

View File

@ -68,12 +68,16 @@ urlpatterns = [
# url(r'^api-doc/', include_docs_urls(title='InvenTree API')),
url(r'^part/', include(part_urls)),
url(r'^stock/', include(stock_urls)),
url(r'^company/', include(company_urls)),
url(r'^supplier-part/', include(supplier_part_urls)),
url(r'^stock/', include(stock_urls)),
url(r'^company/', include(company_urls)),
url(r'^build/', include(build_urls)),
url(r'^admin/', admin.site.urls),
url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')),
]

View File

@ -51,5 +51,7 @@ class EditCompanyForm(forms.ModelForm):
'email',
'contact',
'image',
'is_customer',
'is_supplier',
'notes'
]

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.12 on 2018-04-22 12:01
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('company', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='company',
name='is_customer',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='company',
name='is_supplier',
field=models.BooleanField(default=False),
),
]

View File

@ -49,6 +49,10 @@ class Company(models.Model):
notes = models.TextField(blank=True)
is_customer = models.BooleanField(default=False)
is_supplier = models.BooleanField(default=False)
def __str__(self):
return self.name

View File

@ -0,0 +1,62 @@
{% extends "base.html" %}
{% load static %}
{% block content %}
<div class="row">
<div class="col-sm-6">
<div class="media">
<div class="media-left">
<img class="part-thumb"
{% if company.image %}
src="{{ company.image.url }}"
{% else %}
src="{% static 'img/blank_image.png' %}"
{% endif %}/>
</div>
<div class='media-body'>
<h4>{{ company.name }}</h4>
<p>{{ company.description }}</p>
</div>
<div class='container-fluid'>
<a href="{% url 'company-edit' company.id %}"><button class="btn btn-info">Edit Company Details</button></a>
</div>
</div>
</div>
<div class="col-sm-6">
<table class="table">
{% if company.website %}
<tr>
<td>Website</td><td><a href="{{ company.website }}">{{ company.website }}</a></td>
</tr>
{% endif %}
{% if company.address %}
<tr>
<td>Address</td><td>{{ company.address }}</td>
</tr>
{% endif %}
{% if company.phone %}
<tr>
<td>Phone</td><td>{{ company.phone }}</td>
</tr>
{% endif %}
{% if company.email %}
<tr>
<td>Email</td><td>{{ company.email }}</td>
</tr>
{% endif %}
{% if company.contact %}
<tr>
<td>Contact</td><td>{{ company.contact }}</td>
</tr>
{% endif %}
</table>
</div>
</div>
{% block details %}
{% endblock %}
{% endblock %}

View File

@ -1,46 +1,5 @@
{% extends "supplier/supplier_base.html" %}
{% extends "company/company_base.html" %}
{% block details %}
{% include "supplier/tabs.html" with tab='parts' %}
<h3>Supplier Parts</h3>
<table class="table table-striped">
<tr>
<th>SKU</th>
<th>Description</th>
<th>Parent Part</th>
<th>MPN</th>
<th>URL</th>
</tr>
{% for part in supplier.parts.all %}
<tr>
<td><a href="{% url 'supplier-part-detail' part.id %}">{{ part.SKU }}</a></td>
<td>{{ part.description }}</td>
<td>
{% if part.part %}
<a href="{% url 'part-suppliers' part.part.id %}">{{ part.part.name }}</a>
{% endif %}
</td>
<td>
{% if part.manufacturer %}{{ part.manufacturer.name }}{% endif %}
{% if part.MPN %} | {{ part.MPN }}{% endif %}
</td>
<td>{{ part.URL }}</td>
{% endfor %}
</table>
<div class='container-fluid'>
<a href="{% url 'supplier-part-create' %}?supplier={{ supplier.id }}">
<button class="btn btn-success">New Supplier Part</button>
</a>
<a href="{% url 'supplier-edit' supplier.id %}">
<button class="btn btn-info">Edit supplier details</button>
</a>
<a href="{% url 'supplier-delete' supplier.id %}">
<button class="btn btn-danger">Delete supplier</button>
</a>
</div>
{% endblock %}

View File

@ -6,7 +6,7 @@
<ul class='list-group'>
{% for company in companies %}
<li class='list-group-item'>
<b><a href="{% url 'company-detail' company.id %}">{{ supplier.name }}</a></b>
<b><a href="{% url 'company-detail' company.id %}">{{ company.name }}</a></b>
<br>
{{ company.description }}
{% if company.website %}

View File

@ -1,46 +0,0 @@
{% extends "base.html" %}
{% block content %}
<div class="row">
<div class="col-sm-6">
<h3>{{ supplier.name }}</h3>
<p>{{ supplier.description }}</p>
<p>{{ supplier.notes }}</p>
</div>
<div class="col-sm-6">
<table class="table">
{% if supplier.website %}
<tr>
<td>Website</td><td><a href="{{ supplier.website }}">{{ supplier.website }}</a></td>
</tr>
{% endif %}
{% if supplier.address %}
<tr>
<td>Address</td><td>{{ supplier.address }}</td>
</tr>
{% endif %}
{% if supplier.phone %}
<tr>
<td>Phone</td><td>{{ supplier.phone }}</td>
</tr>
{% endif %}
{% if supplier.email %}
<tr>
<td>Email</td><td>{{ supplier.email }}</td>
</tr>
{% endif %}
{% if supplier.contact %}
<tr>
<td>Contact</td><td>{{ supplier.contact }}</td>
</tr>
{% endif %}
</table>
</div>
</div>
{% block details %}
{% endblock %}
{% endblock %}

View File

@ -36,7 +36,6 @@ class SupplierOrderCreate(CreateView):
return initials
"""
class CompanyIndex(ListView):
model = Company
template_name = 'company/index.html'
@ -44,7 +43,16 @@ class CompanyIndex(ListView):
paginate_by = 50
def get_queryset(self):
return Company.objects.order_by('name')
queryset = Company.objects.all().order_by('name')
if self.request.GET.get('supplier', None):
queryset = queryset.filter(is_supplier=True)
if self.request.GET.get('customer', None):
queryset = queryset.filter(is_customer=True)
return queryset
class CompanyDetail(DetailView):

View File

@ -9,6 +9,7 @@
<li><a href="{% url 'part-index' %}">Parts</a></li>
<li><a href="{% url 'stock-index' %}">Stock</a></li>
<li><a href="{% url 'build-index' %}">Build</a></li>
<li><a href="{% url 'company-index' %}">Companies</a></li>
</ul>
</div>
</nav>