Pre-fill stockitem expiry date in CreateStockItem form

This commit is contained in:
Oliver Walters 2021-01-04 23:40:51 +11:00
parent 37dcf1c1cf
commit 7d7d5d24cc
2 changed files with 11 additions and 1 deletions

View File

@ -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',

View File

@ -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