Add missing 'remove stock' action (#3610)

* Add missing 'remove stock' action

* Add some unit tests for the stock item view
This commit is contained in:
Oliver 2022-08-25 20:07:01 +10:00 committed by GitHub
parent 8fa67b8671
commit 993f36c98f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 0 deletions

View File

@ -80,6 +80,7 @@
<li><a class='dropdown-item' href='#' id='stock-count' title='{% trans "Count stock" %}'><span class='fas fa-check-circle icon-green'></span> {% trans "Count stock" %}</a></li>
{% if not item.customer %}
<li><a class='dropdown-item' href='#' id='stock-add' title='{% trans "Add stock" %}'><span class='fas fa-plus-circle icon-green'></span> {% trans "Add stock" %}</a></li>
<li><a class='dropdown-item' href='#' id='stock-remove' title='{% trans "Remove stock" %}'><span class='fas fa-minus-circle icon-red'></span> {% trans "Remove stock" %}</a></li>
{% endif %}
{% if item.part.trackable %}
<li><a class='dropdown-item' href='#' id='stock-serialize' title='{% trans "Serialize stock" %}'><span class='fas fa-hashtag'></span> {% trans "Serialize stock" %}</a> </li>

View File

@ -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('<h5>Available Quantity</h5>', html)
self.assertIn('<h5>4000 </h5>', html)
# Batch code
self.assertIn('Batch', html)
self.assertIn('<td>B123</td>', 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."""