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

Merge branch 'master' into customer_orders

This commit is contained in:
James Newlands
2018-04-17 23:06:41 +10:00
24 changed files with 530 additions and 53 deletions

View File

@ -8,7 +8,14 @@ from .models import Build
class BuildAdmin(admin.ModelAdmin):
list_display = ('status', )
list_display = ('part',
'status',
'batch',
'quantity',
'creation_date',
'completion_date',
'title',
'notes',
)
admin.site.register(Build, BuildAdmin)

View File

@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.12 on 2018-04-17 06:57
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('part', '0019_auto_20180416_1249'),
('build', '0003_build_part'),
]
operations = [
migrations.CreateModel(
name='BuildOutput',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('quantity', models.PositiveIntegerField(default=1, help_text='Number of parts to build', validators=[django.core.validators.MinValueValidator(1)])),
],
),
migrations.RemoveField(
model_name='build',
name='part',
),
migrations.RemoveField(
model_name='build',
name='quantity',
),
migrations.AlterField(
model_name='build',
name='status',
field=models.PositiveIntegerField(choices=[(40, 'Cancelled'), (10, 'Pending'), (20, 'Allocated'), (50, 'Complete'), (30, 'Holding')], default=10, validators=[django.core.validators.MinValueValidator(0)]),
),
migrations.AddField(
model_name='buildoutput',
name='build',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='outputs', to='build.Build'),
),
migrations.AddField(
model_name='buildoutput',
name='part',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='builds', to='part.Part'),
),
]

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.12 on 2018-04-17 08:29
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('build', '0004_auto_20180417_0657'),
]
operations = [
migrations.AddField(
model_name='buildoutput',
name='batch',
field=models.CharField(blank=True, help_text='Batch code for this build output', max_length=100),
),
]

View File

@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.12 on 2018-04-17 09:33
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('part', '0022_auto_20180417_0819'),
('build', '0005_buildoutput_batch'),
]
operations = [
migrations.RemoveField(
model_name='buildoutput',
name='build',
),
migrations.RemoveField(
model_name='buildoutput',
name='part',
),
migrations.AddField(
model_name='build',
name='batch',
field=models.CharField(blank=True, help_text='Batch code for this build output', max_length=100, null=True),
),
migrations.AddField(
model_name='build',
name='completion_date',
field=models.DateField(blank=True, null=True),
),
migrations.AddField(
model_name='build',
name='creation_date',
field=models.DateField(auto_now=True),
),
migrations.AddField(
model_name='build',
name='notes',
field=models.CharField(blank=True, max_length=500),
),
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,
),
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.AddField(
model_name='build',
name='title',
field=models.CharField(default='Build title', help_text='Brief description of the build', max_length=100),
preserve_default=False,
),
migrations.DeleteModel(
name='BuildOutput',
),
]

View File

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.12 on 2018-04-17 10:25
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('build', '0006_auto_20180417_0933'),
]
operations = [
migrations.AlterField(
model_name='build',
name='status',
field=models.PositiveIntegerField(choices=[(40, 'Complete'), (10, 'Pending'), (20, 'Holding'), (30, 'Cancelled')], default=10, validators=[django.core.validators.MinValueValidator(0)]),
),
]

View File

@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.utils.translation import ugettext as _
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):
@ -14,26 +14,65 @@ class Build(models.Model):
Parts are then taken from stock
"""
class BUILD_STATUS(ChoiceEnum):
# The build is 'pending' - no action taken yet
Pending = 10
# Build status codes
PENDING = 10 # Build is pending / active
HOLDING = 20 # Build is currently being held
CANCELLED = 30 # Build was cancelled
COMPLETE = 40 # Build is complete
# The parts required for this build have been allocated
Allocated = 20
BUILD_STATUS_CODES = {
PENDING : _("Pending"),
HOLDING : _("Holding"),
CANCELLED : _("Cancelled"),
COMPLETE : _("Complete"),
}
# The build has been cancelled (parts unallocated)
Cancelled = 30
# The build is complete!
Complete = 40
batch = models.CharField(max_length=100, blank=True, null=True,
help_text='Batch code for this build output')
# Status of the build
status = models.PositiveIntegerField(default=BUILD_STATUS.Pending.value,
choices=BUILD_STATUS.choices())
status = models.PositiveIntegerField(default=PENDING,
choices=BUILD_STATUS_CODES.items(),
validators=[MinValueValidator(0)])
# Date the build model was 'created'
creation_date = models.DateField(auto_now=True, editable=False)
# Date the build was 'completed'
completion_date = models.DateField(null=True, blank=True)
# Brief build title
title = models.CharField(max_length=100, help_text='Brief description of the build')
# A reference to the part being built
# Only 'buildable' parts can be selected
part = models.ForeignKey(Part, on_delete=models.CASCADE,
related_name='builds')
related_name='builds',
limit_choices_to={'buildable': True},
)
# How many parts to build?
quantity = models.PositiveIntegerField(default=1,
validators=[MinValueValidator(1)],
help_text='Number of parts to build')
# Notes can be attached to each build output
notes = models.CharField(max_length=500, blank=True)
@property
def is_active(self):
""" Is this build active?
An active build is either:
- Pending
- Holding
"""
return self.status in [
self.PENDING,
self.HOLDING
]
@property
def is_complete(self):
return self.status == self.COMPLETE