diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index 4ed7f73f49..5583411009 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -109,6 +109,10 @@ class ConvertStockItemForm(HelperForm): class CreateStockItemForm(HelperForm): """ Form for creating a new StockItem """ + expiry_date = DatePickerFormField( + help_text=('Expiration date for this stock item'), + ) + serial_numbers = forms.CharField(label=_('Serial numbers'), required=False, help_text=_('Enter unique serial numbers (or leave blank)')) def __init__(self, *args, **kwargs): @@ -130,6 +134,7 @@ class CreateStockItemForm(HelperForm): 'batch', 'serial_numbers', 'purchase_price', + 'expiry_date', 'link', 'delete_on_deplete', 'status', diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 582c1b5d89..963d357e31 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -26,7 +26,7 @@ from InvenTree.helpers import str2bool, DownloadFile, GetExportFormats from InvenTree.helpers import extract_serial_numbers from decimal import Decimal, InvalidOperation -from datetime import datetime +from datetime import datetime, timedelta from company.models import Company, SupplierPart from part.models import Part @@ -1596,6 +1596,11 @@ class StockItemCreate(AjaxCreateView): initials['location'] = part.get_default_location() initials['supplier_part'] = part.default_supplier + # If the part has a defined expiry period, extrapolate! + if part.default_expiry > 0: + expiry_date = datetime.now().date() + timedelta(days=part.default_expiry) + initials['expiry_date'] = expiry_date + currency_code = common.settings.currency_code_default() # SupplierPart field has been specified