Add "destination" field to BuildOrder

This commit is contained in:
Oliver Walters 2020-10-20 21:01:51 +11:00
parent 28460b3023
commit ac79e131bc
7 changed files with 54 additions and 9 deletions

View File

@ -322,7 +322,7 @@ class AjaxCreateView(AjaxMixin, CreateView):
"""
pass
def post_save(self, **kwargs):
def post_save(self, new_object, **kwargs):
"""
Hook for doing something with the created object after it is saved
"""
@ -356,7 +356,7 @@ class AjaxCreateView(AjaxMixin, CreateView):
self.pre_save()
self.object = self.form.save()
self.post_save()
self.post_save(self.object)
# Return the PK of the newly-created object
data['pk'] = self.object.pk

View File

@ -35,10 +35,11 @@ class EditBuildForm(HelperForm):
'title',
'part',
'quantity',
'batch',
'take_from',
'destination',
'parent',
'sales_order',
'take_from',
'batch',
'link',
]

View File

@ -0,0 +1,26 @@
# Generated by Django 3.0.7 on 2020-10-20 09:53
from django.db import migrations, models
import django.db.models.deletion
import mptt.fields
class Migration(migrations.Migration):
dependencies = [
('stock', '0052_stockitem_is_building'),
('build', '0021_auto_20201020_0908'),
]
operations = [
migrations.AddField(
model_name='build',
name='destination',
field=models.ForeignKey(blank=True, help_text='Select location where the completed items will be stored', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='incoming_builds', to='stock.StockLocation', verbose_name='Destination Location'),
),
migrations.AlterField(
model_name='build',
name='parent',
field=mptt.fields.TreeForeignKey(blank=True, help_text='BuildOrder to which this build is allocated', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='children', to='build.Build', verbose_name='Parent Build'),
),
]

View File

@ -102,7 +102,7 @@ class Build(MPTTModel):
blank=True, null=True,
related_name='children',
verbose_name=_('Parent Build'),
help_text=_('Parent build to which this build is allocated'),
help_text=_('BuildOrder to which this build is allocated'),
)
part = models.ForeignKey(
@ -137,6 +137,15 @@ class Build(MPTTModel):
help_text=_('Select location to take stock from for this build (leave blank to take from any stock location)')
)
destination = models.ForeignKey(
'stock.StockLocation',
verbose_name=_('Destination Location'),
on_delete=models.SET_NULL,
related_name='incoming_builds',
null=True, blank=True,
help_text=_('Select location where the completed items will be stored'),
)
quantity = models.PositiveIntegerField(
verbose_name=_('Build Quantity'),
default=1,

View File

@ -43,7 +43,7 @@ InvenTree | {% trans "Build Orders" %}
launchModalForm(
"{% url 'build-create' %}",
{
follow: true
follow: true,
}
);
});

View File

@ -412,8 +412,17 @@ class BuildCreate(AjaxCreateView):
initials = super(BuildCreate, self).get_initial().copy()
part = self.request.GET.get('part', None)
if part:
try:
part = Part.objects.get(pk=part)
# User has provided a Part ID
initials['part'] = self.request.GET.get('part', None)
initials['part'] = part
initials['destination'] = part.get_default_location()
except (ValueError, Part.DoesNotExist):
pass
initials['reference'] = Build.getNextBuildNumber()

View File

@ -41,7 +41,7 @@
{% if part.getLatestSerialNumber %}
{{ part.getLatestSerialNumber }}
{% else %}
{% trans "No serial numbers recorded" %}
<i>{% trans "No serial numbers recorded" %}</i>
{% endif %}
</td>
</tr>