From 62f44d06bfc0557dbedf97178dfbf4687c6aa7e5 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 25 Aug 2022 21:31:23 +1000 Subject: [PATCH] Add missing 'remove stock' action (#3610) (#3611) * Add missing 'remove stock' action * Add some unit tests for the stock item view (cherry picked from commit 993f36c98fc83e542866b13b0c9c003a81008d97) --- .../stock/templates/stock/item_base.html | 1 + InvenTree/stock/test_views.py | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index db9c4417d5..8a1388e636 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -80,6 +80,7 @@
  • {% trans "Count stock" %}
  • {% if not item.customer %}
  • {% trans "Add stock" %}
  • +
  • {% trans "Remove stock" %}
  • {% endif %} {% if item.part.trackable %}
  • {% trans "Serialize stock" %}
  • diff --git a/InvenTree/stock/test_views.py b/InvenTree/stock/test_views.py index f54b188dcd..acf1626136 100644 --- a/InvenTree/stock/test_views.py +++ b/InvenTree/stock/test_views.py @@ -31,6 +31,57 @@ class StockListTest(StockViewTestCase): self.assertEqual(response.status_code, 200) +class StockDetailTest(StockViewTestCase): + """Unit test for the 'stock detail' page""" + + def test_basic_info(self): + """Test that basic stock item info is rendered""" + + url = reverse('stock-item-detail', kwargs={'pk': 1}) + + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + + html = str(response.content) + + # Part name + self.assertIn('Stock Item: M2x4 LPHS', html) + + # Quantity + self.assertIn('
    Available Quantity
    ', html) + self.assertIn('
    4000
    ', html) + + # Batch code + self.assertIn('Batch', html) + self.assertIn('B123', html) + + # Actions to check + actions = [ + "id=\\\'stock-count\\\' title=\\\'Count stock\\\'", + "id=\\\'stock-add\\\' title=\\\'Add stock\\\'", + "id=\\\'stock-remove\\\' title=\\\'Remove stock\\\'", + "id=\\\'stock-move\\\' title=\\\'Transfer stock\\\'", + "id=\\\'stock-duplicate\\\'", + "id=\\\'stock-edit\\\'", + "id=\\\'stock-delete\\\'", + ] + + # Initially we should not have any of the required permissions + for act in actions: + self.assertNotIn(act, html) + + # Give the user all the permissions + self.assignRole('stock.add') + self.assignRole('stock.change') + self.assignRole('stock.delete') + + response = self.client.get(url) + html = str(response.content) + + for act in actions: + self.assertIn(act, html) + + class StockOwnershipTest(StockViewTestCase): """Tests for stock ownership views."""