mirror of
https://github.com/inventree/inventree-app.git
synced 2026-11-23 14:16:08 +00:00
Assorted bug fixes (#932)
- Fix broken URLs - Fix incorrect API version check - Remove old debug prints - Additional unit testing
This commit is contained in:
1 parent
ab3114312a
commit
886b80931e
4 files changed
+88
-20
No files matched your search
+3
-3
@@ -331,8 +331,8 @@ class InvenTreeAPI {
|
||||
bool get supportsPartRequirements => apiVersion >= 350;
|
||||
|
||||
// Does the server support the "modern" (consolidated) parameter API?
|
||||
// Ref: https://github.com/inventree/InvenTree/pull/10699
|
||||
bool get supportsModernParameters => apiVersion >= 429;
|
||||
// Ref: https://github.com/inventree/InvenTree/pull/10699 (API v430)
|
||||
bool get supportsModernParameters => apiVersion >= 430;
|
||||
|
||||
// Does the support support the "primary" field on SupplierPart model?
|
||||
bool get supportsSupplierPartPrimaryField => apiVersion >= 456;
|
||||
@@ -2196,7 +2196,7 @@ class InvenTreeAPI {
|
||||
body["location"] = location.toString();
|
||||
}
|
||||
|
||||
post("/api/locate/", body: body, expectedStatusCode: 200).then((
|
||||
post("locate/", body: body, expectedStatusCode: 200).then((
|
||||
APIResponse response,
|
||||
) {
|
||||
if (response.successful()) {
|
||||
|
||||
+11
-8
@@ -215,12 +215,19 @@ class InvenTreePart extends InvenTreeModel {
|
||||
});
|
||||
}
|
||||
|
||||
// API endpoints for this part (relative to the API root)
|
||||
String get serialNumbersUrl => "${URL}${pk}/serial-numbers/";
|
||||
|
||||
String get requirementsUrl => "${URL}${pk}/requirements/";
|
||||
|
||||
String get pricingUrl => InvenTreeAPI().supportsPricingRole
|
||||
? "pricing/part/${pk}/"
|
||||
: "${URL}${pk}/pricing/";
|
||||
|
||||
// Request requirements information for this part
|
||||
Future<InvenTreePartRequirements?> getRequirements() async {
|
||||
try {
|
||||
final response = await InvenTreeAPI().get(
|
||||
"/api/part/${pk}/requirements/",
|
||||
);
|
||||
final response = await InvenTreeAPI().get(requirementsUrl);
|
||||
if (response.isValid()) {
|
||||
final requirementsData = response.data;
|
||||
|
||||
@@ -244,12 +251,8 @@ class InvenTreePart extends InvenTreeModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String url = api.supportsPricingRole
|
||||
? "/api/pricing/part/${pk}/"
|
||||
: "/api/part/${pk}/pricing/";
|
||||
|
||||
try {
|
||||
final response = await api.get(url);
|
||||
final response = await api.get(pricingUrl);
|
||||
if (response.isValid()) {
|
||||
final pricingData = response.data;
|
||||
|
||||
|
||||
@@ -813,7 +813,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
// read the next available serial number
|
||||
showLoadingOverlay();
|
||||
var response = await api.get(
|
||||
"/api/part/${part.pk}/serial-numbers/",
|
||||
part.serialNumbersUrl,
|
||||
expectedStatusCode: null,
|
||||
);
|
||||
hideLoadingOverlay();
|
||||
@@ -822,19 +822,11 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
data["serial_numbers"] =
|
||||
response.data["next"] ?? response.data["latest"];
|
||||
}
|
||||
|
||||
print(
|
||||
"response: " +
|
||||
response.statusCode.toString() +
|
||||
response.data.toString(),
|
||||
);
|
||||
} else {
|
||||
// Cannot set serial numbers for non-trackable parts
|
||||
fields.remove("serial_numbers");
|
||||
}
|
||||
|
||||
print("data: ${data.toString()}");
|
||||
|
||||
InvenTreeStockItem().createForm(
|
||||
context,
|
||||
L10().stockItemCreate,
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Unit tests for part API endpoint URLs and version checks
|
||||
* (regression tests for B14 and B15).
|
||||
*
|
||||
* No server is required.
|
||||
*/
|
||||
|
||||
import "package:flutter_test/flutter_test.dart";
|
||||
|
||||
import "package:inventree/api.dart";
|
||||
import "package:inventree/inventree/part.dart";
|
||||
import "package:inventree/user_profile.dart";
|
||||
|
||||
void main() {
|
||||
final api = InvenTreeAPI();
|
||||
|
||||
tearDown(() {
|
||||
api.serverInfo = {};
|
||||
api.profile = null;
|
||||
});
|
||||
|
||||
// B14: endpoint URLs are relative to the API root (not the host root)
|
||||
group("Part URLs:", () {
|
||||
final part = InvenTreePart.fromJson({"pk": 12});
|
||||
|
||||
test("Relative paths", () {
|
||||
api.serverInfo = {"apiVersion": 568};
|
||||
|
||||
for (final url in [
|
||||
part.serialNumbersUrl,
|
||||
part.requirementsUrl,
|
||||
part.pricingUrl,
|
||||
]) {
|
||||
expect(url.startsWith("/"), isFalse, reason: url);
|
||||
expect(url.contains("api/"), isFalse, reason: url);
|
||||
}
|
||||
|
||||
expect(part.serialNumbersUrl, equals("part/12/serial-numbers/"));
|
||||
expect(part.requirementsUrl, equals("part/12/requirements/"));
|
||||
});
|
||||
|
||||
test("Pricing URL depends on server version", () {
|
||||
api.serverInfo = {"apiVersion": 561};
|
||||
expect(part.pricingUrl, equals("part/12/pricing/"));
|
||||
|
||||
api.serverInfo = {"apiVersion": 562};
|
||||
expect(part.pricingUrl, equals("pricing/part/12/"));
|
||||
});
|
||||
|
||||
test("Resolved against the server API root", () {
|
||||
api.profile = UserProfile(name: "Test", server: "https://example.com");
|
||||
|
||||
expect(
|
||||
api.makeApiUrl(part.serialNumbersUrl),
|
||||
equals("https://example.com/api/part/12/serial-numbers/"),
|
||||
);
|
||||
|
||||
expect(
|
||||
api.makeApiUrl("locate/"),
|
||||
equals("https://example.com/api/locate/"),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// B15: the generic parameter API was added in v430 (not v429)
|
||||
test("Modern parameters version", () {
|
||||
api.serverInfo = {"apiVersion": 429};
|
||||
expect(api.supportsModernParameters, isFalse);
|
||||
|
||||
api.serverInfo = {"apiVersion": 430};
|
||||
expect(api.supportsModernParameters, isTrue);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user