mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Generate a list of allowed BOM items and pass to the form template
This commit is contained in:
		| @@ -678,6 +678,18 @@ class Part(models.Model): | ||||
|             parts.append(bom.sub_part) | ||||
|         return parts | ||||
|  | ||||
|     def get_allowed_bom_items(self): | ||||
|         """ Return a list of parts which can be added to a BOM for this part. | ||||
|  | ||||
|         - Exclude parts which are not 'component' parts | ||||
|         - Exclude parts which this part is in the BOM for | ||||
|         """ | ||||
|  | ||||
|         parts = Part.objects.filter(component=True) | ||||
|         parts = parts.exclude(id__in=[part.id for part in self.used_in.all()]) | ||||
|  | ||||
|         return parts | ||||
|  | ||||
|     @property | ||||
|     def supplier_count(self): | ||||
|         """ Return the number of supplier parts available for this part """ | ||||
|   | ||||
| @@ -49,6 +49,9 @@ | ||||
|                     {% if item.column.guess == 'Part' %} | ||||
|                     <select class='select' id='id_part_{{ row.index }}' name='part_select_{{ row.index }}'> | ||||
|                         <option value=''>---------</option> | ||||
|                         {% for part in allowed_parts_list %} | ||||
|                         <option value='{{ part.id }}'>{{ part.full_name }} - {{ part.description }}</option> | ||||
|                         {% endfor %} | ||||
|                     </select> | ||||
|                     <br> | ||||
|                     {{ item.cell }} | ||||
|   | ||||
| @@ -654,6 +654,7 @@ class BomUpload(FormView): | ||||
|     bom_columns = [] | ||||
|     bom_rows = [] | ||||
|     missing_columns = [] | ||||
|     allowed_parts = [] | ||||
|  | ||||
|      | ||||
|     def get_success_url(self): | ||||
| @@ -703,9 +704,16 @@ class BomUpload(FormView): | ||||
|         ctx['bom_columns'] = self.bom_columns | ||||
|         ctx['bom_rows'] = rows | ||||
|         ctx['missing_columns'] = self.missing_columns | ||||
|         ctx['allowed_parts_list'] = self.allowed_parts | ||||
|  | ||||
|         return ctx | ||||
|  | ||||
|     def getAllowedParts(self): | ||||
|         """ Return a queryset of parts which are allowed to be added to this BOM. | ||||
|         """ | ||||
|  | ||||
|         return self.part.get_allowed_bom_items() | ||||
|  | ||||
|     def get(self, request, *args, **kwargs): | ||||
|         """ Perform the initial 'GET' request. | ||||
|  | ||||
| @@ -915,6 +923,7 @@ class BomUpload(FormView): | ||||
|         self.request = request | ||||
|  | ||||
|         self.part = get_object_or_404(Part, pk=self.kwargs['pk']) | ||||
|         self.allowed_parts = self.getAllowedParts() | ||||
|         self.form = self.get_form(self.get_form_class()) | ||||
|  | ||||
|         # Did the user POST a file named bom_file? | ||||
|   | ||||
		Reference in New Issue
	
	Block a user