Add database table for storing file attachments against a BuildOrder

This commit is contained in:
Oliver Walters 2020-10-26 15:21:03 +11:00
parent 8f108d42d2
commit 664dd0000c
4 changed files with 72 additions and 28 deletions

View File

@ -0,0 +1,31 @@
# Generated by Django 3.0.7 on 2020-10-26 04:17
import InvenTree.models
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('build', '0021_auto_20201020_0908_squashed_0026_auto_20201023_1228'),
]
operations = [
migrations.CreateModel(
name='BuildOrderAttachment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('attachment', models.FileField(help_text='Select file to attach', upload_to=InvenTree.models.rename_attachment)),
('comment', models.CharField(blank=True, help_text='File comment', max_length=100)),
('upload_date', models.DateField(auto_now_add=True, null=True)),
('build', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='build.Build')),
('user', models.ForeignKey(blank=True, help_text='User', null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
),
]

View File

@ -5,6 +5,7 @@ Build database model definitions
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
from datetime import datetime
from django.contrib.auth.models import User
@ -24,6 +25,7 @@ from mptt.models import MPTTModel, TreeForeignKey
from InvenTree.status_codes import BuildStatus
from InvenTree.helpers import increment, getSetting, normalize
from InvenTree.validators import validate_build_order_reference
from InvenTree.models import InvenTreeAttachment
import InvenTree.fields
@ -648,6 +650,17 @@ class Build(MPTTModel):
return self.status == BuildStatus.COMPLETE
class BuildOrderAttachment(InvenTreeAttachment):
"""
Model for storing file attachments against a BuildOrder object
"""
def getSubdir(self):
return os.path.join('bo_files', str(self.build.id))
build = models.ForeignKey(Build, on_delete=models.CASCADE, related_name='attachments')
class BuildItem(models.Model):
""" A BuildItem links multiple StockItem objects to a Build.
These are used to allocate part stock to a build.

View File

@ -33,16 +33,16 @@ function getAvailableTableFilters(tableKey) {
title: '{% trans "Is Serialized" %}',
},
serial_gte: {
title: "{% trans "Serial number GTE" %}",
description: "{% trans "Serial number greater than or equal to" %}"
title: '{% trans "Serial number GTE" %}',
description: '{% trans "Serial number greater than or equal to" %}'
},
serial_lte: {
title: "{% trans "Serial number LTE" %}",
description: "{% trans "Serial number less than or equal to" %}",
title: '{% trans "Serial number LTE" %}',
description: '{% trans "Serial number less than or equal to" %}',
},
serial: {
title: "{% trans "Serial number" %}",
description: "{% trans "Serial number" %}"
title: '{% trans "Serial number" %}',
description: '{% trans "Serial number" %}'
},
batch: {
title: '{% trans "Batch" %}',
@ -99,16 +99,16 @@ function getAvailableTableFilters(tableKey) {
title: '{% trans "Is Serialized" %}',
},
serial: {
title: "{% trans "Serial number" %}",
description: "{% trans "Serial number" %}"
title: '{% trans "Serial number" %}',
description: '{% trans "Serial number" %}'
},
serial_gte: {
title: "{% trans "Serial number GTE" %}",
description: "{% trans "Serial number greater than or equal to" %}"
title: '{% trans "Serial number GTE" %}',
description: '{% trans "Serial number greater than or equal to" %}'
},
serial_lte: {
title: "{% trans "Serial number LTE" %}",
description: "{% trans "Serial number less than or equal to" %}",
title: '{% trans "Serial number LTE" %}',
description: '{% trans "Serial number less than or equal to" %}',
},
status: {
options: stockCodes,
@ -127,7 +127,7 @@ function getAvailableTableFilters(tableKey) {
return {
result: {
type: 'bool',
title: "{% trans 'Test result' %}",
title: '{% trans "Test result" %}',
},
};
}
@ -137,7 +137,7 @@ function getAvailableTableFilters(tableKey) {
return {
required: {
type: 'bool',
title: "{% trans "Required" %}",
title: '{% trans "Required" %}',
}
};
}