diff --git a/InvenTree/part/fixtures/category.yaml b/InvenTree/part/fixtures/category.yaml index 7587cfdbc4..86675a7fa9 100644 --- a/InvenTree/part/fixtures/category.yaml +++ b/InvenTree/part/fixtures/category.yaml @@ -6,7 +6,7 @@ name: Electronics description: Electronic components parent: null - default_location: null + default_location: 1 # Home - model: part.partcategory pk: 2 fields: @@ -54,3 +54,4 @@ name: Fasteners description: Screws, bolts, etc parent: 7 + default_location: 5 diff --git a/InvenTree/part/fixtures/part.yaml b/InvenTree/part/fixtures/part.yaml index 944f959eb8..dc9b17092a 100644 --- a/InvenTree/part/fixtures/part.yaml +++ b/InvenTree/part/fixtures/part.yaml @@ -23,10 +23,17 @@ name: 'R_4K7_0603' description: '4.7kOhm resistor in 0603 package' category: 2 + default_location: 2 # Home/Bathroom # Create some capacitors - model: part.part fields: name: 'C_22N_0805' description: '22nF capacitor in 0805 package' - category: 3 \ No newline at end of file + category: 3 + +- model: part.part + fields: + name: 'Widget' + description: 'A watchamacallit' + category: 7 \ No newline at end of file diff --git a/InvenTree/part/test_category.py b/InvenTree/part/test_category.py index be6a578b23..f2a88c8eb9 100644 --- a/InvenTree/part/test_category.py +++ b/InvenTree/part/test_category.py @@ -13,6 +13,7 @@ class CategoryTest(TestCase): fixtures = [ 'category', 'part', + 'location', ] def setUp(self): @@ -104,3 +105,25 @@ class CategoryTest(TestCase): for f in fasteners: self.assertEqual(f.category, self.mechanical) + + def test_default_locations(self): + """ Test traversal for default locations """ + + self.assertEqual(str(self.fasteners.default_location), 'Office/Drawer') + + # Test that parts in this location return the same default location, too + for p in self.fasteners.children.all(): + self.assert_equal(p.get_default_location(), 'Office/Drawer') + + # Any part under electronics should default to 'Home' + R1 = Part.objects.get(name='R_2K2_0805') + self.assertIsNone(R1.default_location) + self.assertEqual(R1.get_default_location().name, 'Home') + + # But one part has a default_location set + R2 = Part.objects.get(name='R_4K7_0603') + self.assertEqual(R2.get_default_location().name, 'Bathroom') + + # And one part should have no default location at all + W = Part.objects.get(name='Widget') + self.assertIsNone(W.get_default_location()) \ No newline at end of file diff --git a/InvenTree/stock/fixtures/location.yaml b/InvenTree/stock/fixtures/location.yaml new file mode 100644 index 0000000000..f04b192a7d --- /dev/null +++ b/InvenTree/stock/fixtures/location.yaml @@ -0,0 +1,31 @@ +# Create some locations for stock + +- model: stock.stocklocation + pk: 1 + fields: + name: 'Home' + description: 'My house' +- model: stock.stocklocation + pk: 2 + fields: + name: 'Bathroom' + description: 'Where I keep my bath' + parent: 1 +- model: stock.stocklocation + pk: 3 + fields: + name: 'Dining Room' + description: 'A table lives here' + parent: 1 + +- model: stock.stocklocation + pk: 4 + fields: + name: 'Office' + description: 'Place of work' +- model: stock.stocklocation + pk: 5 + fields: + name: 'Drawer' + description: 'In my desk' + parent: 4 \ No newline at end of file