2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 04:25:42 +00:00

Added skeleton for 'build' app

This commit is contained in:
Oliver
2018-04-17 00:32:02 +10:00
parent 86b3092b5e
commit fa23767150
29 changed files with 267 additions and 477 deletions

View File

14
InvenTree/build/admin.py Normal file
View File

@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
from .models import Build
class BuildAdmin(admin.ModelAdmin):
list_display = ('status', )
admin.site.register(Build, BuildAdmin)

8
InvenTree/build/apps.py Normal file
View File

@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class BuildConfig(AppConfig):
name = 'build'

View File

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-04-16 14:03
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('part', '0019_auto_20180416_1249'),
]
operations = [
migrations.CreateModel(
name='Build',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('status', models.PositiveIntegerField(choices=[(b'20', b'Allocated'), (b'30', b'Cancelled'), (b'40', b'Complete'), (b'10', b'Pending')], default=10)),
],
),
migrations.CreateModel(
name='BuildOutput',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('part_name', models.CharField(max_length=255)),
('quantity', models.PositiveIntegerField(default=1, help_text='Number of parts to build', validators=[django.core.validators.MinValueValidator(1)])),
('build', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='outputs', to='build.Build')),
('part', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='builds', to='part.Part')),
],
),
migrations.AlterUniqueTogether(
name='buildoutput',
unique_together=set([('part', 'build')]),
),
]

View File

@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-04-16 14:23
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('build', '0001_initial'),
]
operations = [
migrations.AlterUniqueTogether(
name='buildoutput',
unique_together=set([]),
),
migrations.RemoveField(
model_name='buildoutput',
name='build',
),
migrations.RemoveField(
model_name='buildoutput',
name='part',
),
migrations.AddField(
model_name='build',
name='quantity',
field=models.PositiveIntegerField(default=1, help_text='Number of parts to build', validators=[django.core.validators.MinValueValidator(1)]),
),
migrations.DeleteModel(
name='BuildOutput',
),
]

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-04-16 14:28
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('part', '0019_auto_20180416_1249'),
('build', '0002_auto_20180416_1423'),
]
operations = [
migrations.AddField(
model_name='build',
name='part',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='builds', to='part.Part'),
preserve_default=False,
),
]

View File

39
InvenTree/build/models.py Normal file
View File

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.core.validators import MinValueValidator
from InvenTree.helpers import ChoiceEnum
from part.models import Part
class Build(models.Model):
""" A Build object organises the creation of new parts from the component parts
It uses the part BOM to generate new parts.
Parts are then taken from stock
"""
class BUILD_STATUS(ChoiceEnum):
# The build is 'pending' - no action taken yet
Pending = 10
# The parts required for this build have been allocated
Allocated = 20
# The build has been cancelled (parts unallocated)
Cancelled = 30
# The build is complete!
Complete = 40
# Status of the build
status = models.PositiveIntegerField(default=BUILD_STATUS.Pending.value,
choices=BUILD_STATUS.choices())
part = models.ForeignKey(Part, on_delete=models.CASCADE,
related_name='builds')
quantity = models.PositiveIntegerField(default=1,
validators=[MinValueValidator(1)],
help_text='Number of parts to build')

View File

@ -0,0 +1,3 @@
{% include "base.html" %}
Build detail for Build No. {{ build.id }}.

View File

@ -0,0 +1,7 @@
{% extends "base.html" %}
{% block content %}
<h3>Builds</h3>
{% endblock %}

6
InvenTree/build/tests.py Normal file
View File

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
# from django.test import TestCase
# Create your tests here.

17
InvenTree/build/urls.py Normal file
View File

@ -0,0 +1,17 @@
from django.conf.urls import url, include
from django.views.generic.base import RedirectView
from . import views
build_detail_urls = [
url(r'^.*$', views.BuildDetail.as_view(), name='build-detail'),
]
build_urls = [
# url(r'new/?', views.BuildCreate.as_view(), name='build-create'),
url(r'^(?P<pk>\d+)/', include(build_detail_urls)),
url(r'.*$', views.BuildIndex.as_view(), name='build-index'),
]

22
InvenTree/build/views.py Normal file
View File

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import get_object_or_404
from django.http import HttpResponseRedirect
from django.views.generic import DetailView, ListView
from django.views.generic.edit import UpdateView, DeleteView, CreateView
from .models import Build
class BuildIndex(ListView):
model = Build
template_name = 'build/index.html'
context_object_name = 'builds'
class BuildDetail(DetailView):
model = Build
template_name = 'build/detail.html'
context_object_name = 'build'