Add "default_expiry" field to Part model

This commit is contained in:
Oliver Walters 2021-01-04 23:36:11 +11:00
parent 692cee113c
commit 37dcf1c1cf
4 changed files with 73 additions and 8 deletions

View File

@ -181,6 +181,7 @@ class EditPartForm(HelperForm):
'keywords': 'fa-key',
'link': 'fa-link',
'IPN': 'fa-hashtag',
'default_expiry': 'fa-stopwatch',
}
bom_copy = forms.BooleanField(required=False,
@ -228,6 +229,7 @@ class EditPartForm(HelperForm):
'link',
'default_location',
'default_supplier',
'default_expiry',
'units',
'minimum_stock',
'trackable',

View File

@ -0,0 +1,36 @@
# Generated by Django 3.0.7 on 2021-01-04 12:31
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('company', '0031_auto_20210103_2215'),
('part', '0060_merge_20201112_1722'),
]
operations = [
migrations.AddField(
model_name='part',
name='default_expiry',
field=models.PositiveIntegerField(default=0, help_text='Expiry time (in days) for stock items of this part', validators=[django.core.validators.MinValueValidator(0)], verbose_name='Default Expiry'),
),
migrations.AlterField(
model_name='part',
name='default_supplier',
field=models.ForeignKey(blank=True, help_text='Default supplier part', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='default_parts', to='company.SupplierPart', verbose_name='Default Supplier'),
),
migrations.AlterField(
model_name='part',
name='minimum_stock',
field=models.PositiveIntegerField(default=0, help_text='Minimum allowed stock level', validators=[django.core.validators.MinValueValidator(0)], verbose_name='Minimum Stock'),
),
migrations.AlterField(
model_name='part',
name='units',
field=models.CharField(blank=True, default='', help_text='Stock keeping units for this part', max_length=20, null=True, verbose_name='Units'),
),
]

View File

@ -291,11 +291,12 @@ class Part(MPTTModel):
keywords: Optional keywords for improving part search results
IPN: Internal part number (optional)
revision: Part revision
is_template: If True, this part is a 'template' part and cannot be instantiated as a StockItem
is_template: If True, this part is a 'template' part
link: Link to an external page with more information about this part (e.g. internal Wiki)
image: Image of this part
default_location: Where the item is normally stored (may be null)
default_supplier: The default SupplierPart which should be used to procure and stock this part
default_expiry: The default expiry duration for any StockItem instances of this part
minimum_stock: Minimum preferred quantity to keep in stock
units: Units of measure for this part (default='pcs')
salable: Can this part be sold to customers?
@ -722,15 +723,34 @@ class Part(MPTTModel):
# Default to None if there are multiple suppliers to choose from
return None
default_supplier = models.ForeignKey(SupplierPart,
on_delete=models.SET_NULL,
blank=True, null=True,
help_text=_('Default supplier part'),
related_name='default_parts')
default_supplier = models.ForeignKey(
SupplierPart,
on_delete=models.SET_NULL,
blank=True, null=True,
verbose_name=_('Default Supplier'),
help_text=_('Default supplier part'),
related_name='default_parts'
)
minimum_stock = models.PositiveIntegerField(default=0, validators=[MinValueValidator(0)], help_text=_('Minimum allowed stock level'))
default_expiry = models.PositiveIntegerField(
default=0,
validators=[MinValueValidator(0)],
verbose_name=_('Default Expiry'),
help_text=_('Expiry time (in days) for stock items of this part'),
)
units = models.CharField(max_length=20, default="", blank=True, null=True, help_text=_('Stock keeping units for this part'))
minimum_stock = models.PositiveIntegerField(
default=0, validators=[MinValueValidator(0)],
verbose_name=_('Minimum Stock'),
help_text=_('Minimum allowed stock level')
)
units = models.CharField(
max_length=20, default="",
blank=True, null=True,
verbose_name=_('Units'),
help_text=_('Stock keeping units for this part')
)
assembly = models.BooleanField(
default=False,

View File

@ -109,6 +109,13 @@
<td>{{ part.minimum_stock }}</td>
</tr>
{% endif %}
{% if part.default_expiry > 0 %}
<tr>
<td><span class='fas fa-stopwatch'></span></td>
<td><b>{% trans "Stock Expiry Time" %}</b></td>
<td>{{ part.default_expiry }} {% trans "days" %}</td>
</tr>
{% endif %}
<tr>
<td><span class='fas fa-calendar-alt'></span></td>
<td><b>{% trans "Creation Date" %}</b></td>