Skip to content

Commit

Permalink
Attachments fix (#528)
Browse files Browse the repository at this point in the history
* Bump version

* Fix for viewing and uploading attachment files

- Make sure we use the correct attribute!
  • Loading branch information
SchrodingersGat authored Aug 25, 2024
1 parent 82aace9 commit c52885f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
7 changes: 7 additions & 0 deletions assets/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### 0.16.3 - August 2024
---

- Fixes bug relating to viewing attachment files
- Fixes bug relating to uploading attachment files


### 0.16.2 - August 2024
---

Expand Down
14 changes: 13 additions & 1 deletion lib/inventree/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1001,11 +1001,23 @@ class InvenTreeAttachment extends InvenTreeModel {
String url = URL;

if (InvenTreeAPI().supportsModernAttachments) {
// All attachments are stored in a consolidated table

if (modelType.isEmpty) {
sentryReportMessage("uploadAttachment called with empty 'modelType'");
return false;
}

url = "attachment/";
data["model_id"] = modelId.toString();
data["model_type"] = modelType;

} else {

if (REFERENCE_FIELD.isEmpty) {
sentryReportMessage("uploadAttachment called with empty 'REFERENCE_FIELD'");
return false;
}

data[REFERENCE_FIELD] = modelId.toString();
}

Expand Down
11 changes: 6 additions & 5 deletions lib/widget/attachment_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {

showLoadingOverlay(context);

final bool result = await widget.attachmentClass.uploadAttachment(file, widget.attachmentClass.MODEL_TYPE, widget.modelId);
final bool result = await widget.attachmentClass.uploadAttachment(
file,
widget.attachmentClass.REF_MODEL_TYPE,
widget.modelId
);

hideLoadingOverlay();

Expand Down Expand Up @@ -137,7 +141,7 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
Map<String, String> filters = {};

if (InvenTreeAPI().supportsModernAttachments) {
filters["model_type"] = widget.attachmentClass.MODEL_TYPE;
filters["model_type"] = widget.attachmentClass.REF_MODEL_TYPE;
filters["model_id"] = widget.modelId.toString();
} else {
filters[widget.attachmentClass.REFERENCE_FIELD] = widget.modelId.toString();
Expand All @@ -148,10 +152,7 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
).then((var results) {
attachments.clear();

print("Found ${results.length} results:");

for (var result in results) {
print(result.toString());
if (result is InvenTreeAttachment) {
attachments.add(result);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: inventree
description: InvenTree stock management

version: 0.16.2+88
version: 0.16.3+89

environment:
sdk: ">=2.19.5 <3.13.0"
Expand Down

0 comments on commit c52885f

Please sign in to comment.