mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Pre-fill stockitem expiry date in CreateStockItem form
This commit is contained in:
		| @@ -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', | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user