2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 03:00:54 +00:00

Annotate models with their API list view

- It will make sense, trust me
This commit is contained in:
Oliver
2021-06-25 00:17:58 +10:00
parent b273dc613b
commit 04374c71c2
12 changed files with 153 additions and 5 deletions

View File

@ -1148,7 +1148,7 @@ stock_api_urls = [
url(r'^$', StockItemTestResultList.as_view(), name='api-stock-test-result-list'),
])),
url(r'track/?', StockTrackingList.as_view(), name='api-stock-track'),
url(r'track/?', StockTrackingList.as_view(), name='api-stock-tracking-list'),
url(r'^tree/?', StockCategoryTree.as_view(), name='api-stock-tree'),

View File

@ -52,6 +52,10 @@ class StockLocation(InvenTreeTree):
Stock locations can be heirarchical as required
"""
@staticmethod
def get_api_url():
return reverse('api-location-list')
owner = models.ForeignKey(Owner, on_delete=models.SET_NULL, blank=True, null=True,
verbose_name=_('Owner'),
help_text=_('Select Owner'),
@ -161,6 +165,10 @@ class StockItem(MPTTModel):
packaging: Description of how the StockItem is packaged (e.g. "reel", "loose", "tape" etc)
"""
@staticmethod
def get_api_url():
return reverse('api-stock-list')
# A Query filter which will be re-used in multiple places to determine if a StockItem is actually "in stock"
IN_STOCK_FILTER = Q(
quantity__gt=0,
@ -1608,6 +1616,10 @@ class StockItemAttachment(InvenTreeAttachment):
Model for storing file attachments against a StockItem object.
"""
@staticmethod
def get_api_url():
return reverse('api-stock-attachment-list')
def getSubdir(self):
return os.path.join("stock_files", str(self.stock_item.id))
@ -1639,6 +1651,10 @@ class StockItemTracking(models.Model):
deltas: The changes associated with this history item
"""
@staticmethod
def get_api_url():
return reverse('api-stock-tracking-list')
def get_absolute_url(self):
return '/stock/track/{pk}'.format(pk=self.id)
@ -1697,6 +1713,10 @@ class StockItemTestResult(models.Model):
date: Date the test result was recorded
"""
@staticmethod
def get_api_url():
return reverse('api-stock-test-result-list')
def save(self, *args, **kwargs):
super().clean()

View File

@ -57,7 +57,7 @@
item: {{ item.pk }},
user_detail: true,
},
url: "{% url 'api-stock-track' %}",
url: "{% url 'api-stock-tracking-list' %}",
});
{% endblock %}