mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Function to construct part form fields
This commit is contained in:
		| @@ -23,6 +23,7 @@ from djmoney.money import Money | ||||
| from djmoney.contrib.exchange.models import convert_money | ||||
| from djmoney.contrib.exchange.exceptions import MissingRate | ||||
|  | ||||
| from decimal import Decimal | ||||
|  | ||||
| from .models import Part, PartCategory, BomItem | ||||
| from .models import PartParameter, PartParameterTemplate | ||||
| @@ -30,6 +31,7 @@ from .models import PartAttachment, PartTestTemplate | ||||
| from .models import PartSellPriceBreak, PartInternalPriceBreak | ||||
| from .models import PartCategoryParameterTemplate | ||||
|  | ||||
| from stock.models import StockItem | ||||
| from common.models import InvenTreeSetting | ||||
| from build.models import Build | ||||
|  | ||||
|   | ||||
| @@ -564,7 +564,7 @@ function submitFormData(fields, options) { | ||||
|     var has_files = false; | ||||
|  | ||||
|     // Extract values for each field | ||||
|     for (var idx = 0; idx < options.fields_names.length; idx++) { | ||||
|     for (var idx = 0; idx < options.field_names.length; idx++) { | ||||
|  | ||||
|         var name = options.field_names[idx]; | ||||
|  | ||||
|   | ||||
| @@ -13,6 +13,116 @@ function yesNoLabel(value) { | ||||
|     } | ||||
| } | ||||
|  | ||||
| // Construct fieldset for part forms | ||||
| function partFields(options={}) { | ||||
|  | ||||
|     var fields = { | ||||
|         category: {}, | ||||
|         name: {}, | ||||
|         IPN: {}, | ||||
|         revision: {}, | ||||
|         description: {}, | ||||
|         variant_of: {}, | ||||
|         keywords: { | ||||
|             icon: 'fa-key', | ||||
|         }, | ||||
|         units: {}, | ||||
|         link: { | ||||
|             icon: 'fa-link', | ||||
|         }, | ||||
|         default_location: {}, | ||||
|         default_supplier: {}, | ||||
|         default_expiry: { | ||||
|             icon: 'fa-calendar-alt', | ||||
|         }, | ||||
|         minimum_stock: { | ||||
|             icon: 'fa-boxes', | ||||
|         }, | ||||
|         attributes: { | ||||
|             type: 'candy', | ||||
|             html: `<hr><h4><i>{% trans "Part Attributes" %}</i></h4><hr>` | ||||
|         }, | ||||
|         component: { | ||||
|             value: global_settings.PART_COMPONENT, | ||||
|         }, | ||||
|         assembly: { | ||||
|             value: global_settings.PART_ASSEMBLY, | ||||
|         }, | ||||
|         is_template: { | ||||
|             value: global_settings.PART_TEMPLATE, | ||||
|         }, | ||||
|         trackable: { | ||||
|             value: global_settings.PART_TRACKABLE, | ||||
|         }, | ||||
|         purchaseable: { | ||||
|             value: global_settings.PART_PURCHASEABLE, | ||||
|         }, | ||||
|         salable: { | ||||
|             value: global_settings.PART_SALABLE, | ||||
|         }, | ||||
|         virtual: { | ||||
|             value: global_settings.PART_VIRTUAL, | ||||
|         }, | ||||
|     }; | ||||
|  | ||||
|     // Pop expiry field | ||||
|     if (!global_settings.STOCK_ENABLE_EXPIRY) { | ||||
|         delete fields["default_expiry"]; | ||||
|     } | ||||
|  | ||||
|     // Additional fields when "creating" a new part | ||||
|     if (options.create) { | ||||
|  | ||||
|         // No supplier parts available yet | ||||
|         delete fields["default_supplier"]; | ||||
|  | ||||
|         fields.create = { | ||||
|             type: 'candy', | ||||
|             html: `<hr><h4><i>{% trans "Part Creation Options" %}</i></h4><hr>`, | ||||
|         }; | ||||
|  | ||||
|         if (global_settings.PART_CREATE_INITIAL) { | ||||
|             fields.initial_stock = { | ||||
|                 type: 'decimal', | ||||
|                 label: '{% trans "Initial Stock Quantity" %}', | ||||
|                 help_text: '{% trans "Initialize part stock with specified quantity" %}', | ||||
|             }; | ||||
|         } | ||||
|  | ||||
|         fields.copy_category_parameters = { | ||||
|             type: 'boolean', | ||||
|             label: '{% trans "Copy Category Parameters" %}', | ||||
|             help_text: '{% trans "Copy parameter templates from selected part category" %}', | ||||
|             value: global_settings.PART_CATEGORY_PARAMETERS, | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     // Additional fields when "duplicating" a part | ||||
|     if (options.duplicate) { | ||||
|  | ||||
|         fields.duplicate = { | ||||
|             type: 'candy', | ||||
|             html: `<hr><h4><i>{% trans "Part Duplication Options" %}</i></h4><hr>`, | ||||
|         }; | ||||
|  | ||||
|         fields.copy_bom = { | ||||
|             type: 'boolean', | ||||
|             label: '{% trans "Copy BOM" %}', | ||||
|             help_text: '{% trans "Copy bill of materials from original part" %}', | ||||
|             value: global_settings.PART_COPY_BOM, | ||||
|         }; | ||||
|  | ||||
|         fields.copy_parameters = { | ||||
|             type: 'boolean', | ||||
|             label: '{% trans "Copy Parameters" %}', | ||||
|             help_text: '{% trans "Copy parameter data from original part" %}', | ||||
|             value: global_settings.PART_COPY_PARAMETERS, | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     return fields; | ||||
| } | ||||
|  | ||||
|  | ||||
| function categoryFields() { | ||||
|     return { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user