mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-30 20:55:42 +00:00 
			
		
		
		
	Merge remote-tracking branch 'inventree/master'
This commit is contained in:
		| @@ -90,7 +90,8 @@ class EditCategoryForm(HelperForm): | |||||||
|         fields = [ |         fields = [ | ||||||
|             'parent', |             'parent', | ||||||
|             'name', |             'name', | ||||||
|             'description' |             'description', | ||||||
|  |             'default_location' | ||||||
|         ] |         ] | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -0,0 +1,20 @@ | |||||||
|  | # Generated by Django 2.2 on 2019-05-04 08:57 | ||||||
|  |  | ||||||
|  | from django.db import migrations, models | ||||||
|  | import django.db.models.deletion | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class Migration(migrations.Migration): | ||||||
|  |  | ||||||
|  |     dependencies = [ | ||||||
|  |         ('stock', '0013_remove_stockitem_uuid'), | ||||||
|  |         ('part', '0014_auto_20190502_2039'), | ||||||
|  |     ] | ||||||
|  |  | ||||||
|  |     operations = [ | ||||||
|  |         migrations.AddField( | ||||||
|  |             model_name='partcategory', | ||||||
|  |             name='default_location', | ||||||
|  |             field=models.ForeignKey(blank=True, help_text='Default location for parts in this category', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='default_categories', to='stock.StockLocation'), | ||||||
|  |         ), | ||||||
|  |     ] | ||||||
| @@ -30,6 +30,13 @@ class PartCategory(InvenTreeTree): | |||||||
|     """ PartCategory provides hierarchical organization of Part objects. |     """ PartCategory provides hierarchical organization of Part objects. | ||||||
|     """ |     """ | ||||||
|  |  | ||||||
|  |     default_location = models.ForeignKey( | ||||||
|  |         'stock.StockLocation', related_name="default_categories", | ||||||
|  |         null=True, blank=True, | ||||||
|  |         on_delete=models.SET_NULL, | ||||||
|  |         help_text='Default location for parts in this category' | ||||||
|  |     ) | ||||||
|  |  | ||||||
|     def get_absolute_url(self): |     def get_absolute_url(self): | ||||||
|         return reverse('category-detail', kwargs={'pk': self.id}) |         return reverse('category-detail', kwargs={'pk': self.id}) | ||||||
|  |  | ||||||
| @@ -141,6 +148,29 @@ class Part(models.Model): | |||||||
|                                          help_text='Where is this item normally stored?', |                                          help_text='Where is this item normally stored?', | ||||||
|                                          related_name='default_parts') |                                          related_name='default_parts') | ||||||
|  |  | ||||||
|  |     def get_default_location(self): | ||||||
|  |         """ Get the default location for a Part (may be None). | ||||||
|  |  | ||||||
|  |         If the Part does not specify a default location, | ||||||
|  |         look at the Category this part is in. | ||||||
|  |         The PartCategory object may also specify a default stock location | ||||||
|  |         """ | ||||||
|  |  | ||||||
|  |         if self.default_location: | ||||||
|  |             return self.default_location | ||||||
|  |         elif self.category: | ||||||
|  |             # Traverse up the category tree until we find a default location | ||||||
|  |             cat = self.category | ||||||
|  |  | ||||||
|  |             while cat: | ||||||
|  |                 if cat.default_location: | ||||||
|  |                     return cat.default_location | ||||||
|  |                 else: | ||||||
|  |                     cat = cat.parent | ||||||
|  |  | ||||||
|  |         # Default case - no default category found | ||||||
|  |         return None | ||||||
|  |  | ||||||
|     # Default supplier part |     # Default supplier part | ||||||
|     default_supplier = models.ForeignKey('part.SupplierPart', |     default_supplier = models.ForeignKey('part.SupplierPart', | ||||||
|                                          on_delete=models.SET_NULL, |                                          on_delete=models.SET_NULL, | ||||||
|   | |||||||
| @@ -8,8 +8,11 @@ | |||||||
|     {% if category %} |     {% if category %} | ||||||
|     <h3>{{ category.name }}</h3> |     <h3>{{ category.name }}</h3> | ||||||
|     <p>{{ category.description }}</p> |     <p>{{ category.description }}</p> | ||||||
|  |     {% if category.default_location %} | ||||||
|  |     <p>Default Location: <a href="{% url 'stock-location-detail' category.default-location.id }%">{{ category.default_location }}</a></p> | ||||||
|  |     {% endif %} | ||||||
|     {% else %} |     {% else %} | ||||||
|     <h3>Parts</h3> |     <h3>Part Categories</h3> | ||||||
|     {% endif %} |     {% endif %} | ||||||
| </div> | </div> | ||||||
| <div class='col-sm-6'> | <div class='col-sm-6'> | ||||||
|   | |||||||
| @@ -211,7 +211,7 @@ class StockItemCreate(AjaxCreateView): | |||||||
|             try: |             try: | ||||||
|                 part = Part.objects.get(pk=part_id) |                 part = Part.objects.get(pk=part_id) | ||||||
|                 initials['part'] = part |                 initials['part'] = part | ||||||
|                 initials['location'] = part.default_location |                 initials['location'] = part.get_default_location() | ||||||
|                 initials['supplier_part'] = part.default_supplier |                 initials['supplier_part'] = part.default_supplier | ||||||
|             except Part.DoesNotExist: |             except Part.DoesNotExist: | ||||||
|                 pass |                 pass | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user