Skip to content

Commit

Permalink
Support updated label printing
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat committed Jul 16, 2023
1 parent ac28e1f commit 5967501
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions inventree/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,29 @@ def printlabel(self, label, plugin=None, destination=None, *args, **kwargs):
# Append profile
params['plugin'] = plugin

# Get response
return self._api.get(URL, params=params)

if destination is not None:
if os.path.exists(destination) and os.path.isdir(destination):
# No file name given, construct one
# Otherwise, filename will be something like '?parts[]=37'
destination = os.path.join(
destination,
f'Label_{self.LABELNAME}{label}_{self.pk}.pdf'
)

# Use downloadFile method to get the file
return self._api.downloadFile(url=f'api/{URL}', destination=destination, params=params, *args, **kwargs)

return False
# If API version less than 130, file download is provided directly
if self._api.api_version < 130:
download_url = f'api/{URL}'
else:
# Perform API request, get response
response = self._api.get(URL, params=params)
download_url = response.get('download_url', None)

# Label file is availble for download
if download_url and destination is not None:
if os.path.exists(destination) and os.path.isdir(destination):
# No file name given, construct one
# Otherwise, filename will be something like '?parts[]=37'
destination = os.path.join(
destination,
f'Label_{self.LABELNAME}{label}_{self.pk}.pdf'
)

# Use downloadFile method to get the file
return self._api.downloadFile(url=f'api/{URL}', destination=destination, params=params, *args, **kwargs)

else:
return response

class LabelLocation(inventree.base.MetadataMixin, inventree.base.InventreeObject):
""" Class representing the Label/Location database model """
Expand Down

0 comments on commit 5967501

Please sign in to comment.