mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Added BuildItemAllocation Model
- Used to link stock items to a build
This commit is contained in:
parent
99b386fb95
commit
989611cae2
@ -22,6 +22,6 @@ class EditBuildForm(HelperForm):
|
|||||||
'quantity',
|
'quantity',
|
||||||
'batch',
|
'batch',
|
||||||
'notes',
|
'notes',
|
||||||
# 'status',
|
'status',
|
||||||
# 'completion_date',
|
# 'completion_date',
|
||||||
]
|
]
|
||||||
|
25
InvenTree/build/migrations/0003_builditemallocation.py
Normal file
25
InvenTree/build/migrations/0003_builditemallocation.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Generated by Django 2.2 on 2019-04-29 12:14
|
||||||
|
|
||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('stock', '0009_auto_20190428_0841'),
|
||||||
|
('build', '0002_auto_20190412_2030'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='BuildItemAllocation',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('quantity', models.PositiveIntegerField(default=1, help_text='Stock quantity to allocate to build', validators=[django.core.validators.MinValueValidator(1)])),
|
||||||
|
('build', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='allocated_stock', to='build.Build')),
|
||||||
|
('stock', models.ForeignKey(help_text='Stock Item to allocate to build', on_delete=django.db.models.deletion.CASCADE, related_name='allocations', to='stock.StockItem')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
18
InvenTree/build/migrations/0004_build_url.py
Normal file
18
InvenTree/build/migrations/0004_build_url.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 2.2 on 2019-04-29 12:18
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('build', '0003_builditemallocation'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='build',
|
||||||
|
name='URL',
|
||||||
|
field=models.URLField(blank=True, help_text='Link to external URL'),
|
||||||
|
),
|
||||||
|
]
|
@ -14,6 +14,17 @@ from django.core.validators import MinValueValidator
|
|||||||
|
|
||||||
class Build(models.Model):
|
class Build(models.Model):
|
||||||
""" A Build object organises the creation of new parts from the component parts.
|
""" A Build object organises the creation of new parts from the component parts.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
part: The part to be built (from component BOM items)
|
||||||
|
title: Brief title describing the build (required)
|
||||||
|
quantity: Number of units to be built
|
||||||
|
status: Build status code
|
||||||
|
batch: Batch code transferred to build parts (optional)
|
||||||
|
creation_date: Date the build was created (auto)
|
||||||
|
completion_date: Date the build was completed
|
||||||
|
URL: External URL for extra information
|
||||||
|
notes: Text notes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
@ -23,16 +34,15 @@ class Build(models.Model):
|
|||||||
related_name='builds',
|
related_name='builds',
|
||||||
limit_choices_to={'buildable': True},
|
limit_choices_to={'buildable': True},
|
||||||
)
|
)
|
||||||
""" A reference to the part being built - only parts marked as 'buildable' may be selected """
|
|
||||||
|
|
||||||
#: Brief title describing the build
|
|
||||||
title = models.CharField(max_length=100, help_text='Brief description of the build')
|
title = models.CharField(max_length=100, help_text='Brief description of the build')
|
||||||
|
|
||||||
#: Number of output parts to build
|
quantity = models.PositiveIntegerField(
|
||||||
quantity = models.PositiveIntegerField(default=1,
|
default=1,
|
||||||
validators=[MinValueValidator(1)],
|
validators=[MinValueValidator(1)],
|
||||||
help_text='Number of parts to build')
|
help_text='Number of parts to build'
|
||||||
|
)
|
||||||
|
|
||||||
# Build status codes
|
# Build status codes
|
||||||
PENDING = 10 # Build is pending / active
|
PENDING = 10 # Build is pending / active
|
||||||
HOLDING = 20 # Build is currently being held
|
HOLDING = 20 # Build is currently being held
|
||||||
@ -46,23 +56,21 @@ class Build(models.Model):
|
|||||||
COMPLETE: _("Complete"),
|
COMPLETE: _("Complete"),
|
||||||
}
|
}
|
||||||
|
|
||||||
#: Status of the build (ref BUILD_STATUS_CODES)
|
|
||||||
status = models.PositiveIntegerField(default=PENDING,
|
status = models.PositiveIntegerField(default=PENDING,
|
||||||
choices=BUILD_STATUS_CODES.items(),
|
choices=BUILD_STATUS_CODES.items(),
|
||||||
validators=[MinValueValidator(0)])
|
validators=[MinValueValidator(0)])
|
||||||
|
|
||||||
#: Batch number for the build (optional)
|
|
||||||
batch = models.CharField(max_length=100, blank=True, null=True,
|
batch = models.CharField(max_length=100, blank=True, null=True,
|
||||||
help_text='Batch code for this build output')
|
help_text='Batch code for this build output')
|
||||||
|
|
||||||
#: Date the build model was 'created'
|
|
||||||
creation_date = models.DateField(auto_now=True, editable=False)
|
creation_date = models.DateField(auto_now=True, editable=False)
|
||||||
|
|
||||||
#: Date the build was 'completed' (and parts removed from stock)
|
|
||||||
completion_date = models.DateField(null=True, blank=True)
|
completion_date = models.DateField(null=True, blank=True)
|
||||||
|
|
||||||
|
URL = models.URLField(blank=True, help_text='Link to external URL')
|
||||||
|
|
||||||
#: Notes attached to each build output
|
|
||||||
notes = models.TextField(blank=True)
|
notes = models.TextField(blank=True)
|
||||||
|
""" Notes attached to each build output """
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def required_parts(self):
|
def required_parts(self):
|
||||||
@ -106,3 +114,35 @@ class Build(models.Model):
|
|||||||
def is_complete(self):
|
def is_complete(self):
|
||||||
""" Returns True if the build status is COMPLETE """
|
""" Returns True if the build status is COMPLETE """
|
||||||
return self.status == self.COMPLETE
|
return self.status == self.COMPLETE
|
||||||
|
|
||||||
|
|
||||||
|
class BuildItemAllocation(models.Model):
|
||||||
|
""" A BuildItemAllocation links multiple StockItem objects to a Build.
|
||||||
|
These are used to allocate part stock to a build.
|
||||||
|
Once the Build is completed, the parts are removed from stock and the
|
||||||
|
BuildItemAllocation objects are removed.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
build: Link to a Build object
|
||||||
|
stock: Link to a StockItem object
|
||||||
|
quantity: Number of units allocated
|
||||||
|
"""
|
||||||
|
|
||||||
|
build = models.ForeignKey(
|
||||||
|
Build,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
related_name='allocated_stock',
|
||||||
|
)
|
||||||
|
|
||||||
|
stock = models.ForeignKey(
|
||||||
|
'stock.StockItem',
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
related_name='allocations',
|
||||||
|
help_text='Stock Item to allocate to build',
|
||||||
|
)
|
||||||
|
|
||||||
|
quantity = models.PositiveIntegerField(
|
||||||
|
default=1,
|
||||||
|
validators=[MinValueValidator(1)],
|
||||||
|
help_text='Stock quantity to allocate to build'
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user