mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-30 20:55:42 +00:00 
			
		
		
		
	Merge pull request #1932 from SchrodingersGat/supplier-part-bug-fix
Supplier part bug fix
This commit is contained in:
		| @@ -9,6 +9,8 @@ import os | |||||||
|  |  | ||||||
| from django.utils.translation import ugettext_lazy as _ | from django.utils.translation import ugettext_lazy as _ | ||||||
| from django.core.validators import MinValueValidator | from django.core.validators import MinValueValidator | ||||||
|  | from django.core.exceptions import ValidationError | ||||||
|  |  | ||||||
| from django.db import models | from django.db import models | ||||||
| from django.db.models import Sum, Q, UniqueConstraint | from django.db.models import Sum, Q, UniqueConstraint | ||||||
|  |  | ||||||
| @@ -473,12 +475,32 @@ class SupplierPart(models.Model): | |||||||
|     def get_absolute_url(self): |     def get_absolute_url(self): | ||||||
|         return reverse('supplier-part-detail', kwargs={'pk': self.id}) |         return reverse('supplier-part-detail', kwargs={'pk': self.id}) | ||||||
|  |  | ||||||
|  |     def api_instance_filters(self): | ||||||
|  |          | ||||||
|  |         return { | ||||||
|  |             'manufacturer_part': { | ||||||
|  |                 'part': self.part.pk | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|     class Meta: |     class Meta: | ||||||
|         unique_together = ('part', 'supplier', 'SKU') |         unique_together = ('part', 'supplier', 'SKU') | ||||||
|  |  | ||||||
|         # This model was moved from the 'Part' app |         # This model was moved from the 'Part' app | ||||||
|         db_table = 'part_supplierpart' |         db_table = 'part_supplierpart' | ||||||
|  |  | ||||||
|  |     def clean(self): | ||||||
|  |  | ||||||
|  |         super().clean() | ||||||
|  |  | ||||||
|  |         # Ensure that the linked manufacturer_part points to the same part! | ||||||
|  |         if self.manufacturer_part and self.part: | ||||||
|  |  | ||||||
|  |             if not self.manufacturer_part.part == self.part: | ||||||
|  |                 raise ValidationError({ | ||||||
|  |                     'manufacturer_part': _("Linked manufacturer part must reference the same base part"), | ||||||
|  |                 }) | ||||||
|  |  | ||||||
|     part = models.ForeignKey('part.Part', on_delete=models.CASCADE, |     part = models.ForeignKey('part.Part', on_delete=models.CASCADE, | ||||||
|                              related_name='supplier_parts', |                              related_name='supplier_parts', | ||||||
|                              verbose_name=_('Base Part'), |                              verbose_name=_('Base Part'), | ||||||
|   | |||||||
| @@ -54,8 +54,12 @@ function editManufacturerPart(part, options={}) { | |||||||
|  |  | ||||||
|     var url = `/api/company/part/manufacturer/${part}/`; |     var url = `/api/company/part/manufacturer/${part}/`; | ||||||
|  |  | ||||||
|  |     var fields = manufacturerPartFields(); | ||||||
|  |  | ||||||
|  |     fields.part.hidden = true; | ||||||
|  |  | ||||||
|     constructForm(url, { |     constructForm(url, { | ||||||
|         fields: manufacturerPartFields(), |         fields: fields, | ||||||
|         title: '{% trans "Edit Manufacturer Part" %}', |         title: '{% trans "Edit Manufacturer Part" %}', | ||||||
|         onSuccess: options.onSuccess |         onSuccess: options.onSuccess | ||||||
|     }); |     }); | ||||||
| @@ -157,8 +161,13 @@ function createSupplierPart(options={}) { | |||||||
|  |  | ||||||
| function editSupplierPart(part, options={}) { | function editSupplierPart(part, options={}) { | ||||||
|  |  | ||||||
|  |     var fields = supplierPartFields(); | ||||||
|  |  | ||||||
|  |     // Hide the "part" field | ||||||
|  |     fields.part.hidden = true; | ||||||
|  |  | ||||||
|     constructForm(`/api/company/part/${part}/`, { |     constructForm(`/api/company/part/${part}/`, { | ||||||
|         fields: supplierPartFields(), |         fields: fields, | ||||||
|         title: '{% trans "Edit Supplier Part" %}', |         title: '{% trans "Edit Supplier Part" %}', | ||||||
|         onSuccess: options.onSuccess |         onSuccess: options.onSuccess | ||||||
|     }); |     }); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user