Skip to content

Commit 71f075b

Browse files
Fix URL (add trailing slashes)
1 parent 13746b5 commit 71f075b

File tree

12 files changed

+45
-39
lines changed

12 files changed

+45
-39
lines changed

inventree/base.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ class InventreeObject(object):
2020
URL = ""
2121

2222
@classmethod
23-
def get_url(cls, api):
23+
def get_url(cls):
2424
"""Helper method to get the URL associated with this model."""
25-
return cls.URL
25+
26+
url = cls.URL
27+
28+
if not url.endswith('/'):
29+
url += '/'
30+
31+
return url
2632

2733
# Minimum server version for the particular model type
2834
MIN_API_VERSION = None
@@ -90,7 +96,7 @@ def __init__(self, api, pk=None, data=None):
9096
if pk <= 0:
9197
raise ValueError(f"Supplier <pk> value ({pk}) for {self.__class__} must be positive.")
9298

93-
url = self.get_url(api)
99+
url = self.get_url()
94100

95101
self._url = f"{url}/{pk}/"
96102
self._api = api
@@ -134,7 +140,7 @@ def options(cls, api):
134140
cls.checkApiVersion(api)
135141

136142
response = api.request(
137-
cls.URL,
143+
cls.get_url(),
138144
method='OPTIONS',
139145
)
140146

@@ -668,7 +674,7 @@ def _statusupdate(self, status: str, reload=True, data=None, **kwargs):
668674
raise ValueError(f"Order stats {status} not supported.")
669675

670676
# Set the url
671-
URL = self.URL + f"/{self.pk}/{status}"
677+
URL = self.URL + f"/{self.pk}/{status}/"
672678

673679
if data is None:
674680
data = {}

inventree/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Build(
1313
):
1414
""" Class representing the Build database model """
1515

16-
URL = 'build'
16+
URL = 'build/'
1717
MODEL_TYPE = 'build'
1818

1919
def issue(self):

inventree/company.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Address(inventree.base.InventreeObject):
2525
class Company(inventree.base.ImageMixin, inventree.base.MetadataMixin, inventree.base.InventreeObject):
2626
""" Class representing the Company database model """
2727

28-
URL = 'company'
28+
URL = 'company/'
2929
MODEL_TYPE = "company"
3030

3131
def getContacts(self, **kwargs):
@@ -103,7 +103,7 @@ class SupplierPart(inventree.base.BarcodeMixin, inventree.base.BulkDeleteMixin,
103103
- Implements the BulkDeleteMixin
104104
"""
105105

106-
URL = 'company/part'
106+
URL = 'company/part/'
107107

108108
def getPriceBreaks(self):
109109
""" Get a list of price break objects for this SupplierPart """
@@ -122,7 +122,7 @@ class ManufacturerPart(
122122
- Implements the BulkDeleteMixin
123123
"""
124124

125-
URL = 'company/part/manufacturer'
125+
URL = 'company/part/manufacturer/'
126126
MODEL_TYPE = "manufacturerpart"
127127

128128
def getParameters(self, **kwargs):
@@ -139,10 +139,10 @@ class ManufacturerPartParameter(inventree.base.BulkDeleteMixin, inventree.base.I
139139
- Implements the BulkDeleteMixin
140140
"""
141141

142-
URL = 'company/part/manufacturer/parameter'
142+
URL = 'company/part/manufacturer/parameter/'
143143

144144

145145
class SupplierPriceBreak(inventree.base.InventreeObject):
146146
""" Class representing the SupplierPriceBreak database model """
147147

148-
URL = 'company/price-break'
148+
URL = 'company/price-break/'

inventree/label.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def downloadTemplate(self, destination, overwrite=False):
161161
class LabelTemplate(LabelFunctions):
162162
"""Class representing the LabelTemplate database model."""
163163

164-
URL = 'label/template'
164+
URL = 'label/template/'
165165

166166
def __str__(self):
167167
"""String representation of the LabelTemplate instance."""

inventree/part.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class PartCategoryParameterTemplate(inventree.base.InventreeObject):
1717
"""A model which link a ParameterTemplate to a PartCategory"""
1818

19-
URL = 'part/category/parameters'
19+
URL = 'part/category/parameters/'
2020

2121
def getCategory(self):
2222
"""Return the referenced PartCategory instance"""
@@ -30,7 +30,7 @@ def getTemplate(self):
3030
class PartCategory(inventree.base.MetadataMixin, inventree.base.InventreeObject):
3131
""" Class representing the PartCategory database model """
3232

33-
URL = 'part/category'
33+
URL = 'part/category/'
3434

3535
def getParts(self, **kwargs):
3636
return Part.list(self._api, category=self.pk, **kwargs)
@@ -68,7 +68,7 @@ class Part(
6868
):
6969
""" Class representing the Part database model """
7070

71-
URL = 'part'
71+
URL = 'part/'
7272
MODEL_TYPE = 'part'
7373

7474
def getCategory(self):
@@ -149,7 +149,7 @@ def getRequirements(self):
149149
class PartTestTemplate(inventree.base.MetadataMixin, inventree.base.InventreeObject):
150150
""" Class representing a test template for a Part """
151151

152-
URL = 'part/test-template'
152+
URL = 'part/test-template/'
153153

154154
@classmethod
155155
def generateTestKey(cls, test_name):
@@ -183,7 +183,7 @@ class BomItem(
183183
):
184184
""" Class representing the BomItem database model """
185185

186-
URL = 'bom'
186+
URL = 'bom/'
187187

188188

189189
class BomItemSubstitute(
@@ -192,13 +192,13 @@ class BomItemSubstitute(
192192
):
193193
"""Class representing the BomItemSubstitute database model"""
194194

195-
URL = "bom/substitute"
195+
URL = "bom/substitute/"
196196

197197

198198
class InternalPrice(inventree.base.InventreeObject):
199199
""" Class representing the InternalPrice model """
200200

201-
URL = 'part/internal-price'
201+
URL = 'part/internal-price/'
202202

203203
@classmethod
204204
def setInternalPrice(cls, api, part, quantity: int, price: float):
@@ -219,7 +219,7 @@ def setInternalPrice(cls, api, part, quantity: int, price: float):
219219
class SalePrice(inventree.base.InventreeObject):
220220
""" Class representing the SalePrice model """
221221

222-
URL = 'part/sale-price'
222+
URL = 'part/sale-price/'
223223

224224
@classmethod
225225
def setSalePrice(cls, api, part, quantity: int, price: float, price_currency: str):
@@ -241,7 +241,7 @@ def setSalePrice(cls, api, part, quantity: int, price: float, price_currency: st
241241
class PartRelated(inventree.base.InventreeObject):
242242
""" Class representing a relationship between parts"""
243243

244-
URL = 'part/related'
244+
URL = 'part/related/'
245245

246246
@classmethod
247247
def add_related(cls, api, part1, part2):
@@ -266,7 +266,7 @@ def add_related(cls, api, part1, part2):
266266

267267
class Parameter(inventree.base.InventreeObject):
268268
"""class representing the Parameter database model """
269-
URL = 'part/parameter'
269+
URL = 'part/parameter/'
270270

271271
def getunits(self):
272272
""" Get the units for this parameter """
@@ -277,4 +277,4 @@ def getunits(self):
277277
class ParameterTemplate(inventree.base.InventreeObject):
278278
""" class representing the Parameter Template database model"""
279279

280-
URL = 'part/parameter/template'
280+
URL = 'part/parameter/template/'

inventree/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class InvenTreePlugin(inventree.base.MetadataMixin, inventree.base.InventreeObject):
77
"""Represents a PluginConfig instance on the InvenTree server."""
88

9-
URL = 'plugins'
9+
URL = 'plugins/'
1010
MIN_API_VERSION = 197
1111

1212
@classmethod

inventree/purchase_order.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PurchaseOrder(
1717
):
1818
""" Class representing the PurchaseOrder database model """
1919

20-
URL = 'order/po'
20+
URL = 'order/po/'
2121
MODEL_TYPE = 'purchaseorder'
2222

2323
def getSupplier(self):
@@ -143,7 +143,7 @@ class PurchaseOrderLineItem(
143143
):
144144
""" Class representing the PurchaseOrderLineItem database model """
145145

146-
URL = 'order/po-line'
146+
URL = 'order/po-line/'
147147

148148
def getSupplierPart(self):
149149
"""
@@ -247,7 +247,7 @@ class PurchaseOrderExtraLineItem(
247247
):
248248
""" Class representing the PurchaseOrderExtraLineItem database model """
249249

250-
URL = 'order/po-extra-line'
250+
URL = 'order/po-extra-line/'
251251

252252
def getOrder(self):
253253
"""

inventree/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,4 @@ def downloadTemplate(self, destination, overwrite=False):
124124
class ReportTemplate(ReportFunctions):
125125
"""Class representing the ReportTemplate model."""
126126

127-
URL = 'report/template'
127+
URL = 'report/template/'

inventree/return_order.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ReturnOrder(
1818
):
1919
"""Class representing the ReturnOrder database model"""
2020

21-
URL = 'order/ro'
21+
URL = 'order/ro/'
2222
MIN_API_VERSION = 104
2323
MODEL_TYPE = 'returnorder'
2424

inventree/sales_order.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class SalesOrder(
1818
):
1919
""" Class representing the SalesOrder database model """
2020

21-
URL = 'order/so'
21+
URL = 'order/so/'
2222
MODEL_TYPE = 'salesorder'
2323

2424
def getCustomer(self):
@@ -91,7 +91,7 @@ class SalesOrderLineItem(
9191
):
9292
""" Class representing the SalesOrderLineItem database model """
9393

94-
URL = 'order/so-line'
94+
URL = 'order/so-line/'
9595

9696
def getPart(self):
9797
"""
@@ -182,7 +182,7 @@ class SalesOrderExtraLineItem(
182182
):
183183
""" Class representing the SalesOrderExtraLineItem database model """
184184

185-
URL = 'order/so-extra-line'
185+
URL = 'order/so-extra-line/'
186186

187187
def getOrder(self):
188188
"""
@@ -197,7 +197,7 @@ class SalesOrderAllocation(
197197
"""Class representing the SalesOrderAllocation database model."""
198198

199199
MIN_API_VERSION = 267
200-
URL = 'order/so-allocation'
200+
URL = 'order/so-allocation/'
201201

202202
def getOrder(self):
203203
"""Return the SalesOrder to which this SalesOrderAllocation belongs."""
@@ -228,7 +228,7 @@ class SalesOrderShipment(
228228
):
229229
"""Class representing a shipment for a SalesOrder"""
230230

231-
URL = 'order/so/shipment'
231+
URL = 'order/so/shipment/'
232232

233233
def getOrder(self):
234234
"""Return the SalesOrder to which this SalesOrderShipment belongs."""

0 commit comments

Comments
 (0)