mirror of
https://github.com/inventree/inventree-app.git
synced 2025-07-01 03:10:46 +00:00
Format Code and Add Format Checks to CI (#643)
* Remove unused lib/generated/i18n.dart * Use `fvm dart format .` * Add contributing guidelines * Enforce dart format * Add `dart format off` directive to generated files
This commit is contained in:
1
.github/workflows/ci.yaml
vendored
1
.github/workflows/ci.yaml
vendored
@ -60,6 +60,7 @@ jobs:
|
|||||||
python3 find_dart_files.py
|
python3 find_dart_files.py
|
||||||
flutter pub get
|
flutter pub get
|
||||||
flutter analyze
|
flutter analyze
|
||||||
|
dart format --output=none --set-exit-if-changed .
|
||||||
|
|
||||||
- name: Install Python
|
- name: Install Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v4
|
||||||
|
50
CONTRIBUTING.md
Normal file
50
CONTRIBUTING.md
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# Contributing to InvenTree App
|
||||||
|
|
||||||
|
Thank you for considering contributing to the InvenTree App! This document outlines some guidelines to ensure smooth collaboration.
|
||||||
|
|
||||||
|
## Code Style and Formatting
|
||||||
|
|
||||||
|
### Dart Formatting
|
||||||
|
|
||||||
|
We enforce consistent code formatting using Dart's built-in formatter. Before submitting a pull request:
|
||||||
|
|
||||||
|
1. Run the formatter on your code:
|
||||||
|
```bash
|
||||||
|
fvm dart format .
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Our CI pipeline will verify that all code follows the standard Flutter/Dart formatting rules. Pull requests with improper formatting will fail CI checks.
|
||||||
|
|
||||||
|
### General Guidelines
|
||||||
|
|
||||||
|
- Write clear, readable, and maintainable code
|
||||||
|
- Include comments where necessary
|
||||||
|
- Follow Flutter/Dart best practices
|
||||||
|
- Write tests for new features when applicable
|
||||||
|
|
||||||
|
## Pull Request Process
|
||||||
|
|
||||||
|
1. Fork the repository and create a feature branch
|
||||||
|
2. Make your changes
|
||||||
|
3. Ensure your code passes all tests and linting
|
||||||
|
4. Format your code using `fvm dart format`
|
||||||
|
5. Submit a pull request with a clear description of the changes
|
||||||
|
6. Address any review comments
|
||||||
|
|
||||||
|
## Development Setup
|
||||||
|
|
||||||
|
1. Ensure you have Flutter installed (we use Flutter Version Management)
|
||||||
|
2. Check the required Flutter version in the `.fvmrc` file
|
||||||
|
3. Install dependencies with `fvm flutter pub get`
|
||||||
|
4. Run tests with `fvm flutter test`
|
||||||
|
|
||||||
|
## Reporting Issues
|
||||||
|
|
||||||
|
When reporting issues, please include:
|
||||||
|
- Clear steps to reproduce the issue
|
||||||
|
- Expected behavior
|
||||||
|
- Actual behavior
|
||||||
|
- Screenshots if applicable
|
||||||
|
- Device/environment information
|
||||||
|
|
||||||
|
Thank you for contributing to the InvenTree App!
|
@ -15,6 +15,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
with open("test/coverage_helper_test.dart", "w") as f:
|
with open("test/coverage_helper_test.dart", "w") as f:
|
||||||
f.write("// ignore_for_file: unused_import\n\n")
|
f.write("// ignore_for_file: unused_import\n\n")
|
||||||
|
f.write("// dart format off\n\n")
|
||||||
|
|
||||||
skips = [
|
skips = [
|
||||||
"generated",
|
"generated",
|
||||||
|
378
lib/api.dart
378
lib/api.dart
@ -27,13 +27,17 @@ import "package:inventree/user_profile.dart";
|
|||||||
import "package:inventree/widget/dialogs.dart";
|
import "package:inventree/widget/dialogs.dart";
|
||||||
import "package:inventree/widget/snacks.dart";
|
import "package:inventree/widget/snacks.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing an API response from the server
|
* Class representing an API response from the server
|
||||||
*/
|
*/
|
||||||
class APIResponse {
|
class APIResponse {
|
||||||
|
APIResponse({
|
||||||
APIResponse({this.url = "", this.method = "", this.statusCode = -1, this.error = "", this.data = const {}});
|
this.url = "",
|
||||||
|
this.method = "",
|
||||||
|
this.statusCode = -1,
|
||||||
|
this.error = "",
|
||||||
|
this.data = const {},
|
||||||
|
});
|
||||||
|
|
||||||
int statusCode = -1;
|
int statusCode = -1;
|
||||||
|
|
||||||
@ -88,7 +92,6 @@ class APIResponse {
|
|||||||
* Handles case where the response is paginated, or a complete set of results
|
* Handles case where the response is paginated, or a complete set of results
|
||||||
*/
|
*/
|
||||||
List<dynamic> resultsList() {
|
List<dynamic> resultsList() {
|
||||||
|
|
||||||
if (isList()) {
|
if (isList()) {
|
||||||
return asList();
|
return asList();
|
||||||
} else if (isMap()) {
|
} else if (isMap()) {
|
||||||
@ -104,14 +107,12 @@ class APIResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Custom FileService for caching network images
|
* Custom FileService for caching network images
|
||||||
* Requires a custom badCertificateCallback,
|
* Requires a custom badCertificateCallback,
|
||||||
* so we can accept "dodgy" (e.g. self-signed) certificates
|
* so we can accept "dodgy" (e.g. self-signed) certificates
|
||||||
*/
|
*/
|
||||||
class InvenTreeFileService extends FileService {
|
class InvenTreeFileService extends FileService {
|
||||||
|
|
||||||
InvenTreeFileService({HttpClient? client, bool strictHttps = false}) {
|
InvenTreeFileService({HttpClient? client, bool strictHttps = false}) {
|
||||||
_client = client ?? HttpClient();
|
_client = client ?? HttpClient();
|
||||||
|
|
||||||
@ -126,8 +127,10 @@ class InvenTreeFileService extends FileService {
|
|||||||
HttpClient? _client;
|
HttpClient? _client;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<FileServiceResponse> get(String url,
|
Future<FileServiceResponse> get(
|
||||||
{Map<String, String>? headers}) async {
|
String url, {
|
||||||
|
Map<String, String>? headers,
|
||||||
|
}) async {
|
||||||
final Uri resolved = Uri.base.resolve(url);
|
final Uri resolved = Uri.base.resolve(url);
|
||||||
|
|
||||||
final HttpClientRequest req = await _client!.getUrl(resolved);
|
final HttpClientRequest req = await _client!.getUrl(resolved);
|
||||||
@ -141,8 +144,11 @@ class InvenTreeFileService extends FileService {
|
|||||||
final HttpClientResponse httpResponse = await req.close();
|
final HttpClientResponse httpResponse = await req.close();
|
||||||
|
|
||||||
final http.StreamedResponse _response = http.StreamedResponse(
|
final http.StreamedResponse _response = http.StreamedResponse(
|
||||||
httpResponse.timeout(Duration(seconds: 60)), httpResponse.statusCode,
|
httpResponse.timeout(Duration(seconds: 60)),
|
||||||
contentLength: httpResponse.contentLength < 0 ? 0 : httpResponse.contentLength,
|
httpResponse.statusCode,
|
||||||
|
contentLength: httpResponse.contentLength < 0
|
||||||
|
? 0
|
||||||
|
: httpResponse.contentLength,
|
||||||
reasonPhrase: httpResponse.reasonPhrase,
|
reasonPhrase: httpResponse.reasonPhrase,
|
||||||
isRedirect: httpResponse.isRedirect,
|
isRedirect: httpResponse.isRedirect,
|
||||||
);
|
);
|
||||||
@ -158,12 +164,10 @@ class InvenTreeFileService extends FileService {
|
|||||||
* initialised using a username:password combination.
|
* initialised using a username:password combination.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* API class which manages all communication with the InvenTree server
|
* API class which manages all communication with the InvenTree server
|
||||||
*/
|
*/
|
||||||
class InvenTreeAPI {
|
class InvenTreeAPI {
|
||||||
|
|
||||||
factory InvenTreeAPI() {
|
factory InvenTreeAPI() {
|
||||||
return _api;
|
return _api;
|
||||||
}
|
}
|
||||||
@ -209,7 +213,6 @@ class InvenTreeAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _makeUrl(String url) {
|
String _makeUrl(String url) {
|
||||||
|
|
||||||
// Strip leading slash
|
// Strip leading slash
|
||||||
if (url.startsWith("/")) {
|
if (url.startsWith("/")) {
|
||||||
url = url.substring(1, url.length);
|
url = url.substring(1, url.length);
|
||||||
@ -257,14 +260,12 @@ class InvenTreeAPI {
|
|||||||
* Useful as a precursor check before performing operations.
|
* Useful as a precursor check before performing operations.
|
||||||
*/
|
*/
|
||||||
bool checkConnection() {
|
bool checkConnection() {
|
||||||
|
|
||||||
// Is the server connected?
|
// Is the server connected?
|
||||||
if (!isConnected()) {
|
if (!isConnected()) {
|
||||||
|
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
L10().notConnected,
|
L10().notConnected,
|
||||||
success: false,
|
success: false,
|
||||||
icon: TablerIcons.server
|
icon: TablerIcons.server,
|
||||||
);
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -388,7 +389,6 @@ class InvenTreeAPI {
|
|||||||
return !isConnected() && _connecting;
|
return !isConnected() && _connecting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform the required login steps, in sequence.
|
* Perform the required login steps, in sequence.
|
||||||
* Internal function, called by connectToServer()
|
* Internal function, called by connectToServer()
|
||||||
@ -403,7 +403,6 @@ class InvenTreeAPI {
|
|||||||
* 5. Request information on available plugins
|
* 5. Request information on available plugins
|
||||||
*/
|
*/
|
||||||
Future<bool> _connectToServer() async {
|
Future<bool> _connectToServer() async {
|
||||||
|
|
||||||
if (!await _checkServer()) {
|
if (!await _checkServer()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -413,7 +412,11 @@ class InvenTreeAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!await _checkAuth()) {
|
if (!await _checkAuth()) {
|
||||||
showServerError(_URL_ME, L10().serverNotConnected, L10().serverAuthenticationError);
|
showServerError(
|
||||||
|
_URL_ME,
|
||||||
|
L10().serverNotConnected,
|
||||||
|
L10().serverAuthenticationError,
|
||||||
|
);
|
||||||
|
|
||||||
// Invalidate the token
|
// Invalidate the token
|
||||||
if (profile != null) {
|
if (profile != null) {
|
||||||
@ -436,20 +439,18 @@ class InvenTreeAPI {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check that the remote server is available.
|
* Check that the remote server is available.
|
||||||
* Ping the api/ endpoint, which does not require user authentication
|
* Ping the api/ endpoint, which does not require user authentication
|
||||||
*/
|
*/
|
||||||
Future<bool> _checkServer() async {
|
Future<bool> _checkServer() async {
|
||||||
|
|
||||||
String address = profile?.server ?? "";
|
String address = profile?.server ?? "";
|
||||||
|
|
||||||
if (address.isEmpty) {
|
if (address.isEmpty) {
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
L10().incompleteDetails,
|
L10().incompleteDetails,
|
||||||
icon: TablerIcons.exclamation_circle,
|
icon: TablerIcons.exclamation_circle,
|
||||||
success: false
|
success: false,
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -459,7 +460,9 @@ class InvenTreeAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cache the "strictHttps" setting, so we can use it later without async requirement
|
// Cache the "strictHttps" setting, so we can use it later without async requirement
|
||||||
_strictHttps = await InvenTreeSettingsManager().getValue(INV_STRICT_HTTPS, false) as bool;
|
_strictHttps =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_STRICT_HTTPS, false)
|
||||||
|
as bool;
|
||||||
|
|
||||||
debug("Connecting to ${apiUrl}");
|
debug("Connecting to ${apiUrl}");
|
||||||
|
|
||||||
@ -467,7 +470,11 @@ class InvenTreeAPI {
|
|||||||
|
|
||||||
if (!response.successful()) {
|
if (!response.successful()) {
|
||||||
debug("Server returned invalid response: ${response.statusCode}");
|
debug("Server returned invalid response: ${response.statusCode}");
|
||||||
showStatusCodeError(apiUrl, response.statusCode, details: response.data.toString());
|
showStatusCodeError(
|
||||||
|
apiUrl,
|
||||||
|
response.statusCode,
|
||||||
|
details: response.data.toString(),
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,17 +483,12 @@ class InvenTreeAPI {
|
|||||||
serverInfo = {..._data};
|
serverInfo = {..._data};
|
||||||
|
|
||||||
if (serverVersion.isEmpty) {
|
if (serverVersion.isEmpty) {
|
||||||
showServerError(
|
showServerError(apiUrl, L10().missingData, L10().serverMissingData);
|
||||||
apiUrl,
|
|
||||||
L10().missingData,
|
|
||||||
L10().serverMissingData,
|
|
||||||
);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiVersion < _minApiVersion) {
|
if (apiVersion < _minApiVersion) {
|
||||||
|
|
||||||
String message = L10().serverApiVersion + ": ${apiVersion}";
|
String message = L10().serverApiVersion + ": ${apiVersion}";
|
||||||
|
|
||||||
message += "\n";
|
message += "\n";
|
||||||
@ -496,11 +498,7 @@ class InvenTreeAPI {
|
|||||||
|
|
||||||
message += "Ensure your InvenTree server version is up to date!";
|
message += "Ensure your InvenTree server version is up to date!";
|
||||||
|
|
||||||
showServerError(
|
showServerError(apiUrl, L10().serverOld, message);
|
||||||
apiUrl,
|
|
||||||
L10().serverOld,
|
|
||||||
message,
|
|
||||||
);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -509,7 +507,6 @@ class InvenTreeAPI {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check that the user is authenticated
|
* Check that the user is authenticated
|
||||||
* Fetch the user information
|
* Fetch the user information
|
||||||
@ -525,7 +522,9 @@ class InvenTreeAPI {
|
|||||||
userInfo = response.asMap();
|
userInfo = response.asMap();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
debug("Auth request failed: Server returned status ${response.statusCode}");
|
debug(
|
||||||
|
"Auth request failed: Server returned status ${response.statusCode}",
|
||||||
|
);
|
||||||
if (response.data != null) {
|
if (response.data != null) {
|
||||||
debug("Server response: ${response.data.toString()}");
|
debug("Server response: ${response.data.toString()}");
|
||||||
}
|
}
|
||||||
@ -538,8 +537,11 @@ class InvenTreeAPI {
|
|||||||
* Fetch a token from the server,
|
* Fetch a token from the server,
|
||||||
* with a temporary authentication header
|
* with a temporary authentication header
|
||||||
*/
|
*/
|
||||||
Future<APIResponse> fetchToken(UserProfile userProfile, String username, String password) async {
|
Future<APIResponse> fetchToken(
|
||||||
|
UserProfile userProfile,
|
||||||
|
String username,
|
||||||
|
String password,
|
||||||
|
) async {
|
||||||
debug("Fetching user token from ${userProfile.server}");
|
debug("Fetching user token from ${userProfile.server}");
|
||||||
|
|
||||||
profile = userProfile;
|
profile = userProfile;
|
||||||
@ -574,13 +576,14 @@ class InvenTreeAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Construct auth header from username and password
|
// Construct auth header from username and password
|
||||||
String authHeader = "Basic " + base64Encode(utf8.encode("${username}:${password}"));
|
String authHeader =
|
||||||
|
"Basic " + base64Encode(utf8.encode("${username}:${password}"));
|
||||||
|
|
||||||
// Perform request to get a token
|
// Perform request to get a token
|
||||||
final response = await get(
|
final response = await get(
|
||||||
_URL_TOKEN,
|
_URL_TOKEN,
|
||||||
params: {"name": platform_name},
|
params: {"name": platform_name},
|
||||||
headers: { HttpHeaders.authorizationHeader: authHeader}
|
headers: {HttpHeaders.authorizationHeader: authHeader},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Invalid response
|
// Invalid response
|
||||||
@ -641,11 +644,9 @@ class InvenTreeAPI {
|
|||||||
_connectionStatusChanged();
|
_connectionStatusChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Public facing connection function.
|
/* Public facing connection function.
|
||||||
*/
|
*/
|
||||||
Future<bool> connectToServer(UserProfile prf) async {
|
Future<bool> connectToServer(UserProfile prf) async {
|
||||||
|
|
||||||
// Ensure server is first disconnected
|
// Ensure server is first disconnected
|
||||||
disconnectFromServer();
|
disconnectFromServer();
|
||||||
|
|
||||||
@ -655,7 +656,7 @@ class InvenTreeAPI {
|
|||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
L10().profileSelect,
|
L10().profileSelect,
|
||||||
success: false,
|
success: false,
|
||||||
icon: TablerIcons.exclamation_circle
|
icon: TablerIcons.exclamation_circle,
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -679,9 +680,7 @@ class InvenTreeAPI {
|
|||||||
|
|
||||||
if (_notification_timer == null) {
|
if (_notification_timer == null) {
|
||||||
debug("starting notification timer");
|
debug("starting notification timer");
|
||||||
_notification_timer = Timer.periodic(
|
_notification_timer = Timer.periodic(Duration(seconds: 60), (timer) {
|
||||||
Duration(seconds: 60),
|
|
||||||
(timer) {
|
|
||||||
_refreshNotifications();
|
_refreshNotifications();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -698,7 +697,6 @@ class InvenTreeAPI {
|
|||||||
* Request the user roles (permissions) from the InvenTree server
|
* Request the user roles (permissions) from the InvenTree server
|
||||||
*/
|
*/
|
||||||
Future<bool> _fetchRoles() async {
|
Future<bool> _fetchRoles() async {
|
||||||
|
|
||||||
roles.clear();
|
roles.clear();
|
||||||
|
|
||||||
debug("API: Requesting user role data");
|
debug("API: Requesting user role data");
|
||||||
@ -712,15 +710,10 @@ class InvenTreeAPI {
|
|||||||
var data = response.asMap();
|
var data = response.asMap();
|
||||||
|
|
||||||
if (!data.containsKey("roles")) {
|
if (!data.containsKey("roles")) {
|
||||||
|
|
||||||
roles = {};
|
roles = {};
|
||||||
permissions = {};
|
permissions = {};
|
||||||
|
|
||||||
showServerError(
|
showServerError(apiUrl, L10().serverError, L10().errorUserRoles);
|
||||||
apiUrl,
|
|
||||||
L10().serverError,
|
|
||||||
L10().errorUserRoles,
|
|
||||||
);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -737,7 +730,6 @@ class InvenTreeAPI {
|
|||||||
|
|
||||||
// Request plugin information from the server
|
// Request plugin information from the server
|
||||||
Future<bool> _fetchPlugins() async {
|
Future<bool> _fetchPlugins() async {
|
||||||
|
|
||||||
_plugins.clear();
|
_plugins.clear();
|
||||||
|
|
||||||
debug("API: getPluginInformation()");
|
debug("API: getPluginInformation()");
|
||||||
@ -762,7 +754,6 @@ class InvenTreeAPI {
|
|||||||
* e.g. "sales_order", "change"
|
* e.g. "sales_order", "change"
|
||||||
*/
|
*/
|
||||||
bool checkRole(String role, String permission) {
|
bool checkRole(String role, String permission) {
|
||||||
|
|
||||||
if (!_connected) {
|
if (!_connected) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -793,12 +784,13 @@ class InvenTreeAPI {
|
|||||||
// Unknown error - report it!
|
// Unknown error - report it!
|
||||||
sentryReportError(
|
sentryReportError(
|
||||||
"api.checkRole",
|
"api.checkRole",
|
||||||
error, stackTrace,
|
error,
|
||||||
|
stackTrace,
|
||||||
context: {
|
context: {
|
||||||
"role": role,
|
"role": role,
|
||||||
"permission": permission,
|
"permission": permission,
|
||||||
"error": error.toString(),
|
"error": error.toString(),
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -841,12 +833,13 @@ class InvenTreeAPI {
|
|||||||
// Unknown error - report it!
|
// Unknown error - report it!
|
||||||
sentryReportError(
|
sentryReportError(
|
||||||
"api.checkPermission",
|
"api.checkPermission",
|
||||||
error, stackTrace,
|
error,
|
||||||
|
stackTrace,
|
||||||
context: {
|
context: {
|
||||||
"model": model,
|
"model": model,
|
||||||
"permission": permission,
|
"permission": permission,
|
||||||
"error": error.toString(),
|
"error": error.toString(),
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -855,10 +848,12 @@ class InvenTreeAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Perform a PATCH request
|
// Perform a PATCH request
|
||||||
Future<APIResponse> patch(String url, {Map<String, dynamic> body = const {}, int? expectedStatusCode}) async {
|
Future<APIResponse> patch(
|
||||||
|
String url, {
|
||||||
|
Map<String, dynamic> body = const {},
|
||||||
|
int? expectedStatusCode,
|
||||||
|
}) async {
|
||||||
Map<String, dynamic> _body = body;
|
Map<String, dynamic> _body = body;
|
||||||
|
|
||||||
HttpClientRequest? request = await apiRequest(url, "PATCH");
|
HttpClientRequest? request = await apiRequest(url, "PATCH");
|
||||||
@ -868,14 +863,14 @@ class InvenTreeAPI {
|
|||||||
return APIResponse(
|
return APIResponse(
|
||||||
url: url,
|
url: url,
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
error: "HttpClientRequest is null"
|
error: "HttpClientRequest is null",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return completeRequest(
|
return completeRequest(
|
||||||
request,
|
request,
|
||||||
data: json.encode(_body),
|
data: json.encode(_body),
|
||||||
statusCode: expectedStatusCode
|
statusCode: expectedStatusCode,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -883,7 +878,6 @@ class InvenTreeAPI {
|
|||||||
* Download a file from the given URL
|
* Download a file from the given URL
|
||||||
*/
|
*/
|
||||||
Future<void> downloadFile(String url, {bool openOnDownload = true}) async {
|
Future<void> downloadFile(String url, {bool openOnDownload = true}) async {
|
||||||
|
|
||||||
if (url.isEmpty) {
|
if (url.isEmpty) {
|
||||||
// No URL provided for download
|
// No URL provided for download
|
||||||
return;
|
return;
|
||||||
@ -910,19 +904,22 @@ class InvenTreeAPI {
|
|||||||
|
|
||||||
HttpClientRequest? _request;
|
HttpClientRequest? _request;
|
||||||
|
|
||||||
final bool strictHttps = await InvenTreeSettingsManager().getValue(INV_STRICT_HTTPS, false) as bool;
|
final bool strictHttps =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_STRICT_HTTPS, false)
|
||||||
|
as bool;
|
||||||
|
|
||||||
var client = createClient(url, strictHttps: strictHttps);
|
var client = createClient(url, strictHttps: strictHttps);
|
||||||
|
|
||||||
// Attempt to open a connection to the server
|
// Attempt to open a connection to the server
|
||||||
try {
|
try {
|
||||||
_request = await client.openUrl("GET", _uri).timeout(Duration(seconds: 10));
|
_request = await client
|
||||||
|
.openUrl("GET", _uri)
|
||||||
|
.timeout(Duration(seconds: 10));
|
||||||
|
|
||||||
// Set headers
|
// Set headers
|
||||||
defaultHeaders().forEach((key, value) {
|
defaultHeaders().forEach((key, value) {
|
||||||
_request?.headers.set(key, value);
|
_request?.headers.set(key, value);
|
||||||
});
|
});
|
||||||
|
|
||||||
} on SocketException catch (error) {
|
} on SocketException catch (error) {
|
||||||
debug("SocketException at ${url}: ${error.toString()}");
|
debug("SocketException at ${url}: ${error.toString()}");
|
||||||
showServerError(url, L10().connectionRefused, error.toString());
|
showServerError(url, L10().connectionRefused, error.toString());
|
||||||
@ -939,10 +936,7 @@ class InvenTreeAPI {
|
|||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
debug("Server error at ${url}: ${error.toString()}");
|
debug("Server error at ${url}: ${error.toString()}");
|
||||||
showServerError(url, L10().serverError, error.toString());
|
showServerError(url, L10().serverError, error.toString());
|
||||||
sentryReportError(
|
sentryReportError("api.downloadFile : client.openUrl", error, stackTrace);
|
||||||
"api.downloadFile : client.openUrl",
|
|
||||||
error, stackTrace,
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -972,7 +966,8 @@ class InvenTreeAPI {
|
|||||||
showServerError(url, L10().downloadError, error.toString());
|
showServerError(url, L10().downloadError, error.toString());
|
||||||
sentryReportError(
|
sentryReportError(
|
||||||
"api.downloadFile : client.closeRequest",
|
"api.downloadFile : client.closeRequest",
|
||||||
error, stackTrace,
|
error,
|
||||||
|
stackTrace,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -980,8 +975,13 @@ class InvenTreeAPI {
|
|||||||
/*
|
/*
|
||||||
* Upload a file to the given URL
|
* Upload a file to the given URL
|
||||||
*/
|
*/
|
||||||
Future<APIResponse> uploadFile(String url, File f,
|
Future<APIResponse> uploadFile(
|
||||||
{String name = "attachment", String method="POST", Map<String, dynamic>? fields}) async {
|
String url,
|
||||||
|
File f, {
|
||||||
|
String name = "attachment",
|
||||||
|
String method = "POST",
|
||||||
|
Map<String, dynamic>? fields,
|
||||||
|
}) async {
|
||||||
var _url = makeApiUrl(url);
|
var _url = makeApiUrl(url);
|
||||||
|
|
||||||
var request = http.MultipartRequest(method, Uri.parse(_url));
|
var request = http.MultipartRequest(method, Uri.parse(_url));
|
||||||
@ -990,7 +990,6 @@ class InvenTreeAPI {
|
|||||||
|
|
||||||
if (fields != null) {
|
if (fields != null) {
|
||||||
fields.forEach((String key, dynamic value) {
|
fields.forEach((String key, dynamic value) {
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
request.fields[key] = "";
|
request.fields[key] = "";
|
||||||
} else {
|
} else {
|
||||||
@ -1003,10 +1002,7 @@ class InvenTreeAPI {
|
|||||||
|
|
||||||
request.files.add(_file);
|
request.files.add(_file);
|
||||||
|
|
||||||
APIResponse response = APIResponse(
|
APIResponse response = APIResponse(url: url, method: method);
|
||||||
url: url,
|
|
||||||
method: method,
|
|
||||||
);
|
|
||||||
|
|
||||||
String jsondata = "";
|
String jsondata = "";
|
||||||
|
|
||||||
@ -1030,7 +1026,7 @@ class InvenTreeAPI {
|
|||||||
"statusCode": response.statusCode.toString(),
|
"statusCode": response.statusCode.toString(),
|
||||||
"requestHeaders": request.headers.toString(),
|
"requestHeaders": request.headers.toString(),
|
||||||
"responseHeaders": httpResponse.headers.toString(),
|
"responseHeaders": httpResponse.headers.toString(),
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} on SocketException catch (error) {
|
} on SocketException catch (error) {
|
||||||
@ -1041,7 +1037,7 @@ class InvenTreeAPI {
|
|||||||
showServerError(
|
showServerError(
|
||||||
url,
|
url,
|
||||||
L10().formatException,
|
L10().formatException,
|
||||||
L10().formatExceptionJson + ":\n${jsondata}"
|
L10().formatExceptionJson + ":\n${jsondata}",
|
||||||
);
|
);
|
||||||
|
|
||||||
sentryReportMessage(
|
sentryReportMessage(
|
||||||
@ -1051,18 +1047,14 @@ class InvenTreeAPI {
|
|||||||
"url": url,
|
"url": url,
|
||||||
"statusCode": response.statusCode.toString(),
|
"statusCode": response.statusCode.toString(),
|
||||||
"data": jsondata,
|
"data": jsondata,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
} on TimeoutException {
|
} on TimeoutException {
|
||||||
showTimeoutError(url);
|
showTimeoutError(url);
|
||||||
response.error = "TimeoutException";
|
response.error = "TimeoutException";
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
showServerError(url, L10().serverError, error.toString());
|
showServerError(url, L10().serverError, error.toString());
|
||||||
sentryReportError(
|
sentryReportError("api.uploadFile", error, stackTrace);
|
||||||
"api.uploadFile",
|
|
||||||
error, stackTrace
|
|
||||||
);
|
|
||||||
response.error = "UnknownError";
|
response.error = "UnknownError";
|
||||||
response.errorDetail = error.toString();
|
response.errorDetail = error.toString();
|
||||||
}
|
}
|
||||||
@ -1077,15 +1069,11 @@ class InvenTreeAPI {
|
|||||||
* so that (hopefully) the field messages are correctly translated
|
* so that (hopefully) the field messages are correctly translated
|
||||||
*/
|
*/
|
||||||
Future<APIResponse> options(String url) async {
|
Future<APIResponse> options(String url) async {
|
||||||
|
|
||||||
HttpClientRequest? request = await apiRequest(url, "OPTIONS");
|
HttpClientRequest? request = await apiRequest(url, "OPTIONS");
|
||||||
|
|
||||||
if (request == null) {
|
if (request == null) {
|
||||||
// Return an "invalid" APIResponse
|
// Return an "invalid" APIResponse
|
||||||
return APIResponse(
|
return APIResponse(url: url, method: "OPTIONS");
|
||||||
url: url,
|
|
||||||
method: "OPTIONS"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return completeRequest(request);
|
return completeRequest(request);
|
||||||
@ -1095,22 +1083,22 @@ class InvenTreeAPI {
|
|||||||
* Perform a HTTP POST request
|
* Perform a HTTP POST request
|
||||||
* Returns a json object (or null if unsuccessful)
|
* Returns a json object (or null if unsuccessful)
|
||||||
*/
|
*/
|
||||||
Future<APIResponse> post(String url, {Map<String, dynamic> body = const {}, int? expectedStatusCode=201}) async {
|
Future<APIResponse> post(
|
||||||
|
String url, {
|
||||||
|
Map<String, dynamic> body = const {},
|
||||||
|
int? expectedStatusCode = 201,
|
||||||
|
}) async {
|
||||||
HttpClientRequest? request = await apiRequest(url, "POST");
|
HttpClientRequest? request = await apiRequest(url, "POST");
|
||||||
|
|
||||||
if (request == null) {
|
if (request == null) {
|
||||||
// Return an "invalid" APIResponse
|
// Return an "invalid" APIResponse
|
||||||
return APIResponse(
|
return APIResponse(url: url, method: "POST");
|
||||||
url: url,
|
|
||||||
method: "POST"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return completeRequest(
|
return completeRequest(
|
||||||
request,
|
request,
|
||||||
data: json.encode(body),
|
data: json.encode(body),
|
||||||
statusCode: expectedStatusCode
|
statusCode: expectedStatusCode,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1118,7 +1106,6 @@ class InvenTreeAPI {
|
|||||||
* Perform a request to link a custom barcode to a particular item
|
* Perform a request to link a custom barcode to a particular item
|
||||||
*/
|
*/
|
||||||
Future<bool> linkBarcode(Map<String, String> body) async {
|
Future<bool> linkBarcode(Map<String, String> body) async {
|
||||||
|
|
||||||
HttpClientRequest? request = await apiRequest("/barcode/link/", "POST");
|
HttpClientRequest? request = await apiRequest("/barcode/link/", "POST");
|
||||||
|
|
||||||
if (request == null) {
|
if (request == null) {
|
||||||
@ -1128,18 +1115,16 @@ class InvenTreeAPI {
|
|||||||
final response = await completeRequest(
|
final response = await completeRequest(
|
||||||
request,
|
request,
|
||||||
data: json.encode(body),
|
data: json.encode(body),
|
||||||
statusCode: 200
|
statusCode: 200,
|
||||||
);
|
);
|
||||||
|
|
||||||
return response.isValid() && response.statusCode == 200;
|
return response.isValid() && response.statusCode == 200;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform a request to unlink a custom barcode from a particular item
|
* Perform a request to unlink a custom barcode from a particular item
|
||||||
*/
|
*/
|
||||||
Future<bool> unlinkBarcode(Map<String, dynamic> body) async {
|
Future<bool> unlinkBarcode(Map<String, dynamic> body) async {
|
||||||
|
|
||||||
HttpClientRequest? request = await apiRequest("/barcode/unlink/", "POST");
|
HttpClientRequest? request = await apiRequest("/barcode/unlink/", "POST");
|
||||||
|
|
||||||
if (request == null) {
|
if (request == null) {
|
||||||
@ -1155,13 +1140,11 @@ class InvenTreeAPI {
|
|||||||
return response.isValid() && response.statusCode == 200;
|
return response.isValid() && response.statusCode == 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HttpClient createClient(String url, {bool strictHttps = false}) {
|
HttpClient createClient(String url, {bool strictHttps = false}) {
|
||||||
|
|
||||||
var client = HttpClient();
|
var client = HttpClient();
|
||||||
|
|
||||||
client.badCertificateCallback = (X509Certificate cert, String host, int port) {
|
client.badCertificateCallback =
|
||||||
|
(X509Certificate cert, String host, int port) {
|
||||||
if (strictHttps) {
|
if (strictHttps) {
|
||||||
showServerError(
|
showServerError(
|
||||||
url,
|
url,
|
||||||
@ -1190,21 +1173,14 @@ class InvenTreeAPI {
|
|||||||
*/
|
*/
|
||||||
Future<HttpClientRequest?> apiRequest(
|
Future<HttpClientRequest?> apiRequest(
|
||||||
String url,
|
String url,
|
||||||
String method,
|
String method, {
|
||||||
{
|
|
||||||
Map<String, String> urlParams = const {},
|
Map<String, String> urlParams = const {},
|
||||||
Map<String, String> headers = const {},
|
Map<String, String> headers = const {},
|
||||||
}
|
}) async {
|
||||||
) async {
|
|
||||||
|
|
||||||
var _url = makeApiUrl(url);
|
var _url = makeApiUrl(url);
|
||||||
|
|
||||||
if (_url.isEmpty) {
|
if (_url.isEmpty) {
|
||||||
showServerError(
|
showServerError(url, L10().invalidHost, L10().invalidHostDetails);
|
||||||
url,
|
|
||||||
L10().invalidHost,
|
|
||||||
L10().invalidHostDetails
|
|
||||||
);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1225,23 +1201,23 @@ class InvenTreeAPI {
|
|||||||
Uri? _uri = Uri.tryParse(_url);
|
Uri? _uri = Uri.tryParse(_url);
|
||||||
|
|
||||||
if (_uri == null || _uri.host.isEmpty) {
|
if (_uri == null || _uri.host.isEmpty) {
|
||||||
showServerError(
|
showServerError(_url, L10().invalidHost, L10().invalidHostDetails);
|
||||||
_url,
|
|
||||||
L10().invalidHost,
|
|
||||||
L10().invalidHostDetails
|
|
||||||
);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpClientRequest? _request;
|
HttpClientRequest? _request;
|
||||||
|
|
||||||
final bool strictHttps = await InvenTreeSettingsManager().getValue(INV_STRICT_HTTPS, false) as bool;
|
final bool strictHttps =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_STRICT_HTTPS, false)
|
||||||
|
as bool;
|
||||||
|
|
||||||
var client = createClient(url, strictHttps: strictHttps);
|
var client = createClient(url, strictHttps: strictHttps);
|
||||||
|
|
||||||
// Attempt to open a connection to the server
|
// Attempt to open a connection to the server
|
||||||
try {
|
try {
|
||||||
_request = await client.openUrl(method, _uri).timeout(Duration(seconds: 10));
|
_request = await client
|
||||||
|
.openUrl(method, _uri)
|
||||||
|
.timeout(Duration(seconds: 10));
|
||||||
|
|
||||||
// Default headers
|
// Default headers
|
||||||
defaultHeaders().forEach((key, value) {
|
defaultHeaders().forEach((key, value) {
|
||||||
@ -1281,40 +1257,45 @@ class InvenTreeAPI {
|
|||||||
showServerError(url, L10().serverError, error.toString());
|
showServerError(url, L10().serverError, error.toString());
|
||||||
sentryReportError(
|
sentryReportError(
|
||||||
"api.apiRequest : openUrl",
|
"api.apiRequest : openUrl",
|
||||||
error, stackTrace,
|
error,
|
||||||
context: {
|
stackTrace,
|
||||||
"url": url,
|
context: {"url": url, "method": method},
|
||||||
"method": method,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Complete an API request, and return an APIResponse object
|
* Complete an API request, and return an APIResponse object
|
||||||
*/
|
*/
|
||||||
Future<APIResponse> completeRequest(HttpClientRequest request, {String? data, int? statusCode, bool ignoreResponse = false}) async {
|
Future<APIResponse> completeRequest(
|
||||||
|
HttpClientRequest request, {
|
||||||
|
String? data,
|
||||||
|
int? statusCode,
|
||||||
|
bool ignoreResponse = false,
|
||||||
|
}) async {
|
||||||
if (data != null && data.isNotEmpty) {
|
if (data != null && data.isNotEmpty) {
|
||||||
|
|
||||||
var encoded_data = utf8.encode(data);
|
var encoded_data = utf8.encode(data);
|
||||||
|
|
||||||
request.headers.set(HttpHeaders.contentLengthHeader, encoded_data.length.toString());
|
request.headers.set(
|
||||||
|
HttpHeaders.contentLengthHeader,
|
||||||
|
encoded_data.length.toString(),
|
||||||
|
);
|
||||||
request.add(encoded_data);
|
request.add(encoded_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
APIResponse response = APIResponse(
|
APIResponse response = APIResponse(
|
||||||
method: request.method,
|
method: request.method,
|
||||||
url: request.uri.toString()
|
url: request.uri.toString(),
|
||||||
);
|
);
|
||||||
|
|
||||||
String url = request.uri.toString();
|
String url = request.uri.toString();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HttpClientResponse? _response = await request.close().timeout(Duration(seconds: 10));
|
HttpClientResponse? _response = await request.close().timeout(
|
||||||
|
Duration(seconds: 10),
|
||||||
|
);
|
||||||
|
|
||||||
response.statusCode = _response.statusCode;
|
response.statusCode = _response.statusCode;
|
||||||
|
|
||||||
@ -1338,16 +1319,21 @@ class InvenTreeAPI {
|
|||||||
"requestHeaders": request.headers.toString(),
|
"requestHeaders": request.headers.toString(),
|
||||||
"responseHeaders": _response.headers.toString(),
|
"responseHeaders": _response.headers.toString(),
|
||||||
"responseData": response.data.toString(),
|
"responseData": response.data.toString(),
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
response.data = ignoreResponse
|
||||||
response.data = ignoreResponse ? {} : await responseToJson(url, _response) ?? {};
|
? {}
|
||||||
|
: await responseToJson(url, _response) ?? {};
|
||||||
|
|
||||||
// First check that the returned status code is what we expected
|
// First check that the returned status code is what we expected
|
||||||
if (statusCode != null && statusCode != _response.statusCode) {
|
if (statusCode != null && statusCode != _response.statusCode) {
|
||||||
showStatusCodeError(url, _response.statusCode, details: response.data.toString());
|
showStatusCodeError(
|
||||||
|
url,
|
||||||
|
_response.statusCode,
|
||||||
|
details: response.data.toString(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} on HttpException catch (error) {
|
} on HttpException catch (error) {
|
||||||
@ -1373,14 +1359,12 @@ class InvenTreeAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert a HttpClientResponse response object to JSON
|
* Convert a HttpClientResponse response object to JSON
|
||||||
*/
|
*/
|
||||||
dynamic responseToJson(String url, HttpClientResponse response) async {
|
dynamic responseToJson(String url, HttpClientResponse response) async {
|
||||||
|
|
||||||
String body = await response.transform(utf8.decoder).join();
|
String body = await response.transform(utf8.decoder).join();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -1388,7 +1372,6 @@ class InvenTreeAPI {
|
|||||||
|
|
||||||
return data ?? {};
|
return data ?? {};
|
||||||
} on FormatException {
|
} on FormatException {
|
||||||
|
|
||||||
switch (response.statusCode) {
|
switch (response.statusCode) {
|
||||||
case 400:
|
case 400:
|
||||||
case 401:
|
case 401:
|
||||||
@ -1409,28 +1392,31 @@ class InvenTreeAPI {
|
|||||||
"statusCode": response.statusCode.toString(),
|
"statusCode": response.statusCode.toString(),
|
||||||
"data": body.toString(),
|
"data": body.toString(),
|
||||||
"endpoint": url,
|
"endpoint": url,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
showServerError(
|
showServerError(
|
||||||
url,
|
url,
|
||||||
L10().formatException,
|
L10().formatException,
|
||||||
L10().formatExceptionJson + ":\n${body}"
|
L10().formatExceptionJson + ":\n${body}",
|
||||||
);
|
);
|
||||||
|
|
||||||
// Return an empty map
|
// Return an empty map
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform a HTTP GET request
|
* Perform a HTTP GET request
|
||||||
* Returns a json object (or null if did not complete)
|
* Returns a json object (or null if did not complete)
|
||||||
*/
|
*/
|
||||||
Future<APIResponse> get(String url, {Map<String, String> params = const {}, Map<String, String> headers = const {}, int? expectedStatusCode=200}) async {
|
Future<APIResponse> get(
|
||||||
|
String url, {
|
||||||
|
Map<String, String> params = const {},
|
||||||
|
Map<String, String> headers = const {},
|
||||||
|
int? expectedStatusCode = 200,
|
||||||
|
}) async {
|
||||||
HttpClientRequest? request = await apiRequest(
|
HttpClientRequest? request = await apiRequest(
|
||||||
url,
|
url,
|
||||||
"GET",
|
"GET",
|
||||||
@ -1438,7 +1424,6 @@ class InvenTreeAPI {
|
|||||||
headers: headers,
|
headers: headers,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
if (request == null) {
|
if (request == null) {
|
||||||
// Return an "invalid" APIResponse
|
// Return an "invalid" APIResponse
|
||||||
return APIResponse(
|
return APIResponse(
|
||||||
@ -1455,11 +1440,7 @@ class InvenTreeAPI {
|
|||||||
* Perform a HTTP DELETE request
|
* Perform a HTTP DELETE request
|
||||||
*/
|
*/
|
||||||
Future<APIResponse> delete(String url) async {
|
Future<APIResponse> delete(String url) async {
|
||||||
|
HttpClientRequest? request = await apiRequest(url, "DELETE");
|
||||||
HttpClientRequest? request = await apiRequest(
|
|
||||||
url,
|
|
||||||
"DELETE",
|
|
||||||
);
|
|
||||||
|
|
||||||
if (request == null) {
|
if (request == null) {
|
||||||
// Return an "invalid" APIResponse object
|
// Return an "invalid" APIResponse object
|
||||||
@ -1470,23 +1451,17 @@ class InvenTreeAPI {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return completeRequest(
|
return completeRequest(request, ignoreResponse: true);
|
||||||
request,
|
|
||||||
ignoreResponse: true,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the current locale code for the running app
|
// Find the current locale code for the running app
|
||||||
String get currentLocale {
|
String get currentLocale {
|
||||||
|
|
||||||
if (hasContext()) {
|
if (hasContext()) {
|
||||||
// Try to get app context
|
// Try to get app context
|
||||||
BuildContext? context = OneContext().context;
|
BuildContext? context = OneContext().context;
|
||||||
|
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
Locale? locale = InvenTreeApp
|
Locale? locale = InvenTreeApp.of(context)?.locale;
|
||||||
.of(context)
|
|
||||||
?.locale;
|
|
||||||
|
|
||||||
if (locale != null) {
|
if (locale != null) {
|
||||||
return locale.languageCode; //.toString();
|
return locale.languageCode; //.toString();
|
||||||
@ -1526,8 +1501,11 @@ class InvenTreeAPI {
|
|||||||
|
|
||||||
static String get staticThumb => "/static/img/blank_image.thumbnail.png";
|
static String get staticThumb => "/static/img/blank_image.thumbnail.png";
|
||||||
|
|
||||||
CachedNetworkImage? getThumbnail(String imageUrl, {double size = 40, bool hideIfNull = false}) {
|
CachedNetworkImage? getThumbnail(
|
||||||
|
String imageUrl, {
|
||||||
|
double size = 40,
|
||||||
|
bool hideIfNull = false,
|
||||||
|
}) {
|
||||||
if (hideIfNull) {
|
if (hideIfNull) {
|
||||||
if (imageUrl.isEmpty) {
|
if (imageUrl.isEmpty) {
|
||||||
return null;
|
return null;
|
||||||
@ -1535,11 +1513,7 @@ class InvenTreeAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return getImage(
|
return getImage(imageUrl, width: size, height: size);
|
||||||
imageUrl,
|
|
||||||
width: size,
|
|
||||||
height: size
|
|
||||||
);
|
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
sentryReportError("_getThumbnail", error, stackTrace);
|
sentryReportError("_getThumbnail", error, stackTrace);
|
||||||
return null;
|
return null;
|
||||||
@ -1550,7 +1524,11 @@ class InvenTreeAPI {
|
|||||||
* Load image from the InvenTree server,
|
* Load image from the InvenTree server,
|
||||||
* or from local cache (if it has been cached!)
|
* or from local cache (if it has been cached!)
|
||||||
*/
|
*/
|
||||||
CachedNetworkImage getImage(String imageUrl, {double? height, double? width}) {
|
CachedNetworkImage getImage(
|
||||||
|
String imageUrl, {
|
||||||
|
double? height,
|
||||||
|
double? width,
|
||||||
|
}) {
|
||||||
if (imageUrl.isEmpty) {
|
if (imageUrl.isEmpty) {
|
||||||
imageUrl = staticImage;
|
imageUrl = staticImage;
|
||||||
}
|
}
|
||||||
@ -1560,18 +1538,14 @@ class InvenTreeAPI {
|
|||||||
const key = "inventree_network_image";
|
const key = "inventree_network_image";
|
||||||
|
|
||||||
CacheManager manager = CacheManager(
|
CacheManager manager = CacheManager(
|
||||||
Config(
|
Config(key, fileService: InvenTreeFileService(strictHttps: _strictHttps)),
|
||||||
key,
|
|
||||||
fileService: InvenTreeFileService(
|
|
||||||
strictHttps: _strictHttps,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return CachedNetworkImage(
|
return CachedNetworkImage(
|
||||||
imageUrl: url,
|
imageUrl: url,
|
||||||
placeholder: (context, url) => CircularProgressIndicator(),
|
placeholder: (context, url) => CircularProgressIndicator(),
|
||||||
errorWidget: (context, url, error) => Icon(TablerIcons.circle_x, color: COLOR_DANGER),
|
errorWidget: (context, url, error) =>
|
||||||
|
Icon(TablerIcons.circle_x, color: COLOR_DANGER),
|
||||||
httpHeaders: defaultHeaders(),
|
httpHeaders: defaultHeaders(),
|
||||||
height: height,
|
height: height,
|
||||||
width: width,
|
width: width,
|
||||||
@ -1584,7 +1558,6 @@ class InvenTreeAPI {
|
|||||||
Map<String, InvenTreeUserSetting> _userSettings = {};
|
Map<String, InvenTreeUserSetting> _userSettings = {};
|
||||||
|
|
||||||
Future<String> getGlobalSetting(String key) async {
|
Future<String> getGlobalSetting(String key) async {
|
||||||
|
|
||||||
InvenTreeGlobalSetting? setting = _globalSettings[key];
|
InvenTreeGlobalSetting? setting = _globalSettings[key];
|
||||||
|
|
||||||
if ((setting != null) && setting.reloadedWithin(Duration(minutes: 5))) {
|
if ((setting != null) && setting.reloadedWithin(Duration(minutes: 5))) {
|
||||||
@ -1603,7 +1576,10 @@ class InvenTreeAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return a boolean global setting value
|
// Return a boolean global setting value
|
||||||
Future<bool> getGlobalBooleanSetting(String key, { bool backup = false }) async {
|
Future<bool> getGlobalBooleanSetting(
|
||||||
|
String key, {
|
||||||
|
bool backup = false,
|
||||||
|
}) async {
|
||||||
String value = await getGlobalSetting(key);
|
String value = await getGlobalSetting(key);
|
||||||
|
|
||||||
if (value.isEmpty) {
|
if (value.isEmpty) {
|
||||||
@ -1614,7 +1590,6 @@ class InvenTreeAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<String> getUserSetting(String key) async {
|
Future<String> getUserSetting(String key) async {
|
||||||
|
|
||||||
InvenTreeUserSetting? setting = _userSettings[key];
|
InvenTreeUserSetting? setting = _userSettings[key];
|
||||||
|
|
||||||
if ((setting != null) && setting.reloadedWithin(Duration(minutes: 5))) {
|
if ((setting != null) && setting.reloadedWithin(Duration(minutes: 5))) {
|
||||||
@ -1641,8 +1616,11 @@ class InvenTreeAPI {
|
|||||||
/*
|
/*
|
||||||
* Send a request to the server to locate / identify either a StockItem or StockLocation
|
* Send a request to the server to locate / identify either a StockItem or StockLocation
|
||||||
*/
|
*/
|
||||||
Future<void> locateItemOrLocation(BuildContext context, {int? item, int? location}) async {
|
Future<void> locateItemOrLocation(
|
||||||
|
BuildContext context, {
|
||||||
|
int? item,
|
||||||
|
int? location,
|
||||||
|
}) async {
|
||||||
var plugins = getPlugins(mixin: "locate");
|
var plugins = getPlugins(mixin: "locate");
|
||||||
|
|
||||||
if (plugins.isEmpty) {
|
if (plugins.isEmpty) {
|
||||||
@ -1672,7 +1650,7 @@ class InvenTreeAPI {
|
|||||||
"value": plugins.first.key,
|
"value": plugins.first.key,
|
||||||
"choices": plugin_options,
|
"choices": plugin_options,
|
||||||
"required": true,
|
"required": true,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await launchApiForm(
|
await launchApiForm(
|
||||||
@ -1683,13 +1661,11 @@ class InvenTreeAPI {
|
|||||||
icon: TablerIcons.location_search,
|
icon: TablerIcons.location_search,
|
||||||
onSuccess: (Map<String, dynamic> data) async {
|
onSuccess: (Map<String, dynamic> data) async {
|
||||||
plugin_name = (data["plugin"] ?? "") as String;
|
plugin_name = (data["plugin"] ?? "") as String;
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> body = {
|
Map<String, dynamic> body = {"plugin": plugin_name};
|
||||||
"plugin": plugin_name,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
body["item"] = item.toString();
|
body["item"] = item.toString();
|
||||||
@ -1699,16 +1675,11 @@ class InvenTreeAPI {
|
|||||||
body["location"] = location.toString();
|
body["location"] = location.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
post(
|
post("/api/locate/", body: body, expectedStatusCode: 200).then((
|
||||||
"/api/locate/",
|
APIResponse response,
|
||||||
body: body,
|
) {
|
||||||
expectedStatusCode: 200,
|
|
||||||
).then((APIResponse response) {
|
|
||||||
if (response.successful()) {
|
if (response.successful()) {
|
||||||
showSnackIcon(
|
showSnackIcon(L10().requestSuccessful, success: true);
|
||||||
L10().requestSuccessful,
|
|
||||||
success: true,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1726,10 +1697,13 @@ class InvenTreeAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Accessors methods for various status code classes
|
// Accessors methods for various status code classes
|
||||||
InvenTreeStatusCode get StockHistoryStatus => _get_status_class("stock/track/status/");
|
InvenTreeStatusCode get StockHistoryStatus =>
|
||||||
|
_get_status_class("stock/track/status/");
|
||||||
InvenTreeStatusCode get StockStatus => _get_status_class("stock/status/");
|
InvenTreeStatusCode get StockStatus => _get_status_class("stock/status/");
|
||||||
InvenTreeStatusCode get PurchaseOrderStatus => _get_status_class("order/po/status/");
|
InvenTreeStatusCode get PurchaseOrderStatus =>
|
||||||
InvenTreeStatusCode get SalesOrderStatus => _get_status_class("order/so/status/");
|
_get_status_class("order/po/status/");
|
||||||
|
InvenTreeStatusCode get SalesOrderStatus =>
|
||||||
|
_get_status_class("order/so/status/");
|
||||||
|
|
||||||
void clearStatusCodeData() {
|
void clearStatusCodeData() {
|
||||||
StockHistoryStatus.data.clear();
|
StockHistoryStatus.data.clear();
|
||||||
@ -1762,5 +1736,3 @@ class InvenTreeAPI {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "dart:io";
|
import "dart:io";
|
||||||
|
|
||||||
import "package:intl/intl.dart";
|
import "package:intl/intl.dart";
|
||||||
@ -27,13 +26,11 @@ import "package:inventree/widget/fields.dart";
|
|||||||
import "package:inventree/widget/progress.dart";
|
import "package:inventree/widget/progress.dart";
|
||||||
import "package:inventree/widget/snacks.dart";
|
import "package:inventree/widget/snacks.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class that represents a single "form field",
|
* Class that represents a single "form field",
|
||||||
* defined by the InvenTree API
|
* defined by the InvenTree API
|
||||||
*/
|
*/
|
||||||
class APIFormField {
|
class APIFormField {
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
APIFormField(this.name, this.data);
|
APIFormField(this.name, this.data);
|
||||||
|
|
||||||
@ -53,7 +50,6 @@ class APIFormField {
|
|||||||
|
|
||||||
// Return the "lookup path" for this field, within the server data
|
// Return the "lookup path" for this field, within the server data
|
||||||
String get lookupPath {
|
String get lookupPath {
|
||||||
|
|
||||||
// Simple top-level case
|
// Simple top-level case
|
||||||
if (parent.isEmpty && !nested) {
|
if (parent.isEmpty && !nested) {
|
||||||
return name;
|
return name;
|
||||||
@ -133,19 +129,16 @@ class APIFormField {
|
|||||||
|
|
||||||
// Construct a set of "filters" for this field (e.g. related field)
|
// Construct a set of "filters" for this field (e.g. related field)
|
||||||
Map<String, String> get filters {
|
Map<String, String> get filters {
|
||||||
|
|
||||||
Map<String, String> _filters = {};
|
Map<String, String> _filters = {};
|
||||||
|
|
||||||
// Start with the field "definition" (provided by the server)
|
// Start with the field "definition" (provided by the server)
|
||||||
if (definition.containsKey("filters")) {
|
if (definition.containsKey("filters")) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var fDef = definition["filters"] as Map<String, dynamic>;
|
var fDef = definition["filters"] as Map<String, dynamic>;
|
||||||
|
|
||||||
fDef.forEach((String key, dynamic value) {
|
fDef.forEach((String key, dynamic value) {
|
||||||
_filters[key] = value.toString();
|
_filters[key] = value.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// pass
|
// pass
|
||||||
}
|
}
|
||||||
@ -153,7 +146,6 @@ class APIFormField {
|
|||||||
|
|
||||||
// Next, look at any "instance_filters" provided by the server
|
// Next, look at any "instance_filters" provided by the server
|
||||||
if (definition.containsKey("instance_filters")) {
|
if (definition.containsKey("instance_filters")) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var fIns = definition["instance_filters"] as Map<String, dynamic>;
|
var fIns = definition["instance_filters"] as Map<String, dynamic>;
|
||||||
|
|
||||||
@ -163,7 +155,6 @@ class APIFormField {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
// pass
|
// pass
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, augment or override with any filters provided by the calling function
|
// Finally, augment or override with any filters provided by the calling function
|
||||||
@ -180,14 +171,12 @@ class APIFormField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return _filters;
|
return _filters;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasErrors() => errorMessages().isNotEmpty;
|
bool hasErrors() => errorMessages().isNotEmpty;
|
||||||
|
|
||||||
// Extract error messages from the server response
|
// Extract error messages from the server response
|
||||||
void extractErrorMessages(APIResponse response) {
|
void extractErrorMessages(APIResponse response) {
|
||||||
|
|
||||||
dynamic errors;
|
dynamic errors;
|
||||||
|
|
||||||
if (isSimple) {
|
if (isSimple) {
|
||||||
@ -213,7 +202,6 @@ class APIFormField {
|
|||||||
|
|
||||||
// Return the error message associated with this field
|
// Return the error message associated with this field
|
||||||
List<String> errorMessages() {
|
List<String> errorMessages() {
|
||||||
|
|
||||||
dynamic errors = data["errors"] ?? [];
|
dynamic errors = data["errors"] ?? [];
|
||||||
|
|
||||||
// Handle the case where a single error message is returned
|
// Handle the case where a single error message is returned
|
||||||
@ -246,7 +234,6 @@ class APIFormField {
|
|||||||
List<dynamic> get choices => (getParameter("choices") ?? []) as List<dynamic>;
|
List<dynamic> get choices => (getParameter("choices") ?? []) as List<dynamic>;
|
||||||
|
|
||||||
Future<void> loadInitialData() async {
|
Future<void> loadInitialData() async {
|
||||||
|
|
||||||
// Only for "related fields"
|
// Only for "related fields"
|
||||||
if (type != "related field") {
|
if (type != "related field") {
|
||||||
return;
|
return;
|
||||||
@ -265,10 +252,7 @@ class APIFormField {
|
|||||||
|
|
||||||
String url = api_url + "/" + pk.toString() + "/";
|
String url = api_url + "/" + pk.toString() + "/";
|
||||||
|
|
||||||
final APIResponse response = await InvenTreeAPI().get(
|
final APIResponse response = await InvenTreeAPI().get(url, params: filters);
|
||||||
url,
|
|
||||||
params: filters,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response.successful()) {
|
if (response.successful()) {
|
||||||
initial_data = response.data;
|
initial_data = response.data;
|
||||||
@ -277,7 +261,6 @@ class APIFormField {
|
|||||||
|
|
||||||
// Construct a widget for this input
|
// Construct a widget for this input
|
||||||
Widget constructField(BuildContext context) {
|
Widget constructField(BuildContext context) {
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "string":
|
case "string":
|
||||||
case "url":
|
case "url":
|
||||||
@ -302,17 +285,14 @@ class APIFormField {
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
"Unsupported field type: '${type}' for field '${name}'",
|
"Unsupported field type: '${type}' for field '${name}'",
|
||||||
style: TextStyle(
|
style: TextStyle(color: COLOR_DANGER, fontStyle: FontStyle.italic),
|
||||||
color: COLOR_DANGER,
|
),
|
||||||
fontStyle: FontStyle.italic),
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Field for capturing a barcode
|
// Field for capturing a barcode
|
||||||
Widget _constructBarcodeField(BuildContext context) {
|
Widget _constructBarcodeField(BuildContext context) {
|
||||||
|
|
||||||
TextEditingController controller = TextEditingController();
|
TextEditingController controller = TextEditingController();
|
||||||
|
|
||||||
String barcode = (value ?? "").toString();
|
String barcode = (value ?? "").toString();
|
||||||
@ -332,10 +312,7 @@ class APIFormField {
|
|||||||
hintText: placeholderText,
|
hintText: placeholderText,
|
||||||
),
|
),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: TextField(
|
title: TextField(readOnly: true, controller: controller),
|
||||||
readOnly: true,
|
|
||||||
controller: controller,
|
|
||||||
),
|
|
||||||
trailing: IconButton(
|
trailing: IconButton(
|
||||||
icon: Icon(TablerIcons.qrcode),
|
icon: Icon(TablerIcons.qrcode),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
@ -349,14 +326,12 @@ class APIFormField {
|
|||||||
scanBarcode(context, handler: handler);
|
scanBarcode(context, handler: handler);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Field for displaying and selecting dates
|
// Field for displaying and selecting dates
|
||||||
Widget _constructDateField() {
|
Widget _constructDateField() {
|
||||||
|
|
||||||
DateTime? currentDate = DateTime.tryParse((value ?? "") as String);
|
DateTime? currentDate = DateTime.tryParse((value ?? "") as String);
|
||||||
|
|
||||||
return InputDecorator(
|
return InputDecorator(
|
||||||
@ -387,18 +362,17 @@ class APIFormField {
|
|||||||
|
|
||||||
return time;
|
return time;
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Field for selecting and uploading files
|
// Field for selecting and uploading files
|
||||||
Widget _constructFileField() {
|
Widget _constructFileField() {
|
||||||
|
|
||||||
TextEditingController controller = TextEditingController();
|
TextEditingController controller = TextEditingController();
|
||||||
|
|
||||||
controller.text = (attachedfile?.path ?? L10().attachmentSelect).split("/").last;
|
controller.text = (attachedfile?.path ?? L10().attachmentSelect)
|
||||||
|
.split("/")
|
||||||
|
.last;
|
||||||
|
|
||||||
return InputDecorator(
|
return InputDecorator(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
@ -406,10 +380,7 @@ class APIFormField {
|
|||||||
labelStyle: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
|
labelStyle: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
|
||||||
),
|
),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: TextField(
|
title: TextField(readOnly: true, controller: controller),
|
||||||
readOnly: true,
|
|
||||||
controller: controller,
|
|
||||||
),
|
|
||||||
trailing: IconButton(
|
trailing: IconButton(
|
||||||
icon: Icon(TablerIcons.circle_plus),
|
icon: Icon(TablerIcons.circle_plus),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
@ -421,17 +392,16 @@ class APIFormField {
|
|||||||
|
|
||||||
// Save the file
|
// Save the file
|
||||||
attachedfile = file;
|
attachedfile = file;
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Field for selecting from multiple choice options
|
// Field for selecting from multiple choice options
|
||||||
Widget _constructChoiceField() {
|
Widget _constructChoiceField() {
|
||||||
|
|
||||||
dynamic initial;
|
dynamic initial;
|
||||||
|
|
||||||
// Check if the current value is within the allowed values
|
// Check if the current value is within the allowed values
|
||||||
@ -445,9 +415,7 @@ class APIFormField {
|
|||||||
return DropdownSearch<dynamic>(
|
return DropdownSearch<dynamic>(
|
||||||
popupProps: PopupProps.bottomSheet(
|
popupProps: PopupProps.bottomSheet(
|
||||||
showSelectedItems: false,
|
showSelectedItems: false,
|
||||||
searchFieldProps: TextFieldProps(
|
searchFieldProps: TextFieldProps(autofocus: true),
|
||||||
autofocus: true
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
selectedItem: initial,
|
selectedItem: initial,
|
||||||
items: choices,
|
items: choices,
|
||||||
@ -455,7 +423,8 @@ class APIFormField {
|
|||||||
dropdownSearchDecoration: InputDecoration(
|
dropdownSearchDecoration: InputDecoration(
|
||||||
labelText: label,
|
labelText: label,
|
||||||
hintText: helpText,
|
hintText: helpText,
|
||||||
)),
|
),
|
||||||
|
),
|
||||||
onChanged: null,
|
onChanged: null,
|
||||||
clearButtonProps: ClearButtonProps(isVisible: !required),
|
clearButtonProps: ClearButtonProps(isVisible: !required),
|
||||||
itemAsString: (dynamic item) {
|
itemAsString: (dynamic item) {
|
||||||
@ -467,12 +436,12 @@ class APIFormField {
|
|||||||
} else {
|
} else {
|
||||||
data["value"] = item["value"];
|
data["value"] = item["value"];
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct a floating point numerical input field
|
// Construct a floating point numerical input field
|
||||||
Widget _constructFloatField() {
|
Widget _constructFloatField() {
|
||||||
|
|
||||||
// Initial value: try to cast to a valid number
|
// Initial value: try to cast to a valid number
|
||||||
String initial = "";
|
String initial = "";
|
||||||
|
|
||||||
@ -491,7 +460,10 @@ class APIFormField {
|
|||||||
hintText: placeholderText,
|
hintText: placeholderText,
|
||||||
),
|
),
|
||||||
initialValue: initial,
|
initialValue: initial,
|
||||||
keyboardType: TextInputType.numberWithOptions(signed: true, decimal: true),
|
keyboardType: TextInputType.numberWithOptions(
|
||||||
|
signed: true,
|
||||||
|
decimal: true,
|
||||||
|
),
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
value = value?.trim() ?? "";
|
value = value?.trim() ?? "";
|
||||||
|
|
||||||
@ -512,7 +484,6 @@ class APIFormField {
|
|||||||
data["value"] = val;
|
data["value"] = val;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct an input for a related field
|
// Construct an input for a related field
|
||||||
@ -528,22 +499,20 @@ class APIFormField {
|
|||||||
emptyBuilder: (context, item) {
|
emptyBuilder: (context, item) {
|
||||||
return _renderEmptyResult();
|
return _renderEmptyResult();
|
||||||
},
|
},
|
||||||
searchFieldProps: TextFieldProps(
|
searchFieldProps: TextFieldProps(autofocus: true),
|
||||||
autofocus: true
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
selectedItem: initial_data,
|
selectedItem: initial_data,
|
||||||
asyncItems: (String filter) async {
|
asyncItems: (String filter) async {
|
||||||
Map<String, String> _filters = {
|
Map<String, String> _filters = {..._relatedFieldFilters(), ...filters};
|
||||||
..._relatedFieldFilters(),
|
|
||||||
...filters,
|
|
||||||
};
|
|
||||||
|
|
||||||
_filters["search"] = filter;
|
_filters["search"] = filter;
|
||||||
_filters["offset"] = "0";
|
_filters["offset"] = "0";
|
||||||
_filters["limit"] = "25";
|
_filters["limit"] = "25";
|
||||||
|
|
||||||
final APIResponse response = await InvenTreeAPI().get(api_url, params: _filters);
|
final APIResponse response = await InvenTreeAPI().get(
|
||||||
|
api_url,
|
||||||
|
params: _filters,
|
||||||
|
);
|
||||||
|
|
||||||
if (response.isValid()) {
|
if (response.isValid()) {
|
||||||
return response.resultsList();
|
return response.resultsList();
|
||||||
@ -551,14 +520,13 @@ class APIFormField {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
clearButtonProps: ClearButtonProps(
|
clearButtonProps: ClearButtonProps(isVisible: !required),
|
||||||
isVisible: !required
|
|
||||||
),
|
|
||||||
dropdownDecoratorProps: DropDownDecoratorProps(
|
dropdownDecoratorProps: DropDownDecoratorProps(
|
||||||
dropdownSearchDecoration: InputDecoration(
|
dropdownSearchDecoration: InputDecoration(
|
||||||
labelText: label,
|
labelText: label,
|
||||||
hintText: helpText,
|
hintText: helpText,
|
||||||
)),
|
),
|
||||||
|
),
|
||||||
onChanged: null,
|
onChanged: null,
|
||||||
itemAsString: (dynamic item) {
|
itemAsString: (dynamic item) {
|
||||||
Map<String, dynamic> data = item as Map<String, dynamic>;
|
Map<String, dynamic> data = item as Map<String, dynamic>;
|
||||||
@ -607,12 +575,12 @@ class APIFormField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct a set of custom filters for the dropdown search
|
// Construct a set of custom filters for the dropdown search
|
||||||
Map<String, String> _relatedFieldFilters() {
|
Map<String, String> _relatedFieldFilters() {
|
||||||
|
|
||||||
switch (model) {
|
switch (model) {
|
||||||
case InvenTreeSupplierPart.MODEL_TYPE:
|
case InvenTreeSupplierPart.MODEL_TYPE:
|
||||||
return InvenTreeSupplierPart().defaultListFilters();
|
return InvenTreeSupplierPart().defaultListFilters();
|
||||||
@ -626,8 +594,12 @@ class APIFormField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Render a "related field" based on the "model" type
|
// Render a "related field" based on the "model" type
|
||||||
Widget _renderRelatedField(String fieldName, dynamic item, bool selected, bool extended) {
|
Widget _renderRelatedField(
|
||||||
|
String fieldName,
|
||||||
|
dynamic item,
|
||||||
|
bool selected,
|
||||||
|
bool extended,
|
||||||
|
) {
|
||||||
// Convert to JSON
|
// Convert to JSON
|
||||||
Map<String, dynamic> data = {};
|
Map<String, dynamic> data = {};
|
||||||
|
|
||||||
@ -641,14 +613,16 @@ class APIFormField {
|
|||||||
data = {};
|
data = {};
|
||||||
|
|
||||||
sentryReportError(
|
sentryReportError(
|
||||||
"_renderRelatedField", error, stackTrace,
|
"_renderRelatedField",
|
||||||
|
error,
|
||||||
|
stackTrace,
|
||||||
context: {
|
context: {
|
||||||
"method": "_renderRelateField",
|
"method": "_renderRelateField",
|
||||||
"field_name": fieldName,
|
"field_name": fieldName,
|
||||||
"item": item.toString(),
|
"item": item.toString(),
|
||||||
"selected": selected.toString(),
|
"selected": selected.toString(),
|
||||||
"extended": extended.toString(),
|
"extended": extended.toString(),
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -659,13 +633,23 @@ class APIFormField {
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
part.fullname,
|
part.fullname,
|
||||||
style: TextStyle(fontWeight: selected && extended ? FontWeight.bold : FontWeight.normal)
|
style: TextStyle(
|
||||||
|
fontWeight: selected && extended
|
||||||
|
? FontWeight.bold
|
||||||
|
: FontWeight.normal,
|
||||||
),
|
),
|
||||||
subtitle: extended ? Text(
|
),
|
||||||
|
subtitle: extended
|
||||||
|
? Text(
|
||||||
part.description,
|
part.description,
|
||||||
style: TextStyle(fontWeight: selected ? FontWeight.bold : FontWeight.normal),
|
style: TextStyle(
|
||||||
) : null,
|
fontWeight: selected ? FontWeight.bold : FontWeight.normal,
|
||||||
leading: extended ? InvenTreeAPI().getThumbnail(part.thumbnail) : null,
|
),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
leading: extended
|
||||||
|
? InvenTreeAPI().getThumbnail(part.thumbnail)
|
||||||
|
: null,
|
||||||
);
|
);
|
||||||
case InvenTreePartTestTemplate.MODEL_TYPE:
|
case InvenTreePartTestTemplate.MODEL_TYPE:
|
||||||
var template = InvenTreePartTestTemplate.fromJson(data);
|
var template = InvenTreePartTestTemplate.fromJson(data);
|
||||||
@ -680,30 +664,39 @@ class APIFormField {
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(part.SKU),
|
title: Text(part.SKU),
|
||||||
subtitle: Text(part.partName),
|
subtitle: Text(part.partName),
|
||||||
leading: extended ? InvenTreeAPI().getThumbnail(part.partImage) : null,
|
leading: extended
|
||||||
trailing: extended && part.supplierImage.isNotEmpty ? InvenTreeAPI().getThumbnail(part.supplierImage) : null,
|
? InvenTreeAPI().getThumbnail(part.partImage)
|
||||||
|
: null,
|
||||||
|
trailing: extended && part.supplierImage.isNotEmpty
|
||||||
|
? InvenTreeAPI().getThumbnail(part.supplierImage)
|
||||||
|
: null,
|
||||||
);
|
);
|
||||||
case InvenTreePartCategory.MODEL_TYPE:
|
case InvenTreePartCategory.MODEL_TYPE:
|
||||||
|
|
||||||
var cat = InvenTreePartCategory.fromJson(data);
|
var cat = InvenTreePartCategory.fromJson(data);
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
cat.pathstring,
|
cat.pathstring,
|
||||||
style: TextStyle(fontWeight: selected && extended ? FontWeight.bold : FontWeight.normal)
|
style: TextStyle(
|
||||||
|
fontWeight: selected && extended
|
||||||
|
? FontWeight.bold
|
||||||
|
: FontWeight.normal,
|
||||||
),
|
),
|
||||||
subtitle: extended ? Text(
|
),
|
||||||
|
subtitle: extended
|
||||||
|
? Text(
|
||||||
cat.description,
|
cat.description,
|
||||||
style: TextStyle(fontWeight: selected ? FontWeight.bold : FontWeight.normal),
|
style: TextStyle(
|
||||||
) : null,
|
fontWeight: selected ? FontWeight.bold : FontWeight.normal,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
);
|
);
|
||||||
case InvenTreeStockItem.MODEL_TYPE:
|
case InvenTreeStockItem.MODEL_TYPE:
|
||||||
var item = InvenTreeStockItem.fromJson(data);
|
var item = InvenTreeStockItem.fromJson(data);
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(
|
title: Text(item.partName),
|
||||||
item.partName,
|
|
||||||
),
|
|
||||||
leading: InvenTreeAPI().getThumbnail(item.partThumbnail),
|
leading: InvenTreeAPI().getThumbnail(item.partThumbnail),
|
||||||
trailing: Text(item.quantityString()),
|
trailing: Text(item.quantityString()),
|
||||||
);
|
);
|
||||||
@ -713,12 +706,20 @@ class APIFormField {
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
loc.pathstring,
|
loc.pathstring,
|
||||||
style: TextStyle(fontWeight: selected && extended ? FontWeight.bold : FontWeight.normal)
|
style: TextStyle(
|
||||||
|
fontWeight: selected && extended
|
||||||
|
? FontWeight.bold
|
||||||
|
: FontWeight.normal,
|
||||||
),
|
),
|
||||||
subtitle: extended ? Text(
|
),
|
||||||
|
subtitle: extended
|
||||||
|
? Text(
|
||||||
loc.description,
|
loc.description,
|
||||||
style: TextStyle(fontWeight: selected ? FontWeight.bold : FontWeight.normal),
|
style: TextStyle(
|
||||||
) : null,
|
fontWeight: selected ? FontWeight.bold : FontWeight.normal,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
);
|
);
|
||||||
case InvenTreeSalesOrderShipment.MODEL_TYPE:
|
case InvenTreeSalesOrderShipment.MODEL_TYPE:
|
||||||
var shipment = InvenTreeSalesOrderShipment.fromJson(data);
|
var shipment = InvenTreeSalesOrderShipment.fromJson(data);
|
||||||
@ -738,32 +739,26 @@ class APIFormField {
|
|||||||
case "contact":
|
case "contact":
|
||||||
String name = (data["name"] ?? "") as String;
|
String name = (data["name"] ?? "") as String;
|
||||||
String role = (data["role"] ?? "") as String;
|
String role = (data["role"] ?? "") as String;
|
||||||
return ListTile(
|
return ListTile(title: Text(name), subtitle: Text(role));
|
||||||
title: Text(name),
|
|
||||||
subtitle: Text(role),
|
|
||||||
);
|
|
||||||
case InvenTreeCompany.MODEL_TYPE:
|
case InvenTreeCompany.MODEL_TYPE:
|
||||||
var company = InvenTreeCompany.fromJson(data);
|
var company = InvenTreeCompany.fromJson(data);
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(company.name),
|
title: Text(company.name),
|
||||||
subtitle: extended ? Text(company.description) : null,
|
subtitle: extended ? Text(company.description) : null,
|
||||||
leading: InvenTreeAPI().getThumbnail(company.thumbnail)
|
leading: InvenTreeAPI().getThumbnail(company.thumbnail),
|
||||||
);
|
);
|
||||||
case InvenTreeProjectCode.MODEL_TYPE:
|
case InvenTreeProjectCode.MODEL_TYPE:
|
||||||
var project_code = InvenTreeProjectCode.fromJson(data);
|
var project_code = InvenTreeProjectCode.fromJson(data);
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(project_code.code),
|
title: Text(project_code.code),
|
||||||
subtitle: Text(project_code.description),
|
subtitle: Text(project_code.description),
|
||||||
leading: Icon(TablerIcons.list)
|
leading: Icon(TablerIcons.list),
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
"Unsupported model",
|
"Unsupported model",
|
||||||
style: TextStyle(
|
style: TextStyle(fontWeight: FontWeight.bold, color: COLOR_DANGER),
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: COLOR_DANGER
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
subtitle: Text("Model '${model}' rendering not supported"),
|
subtitle: Text("Model '${model}' rendering not supported"),
|
||||||
);
|
);
|
||||||
@ -782,10 +777,8 @@ class APIFormField {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Construct a string input element
|
// Construct a string input element
|
||||||
Widget _constructString() {
|
Widget _constructString() {
|
||||||
|
|
||||||
if (readOnly) {
|
if (readOnly) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(label),
|
title: Text(label),
|
||||||
@ -821,7 +814,6 @@ class APIFormField {
|
|||||||
|
|
||||||
// Construct a boolean input element
|
// Construct a boolean input element
|
||||||
Widget _constructBoolean() {
|
Widget _constructBoolean() {
|
||||||
|
|
||||||
bool? initial_value;
|
bool? initial_value;
|
||||||
|
|
||||||
if (value is bool || value == null) {
|
if (value is bool || value == null) {
|
||||||
@ -860,15 +852,12 @@ class APIFormField {
|
|||||||
color: hasErrors() ? COLOR_DANGER : null,
|
color: hasErrors() ? COLOR_DANGER : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Extract field options from a returned OPTIONS request
|
* Extract field options from a returned OPTIONS request
|
||||||
*/
|
*/
|
||||||
Map<String, dynamic> extractFields(APIResponse response) {
|
Map<String, dynamic> extractFields(APIResponse response) {
|
||||||
|
|
||||||
if (!response.isValid()) {
|
if (!response.isValid()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -896,8 +885,10 @@ Map<String, dynamic> extractFields(APIResponse response) {
|
|||||||
* The map "tree" is traversed based on the provided lookup string, which can use dotted notation.
|
* The map "tree" is traversed based on the provided lookup string, which can use dotted notation.
|
||||||
* This allows complex paths to be used to lookup field information.
|
* This allows complex paths to be used to lookup field information.
|
||||||
*/
|
*/
|
||||||
Map<String, dynamic> extractFieldDefinition(Map<String, dynamic> data, String lookup) {
|
Map<String, dynamic> extractFieldDefinition(
|
||||||
|
Map<String, dynamic> data,
|
||||||
|
String lookup,
|
||||||
|
) {
|
||||||
List<String> path = lookup.split(".");
|
List<String> path = lookup.split(".");
|
||||||
|
|
||||||
// Shadow copy the data for path traversal
|
// Shadow copy the data for path traversal
|
||||||
@ -905,7 +896,6 @@ Map<String, dynamic> extractFieldDefinition(Map<String, dynamic> data, String lo
|
|||||||
|
|
||||||
// Iterate through all but the last element of the path
|
// Iterate through all but the last element of the path
|
||||||
for (int ii = 0; ii < (path.length - 1); ii++) {
|
for (int ii = 0; ii < (path.length - 1); ii++) {
|
||||||
|
|
||||||
String el = path[ii];
|
String el = path[ii];
|
||||||
|
|
||||||
if (!_data.containsKey(el)) {
|
if (!_data.containsKey(el)) {
|
||||||
@ -923,11 +913,9 @@ Map<String, dynamic> extractFieldDefinition(Map<String, dynamic> data, String lo
|
|||||||
// Report the error
|
// Report the error
|
||||||
sentryReportError(
|
sentryReportError(
|
||||||
"apiForm.extractFieldDefinition : path traversal",
|
"apiForm.extractFieldDefinition : path traversal",
|
||||||
error, stackTrace,
|
error,
|
||||||
context: {
|
stackTrace,
|
||||||
"path": path.toString(),
|
context: {"path": path.toString(), "el": el},
|
||||||
"el": el,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -938,7 +926,6 @@ Map<String, dynamic> extractFieldDefinition(Map<String, dynamic> data, String lo
|
|||||||
if (!_data.containsKey(el)) {
|
if (!_data.containsKey(el)) {
|
||||||
return {};
|
return {};
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Map<String, dynamic> definition = _data[el] as Map<String, dynamic>;
|
Map<String, dynamic> definition = _data[el] as Map<String, dynamic>;
|
||||||
|
|
||||||
@ -950,19 +937,16 @@ Map<String, dynamic> extractFieldDefinition(Map<String, dynamic> data, String lo
|
|||||||
// Report the error
|
// Report the error
|
||||||
sentryReportError(
|
sentryReportError(
|
||||||
"apiForm.extractFieldDefinition : as map",
|
"apiForm.extractFieldDefinition : as map",
|
||||||
error, stacktrace,
|
error,
|
||||||
context: {
|
stacktrace,
|
||||||
"el": el.toString(),
|
context: {"el": el.toString()},
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Launch an API-driven form,
|
* Launch an API-driven form,
|
||||||
* which uses the OPTIONS metadata (at the provided URL)
|
* which uses the OPTIONS metadata (at the provided URL)
|
||||||
@ -976,24 +960,24 @@ Map<String, dynamic> extractFieldDefinition(Map<String, dynamic> data, String lo
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Future<void> launchApiForm(
|
Future<void> launchApiForm(
|
||||||
BuildContext context, String title, String url, Map<String, dynamic> fields,
|
BuildContext context,
|
||||||
{
|
String title,
|
||||||
|
String url,
|
||||||
|
Map<String, dynamic> fields, {
|
||||||
String fileField = "",
|
String fileField = "",
|
||||||
Map<String, dynamic> modelData = const {},
|
Map<String, dynamic> modelData = const {},
|
||||||
String method = "PATCH",
|
String method = "PATCH",
|
||||||
Function(Map<String, dynamic>)? onSuccess,
|
Function(Map<String, dynamic>)? onSuccess,
|
||||||
bool Function(Map<String, dynamic>)? validate,
|
bool Function(Map<String, dynamic>)? validate,
|
||||||
Function? onCancel,
|
Function? onCancel,
|
||||||
IconData icon = TablerIcons.device_floppy
|
IconData icon = TablerIcons.device_floppy,
|
||||||
}) async {
|
}) async {
|
||||||
|
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
|
|
||||||
// List of fields defined by the server
|
// List of fields defined by the server
|
||||||
Map<String, dynamic> serverFields = {};
|
Map<String, dynamic> serverFields = {};
|
||||||
|
|
||||||
if (url.isNotEmpty) {
|
if (url.isNotEmpty) {
|
||||||
|
|
||||||
var options = await InvenTreeAPI().options(url);
|
var options = await InvenTreeAPI().options(url);
|
||||||
|
|
||||||
// Invalid response from server
|
// Invalid response from server
|
||||||
@ -1006,10 +990,7 @@ Future<void> launchApiForm(
|
|||||||
|
|
||||||
if (serverFields.isEmpty) {
|
if (serverFields.isEmpty) {
|
||||||
// User does not have permission to perform this action
|
// User does not have permission to perform this action
|
||||||
showSnackIcon(
|
showSnackIcon(L10().response403, icon: TablerIcons.user_x);
|
||||||
L10().response403,
|
|
||||||
icon: TablerIcons.user_x,
|
|
||||||
);
|
|
||||||
|
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
return;
|
return;
|
||||||
@ -1022,7 +1003,6 @@ Future<void> launchApiForm(
|
|||||||
APIFormField field;
|
APIFormField field;
|
||||||
|
|
||||||
for (String fieldName in fields.keys) {
|
for (String fieldName in fields.keys) {
|
||||||
|
|
||||||
dynamic data = fields[fieldName];
|
dynamic data = fields[fieldName];
|
||||||
|
|
||||||
Map<String, dynamic> fieldData = {};
|
Map<String, dynamic> fieldData = {};
|
||||||
@ -1066,7 +1046,8 @@ Future<void> launchApiForm(
|
|||||||
// Now, launch a new widget!
|
// Now, launch a new widget!
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => APIFormWidget(
|
MaterialPageRoute(
|
||||||
|
builder: (context) => APIFormWidget(
|
||||||
title,
|
title,
|
||||||
url,
|
url,
|
||||||
formFields,
|
formFields,
|
||||||
@ -1075,26 +1056,23 @@ Future<void> launchApiForm(
|
|||||||
validate: validate,
|
validate: validate,
|
||||||
fileField: fileField,
|
fileField: fileField,
|
||||||
icon: icon,
|
icon: icon,
|
||||||
))
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class APIFormWidget extends StatefulWidget {
|
class APIFormWidget extends StatefulWidget {
|
||||||
|
|
||||||
const APIFormWidget(
|
const APIFormWidget(
|
||||||
this.title,
|
this.title,
|
||||||
this.url,
|
this.url,
|
||||||
this.fields,
|
this.fields,
|
||||||
this.method,
|
this.method, {
|
||||||
{
|
|
||||||
Key? key,
|
Key? key,
|
||||||
this.onSuccess,
|
this.onSuccess,
|
||||||
this.validate,
|
this.validate,
|
||||||
this.fileField = "",
|
this.fileField = "",
|
||||||
this.icon = TablerIcons.device_floppy,
|
this.icon = TablerIcons.device_floppy,
|
||||||
}
|
}) : super(key: key);
|
||||||
) : super(key: key);
|
|
||||||
|
|
||||||
//! Form title to display
|
//! Form title to display
|
||||||
final String title;
|
final String title;
|
||||||
@ -1118,12 +1096,9 @@ class APIFormWidget extends StatefulWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
_APIFormWidgetState createState() => _APIFormWidgetState();
|
_APIFormWidgetState createState() => _APIFormWidgetState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _APIFormWidgetState extends State<APIFormWidget> {
|
class _APIFormWidgetState extends State<APIFormWidget> {
|
||||||
|
|
||||||
_APIFormWidgetState() : super();
|
_APIFormWidgetState() : super();
|
||||||
|
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
@ -1133,7 +1108,6 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
bool spacerRequired = false;
|
bool spacerRequired = false;
|
||||||
|
|
||||||
List<Widget> _buildForm() {
|
List<Widget> _buildForm() {
|
||||||
|
|
||||||
List<Widget> widgets = [];
|
List<Widget> widgets = [];
|
||||||
|
|
||||||
// Display non-field errors first
|
// Display non-field errors first
|
||||||
@ -1141,26 +1115,16 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
for (String error in nonFieldErrors) {
|
for (String error in nonFieldErrors) {
|
||||||
widgets.add(
|
widgets.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(
|
title: Text(error, style: TextStyle(color: COLOR_DANGER)),
|
||||||
error,
|
leading: Icon(TablerIcons.exclamation_circle, color: COLOR_DANGER),
|
||||||
style: TextStyle(
|
|
||||||
color: COLOR_DANGER,
|
|
||||||
),
|
),
|
||||||
),
|
|
||||||
leading: Icon(
|
|
||||||
TablerIcons.exclamation_circle,
|
|
||||||
color: COLOR_DANGER
|
|
||||||
),
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
widgets.add(Divider(height: 5));
|
widgets.add(Divider(height: 5));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var field in widget.fields) {
|
for (var field in widget.fields) {
|
||||||
|
|
||||||
if (field.hidden) {
|
if (field.hidden) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1189,8 +1153,8 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
fontStyle: FontStyle.italic,
|
fontStyle: FontStyle.italic,
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1210,20 +1174,16 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<APIResponse> _submit(Map<String, dynamic> data) async {
|
Future<APIResponse> _submit(Map<String, dynamic> data) async {
|
||||||
|
|
||||||
// If a file upload is required, we have to handle the submission differently
|
// If a file upload is required, we have to handle the submission differently
|
||||||
if (widget.fileField.isNotEmpty) {
|
if (widget.fileField.isNotEmpty) {
|
||||||
|
|
||||||
// Pop the "file" field
|
// Pop the "file" field
|
||||||
data.remove(widget.fileField);
|
data.remove(widget.fileField);
|
||||||
|
|
||||||
for (var field in widget.fields) {
|
for (var field in widget.fields) {
|
||||||
if (field.name == widget.fileField) {
|
if (field.name == widget.fileField) {
|
||||||
|
|
||||||
File? file = field.attachedfile;
|
File? file = field.attachedfile;
|
||||||
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
|
|
||||||
// A valid file has been supplied
|
// A valid file has been supplied
|
||||||
final response = await InvenTreeAPI().uploadFile(
|
final response = await InvenTreeAPI().uploadFile(
|
||||||
widget.url,
|
widget.url,
|
||||||
@ -1239,23 +1199,21 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (widget.method == "POST") {
|
if (widget.method == "POST") {
|
||||||
|
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
final response = await InvenTreeAPI().post(
|
final response = await InvenTreeAPI().post(
|
||||||
widget.url,
|
widget.url,
|
||||||
body: data,
|
body: data,
|
||||||
expectedStatusCode: null
|
expectedStatusCode: null,
|
||||||
);
|
);
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
final response = await InvenTreeAPI().patch(
|
final response = await InvenTreeAPI().patch(
|
||||||
widget.url,
|
widget.url,
|
||||||
body: data,
|
body: data,
|
||||||
expectedStatusCode: null
|
expectedStatusCode: null,
|
||||||
);
|
);
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
|
|
||||||
@ -1264,17 +1222,12 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void extractNonFieldErrors(APIResponse response) {
|
void extractNonFieldErrors(APIResponse response) {
|
||||||
|
|
||||||
List<String> errors = [];
|
List<String> errors = [];
|
||||||
|
|
||||||
Map<String, dynamic> data = response.asMap();
|
Map<String, dynamic> data = response.asMap();
|
||||||
|
|
||||||
// Potential keys representing non-field errors
|
// Potential keys representing non-field errors
|
||||||
List<String> keys = [
|
List<String> keys = ["__all__", "non_field_errors", "errors"];
|
||||||
"__all__",
|
|
||||||
"non_field_errors",
|
|
||||||
"errors",
|
|
||||||
];
|
|
||||||
|
|
||||||
for (String key in keys) {
|
for (String key in keys) {
|
||||||
if (data.containsKey(key)) {
|
if (data.containsKey(key)) {
|
||||||
@ -1301,7 +1254,6 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
var errors = response.asMap();
|
var errors = response.asMap();
|
||||||
|
|
||||||
for (String fieldName in errors.keys) {
|
for (String fieldName in errors.keys) {
|
||||||
|
|
||||||
bool match = false;
|
bool match = false;
|
||||||
|
|
||||||
switch (fieldName) {
|
switch (fieldName) {
|
||||||
@ -1313,7 +1265,6 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
for (var field in widget.fields) {
|
for (var field in widget.fields) {
|
||||||
|
|
||||||
// Hidden fields can't display errors, so we won't match
|
// Hidden fields can't display errors, so we won't match
|
||||||
if (field.hidden) {
|
if (field.hidden) {
|
||||||
continue;
|
continue;
|
||||||
@ -1324,7 +1275,6 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
match = true;
|
match = true;
|
||||||
break;
|
break;
|
||||||
} else if (field.parent == fieldName) {
|
} else if (field.parent == fieldName) {
|
||||||
|
|
||||||
var error = errors[fieldName];
|
var error = errors[fieldName];
|
||||||
|
|
||||||
if (error is List) {
|
if (error is List) {
|
||||||
@ -1340,7 +1290,6 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!match) {
|
if (!match) {
|
||||||
@ -1352,7 +1301,7 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
"status_code": response.statusCode.toString(),
|
"status_code": response.statusCode.toString(),
|
||||||
"field": fieldName,
|
"field": fieldName,
|
||||||
"error_message": response.data.toString(),
|
"error_message": response.data.toString(),
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1362,14 +1311,12 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
* Submit the form data to the server, and handle the results
|
* Submit the form data to the server, and handle the results
|
||||||
*/
|
*/
|
||||||
Future<void> _save(BuildContext context) async {
|
Future<void> _save(BuildContext context) async {
|
||||||
|
|
||||||
// Package up the form data
|
// Package up the form data
|
||||||
Map<String, dynamic> data = {};
|
Map<String, dynamic> data = {};
|
||||||
|
|
||||||
// Iterate through and find "simple" top-level fields
|
// Iterate through and find "simple" top-level fields
|
||||||
|
|
||||||
for (var field in widget.fields) {
|
for (var field in widget.fields) {
|
||||||
|
|
||||||
if (field.readOnly) {
|
if (field.readOnly) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1380,7 +1327,6 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
} else {
|
} else {
|
||||||
// Not so simple... (WHY DID I MAKE THE API SO COMPLEX?)
|
// Not so simple... (WHY DID I MAKE THE API SO COMPLEX?)
|
||||||
if (field.parent.isNotEmpty) {
|
if (field.parent.isNotEmpty) {
|
||||||
|
|
||||||
// TODO: This is a dirty hack, there *must* be a cleaner way?!
|
// TODO: This is a dirty hack, there *must* be a cleaner way?!
|
||||||
|
|
||||||
dynamic parent = data[field.parent] ?? {};
|
dynamic parent = data[field.parent] ?? {};
|
||||||
@ -1442,7 +1388,6 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
|
|
||||||
if (successFunc != null) {
|
if (successFunc != null) {
|
||||||
|
|
||||||
// Ensure the response is a valid JSON structure
|
// Ensure the response is a valid JSON structure
|
||||||
Map<String, dynamic> json = {};
|
Map<String, dynamic> json = {};
|
||||||
|
|
||||||
@ -1457,10 +1402,7 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
return;
|
return;
|
||||||
case 400:
|
case 400:
|
||||||
// Form submission / validation error
|
// Form submission / validation error
|
||||||
showSnackIcon(
|
showSnackIcon(L10().formError, success: false);
|
||||||
L10().formError,
|
|
||||||
success: false,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Update field errors
|
// Update field errors
|
||||||
for (var field in widget.fields) {
|
for (var field in widget.fields) {
|
||||||
@ -1470,30 +1412,15 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
extractNonFieldErrors(response);
|
extractNonFieldErrors(response);
|
||||||
checkInvalidErrors(response);
|
checkInvalidErrors(response);
|
||||||
case 401:
|
case 401:
|
||||||
showSnackIcon(
|
showSnackIcon("401: " + L10().response401, success: false);
|
||||||
"401: " + L10().response401,
|
|
||||||
success: false
|
|
||||||
);
|
|
||||||
case 403:
|
case 403:
|
||||||
showSnackIcon(
|
showSnackIcon("403: " + L10().response403, success: false);
|
||||||
"403: " + L10().response403,
|
|
||||||
success: false,
|
|
||||||
);
|
|
||||||
case 404:
|
case 404:
|
||||||
showSnackIcon(
|
showSnackIcon("404: " + L10().response404, success: false);
|
||||||
"404: " + L10().response404,
|
|
||||||
success: false,
|
|
||||||
);
|
|
||||||
case 405:
|
case 405:
|
||||||
showSnackIcon(
|
showSnackIcon("405: " + L10().response405, success: false);
|
||||||
"405: " + L10().response405,
|
|
||||||
success: false,
|
|
||||||
);
|
|
||||||
case 500:
|
case 500:
|
||||||
showSnackIcon(
|
showSnackIcon("500: " + L10().response500, success: false);
|
||||||
"500: " + L10().response500,
|
|
||||||
success: false,
|
|
||||||
);
|
|
||||||
default:
|
default:
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
"${response.statusCode}: " + L10().responseInvalid,
|
"${response.statusCode}: " + L10().responseInvalid,
|
||||||
@ -1504,12 +1431,10 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
// Refresh the form
|
// Refresh the form
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(widget.title),
|
title: Text(widget.title),
|
||||||
@ -1518,15 +1443,14 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(widget.icon),
|
icon: Icon(widget.icon),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
|
||||||
if (_formKey.currentState!.validate()) {
|
if (_formKey.currentState!.validate()) {
|
||||||
_formKey.currentState!.save();
|
_formKey.currentState!.save();
|
||||||
|
|
||||||
_save(context);
|
_save(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
]
|
],
|
||||||
),
|
),
|
||||||
body: Form(
|
body: Form(
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
@ -1538,9 +1462,8 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
children: _buildForm(),
|
children: _buildForm(),
|
||||||
),
|
),
|
||||||
padding: EdgeInsets.all(16),
|
padding: EdgeInsets.all(16),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import "package:inventree/helpers.dart";
|
|||||||
import "package:one_context/one_context.dart";
|
import "package:one_context/one_context.dart";
|
||||||
|
|
||||||
bool isDarkMode() {
|
bool isDarkMode() {
|
||||||
|
|
||||||
if (!hasContext()) {
|
if (!hasContext()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import "package:inventree/widget/company/manufacturer_part_detail.dart";
|
|||||||
import "package:inventree/widget/order/sales_order_detail.dart";
|
import "package:inventree/widget/order/sales_order_detail.dart";
|
||||||
import "package:one_context/one_context.dart";
|
import "package:one_context/one_context.dart";
|
||||||
|
|
||||||
|
|
||||||
import "package:inventree/api.dart";
|
import "package:inventree/api.dart";
|
||||||
import "package:inventree/l10.dart";
|
import "package:inventree/l10.dart";
|
||||||
|
|
||||||
@ -35,10 +34,8 @@ import "package:inventree/widget/stock/stock_detail.dart";
|
|||||||
import "package:inventree/widget/company/company_detail.dart";
|
import "package:inventree/widget/company/company_detail.dart";
|
||||||
import "package:inventree/widget/company/supplier_part_detail.dart";
|
import "package:inventree/widget/company/supplier_part_detail.dart";
|
||||||
|
|
||||||
|
|
||||||
// Signal a barcode scan success to the user
|
// Signal a barcode scan success to the user
|
||||||
Future<void> barcodeSuccess(String msg) async {
|
Future<void> barcodeSuccess(String msg) async {
|
||||||
|
|
||||||
barcodeSuccessTone();
|
barcodeSuccessTone();
|
||||||
showSnackIcon(msg, success: true);
|
showSnackIcon(msg, success: true);
|
||||||
}
|
}
|
||||||
@ -52,19 +49,18 @@ Future<void> barcodeFailure(String msg, dynamic extra) async {
|
|||||||
onAction: () {
|
onAction: () {
|
||||||
if (hasContext()) {
|
if (hasContext()) {
|
||||||
OneContext().showDialog(
|
OneContext().showDialog(
|
||||||
builder: (BuildContext context) =>
|
builder: (BuildContext context) => SimpleDialog(
|
||||||
SimpleDialog(
|
|
||||||
title: Text(L10().barcodeError),
|
title: Text(L10().barcodeError),
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().responseData),
|
title: Text(L10().responseData),
|
||||||
subtitle: Text(extra.toString())
|
subtitle: Text(extra.toString()),
|
||||||
)
|
),
|
||||||
]
|
],
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,15 +71,22 @@ Future<void> barcodeFailure(String msg, dynamic extra) async {
|
|||||||
* - Returns a Future which resolves when the scanner is dismissed
|
* - Returns a Future which resolves when the scanner is dismissed
|
||||||
* - The provided BarcodeHandler instance is used to handle the scanned barcode
|
* - The provided BarcodeHandler instance is used to handle the scanned barcode
|
||||||
*/
|
*/
|
||||||
Future<Object?> scanBarcode(BuildContext context, {BarcodeHandler? handler}) async {
|
Future<Object?> scanBarcode(
|
||||||
|
BuildContext context, {
|
||||||
|
BarcodeHandler? handler,
|
||||||
|
}) async {
|
||||||
// Default to generic scan handler
|
// Default to generic scan handler
|
||||||
handler ??= BarcodeScanHandler();
|
handler ??= BarcodeScanHandler();
|
||||||
|
|
||||||
InvenTreeBarcodeController controller = CameraBarcodeController(handler);
|
InvenTreeBarcodeController controller = CameraBarcodeController(handler);
|
||||||
|
|
||||||
// Select barcode controller based on user preference
|
// Select barcode controller based on user preference
|
||||||
final int barcodeControllerType = await InvenTreeSettingsManager().getValue(INV_BARCODE_SCAN_TYPE, BARCODE_CONTROLLER_CAMERA) as int;
|
final int barcodeControllerType =
|
||||||
|
await InvenTreeSettingsManager().getValue(
|
||||||
|
INV_BARCODE_SCAN_TYPE,
|
||||||
|
BARCODE_CONTROLLER_CAMERA,
|
||||||
|
)
|
||||||
|
as int;
|
||||||
|
|
||||||
switch (barcodeControllerType) {
|
switch (barcodeControllerType) {
|
||||||
case BARCODE_CONTROLLER_WEDGE:
|
case BARCODE_CONTROLLER_WEDGE:
|
||||||
@ -95,14 +98,10 @@ Future<Object?> scanBarcode(BuildContext context, {BarcodeHandler? handler}) asy
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Navigator.of(context).push(
|
return Navigator.of(context).push(
|
||||||
PageRouteBuilder(
|
PageRouteBuilder(pageBuilder: (context, _, _) => controller, opaque: false),
|
||||||
pageBuilder: (context, _, _) => controller,
|
|
||||||
opaque: false,
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class for general barcode scanning.
|
* Class for general barcode scanning.
|
||||||
* Scan *any* barcode without context, and then redirect app to correct view.
|
* Scan *any* barcode without context, and then redirect app to correct view.
|
||||||
@ -116,13 +115,11 @@ Future<Object?> scanBarcode(BuildContext context, {BarcodeHandler? handler}) asy
|
|||||||
* - PurchaseOrder
|
* - PurchaseOrder
|
||||||
*/
|
*/
|
||||||
class BarcodeScanHandler extends BarcodeHandler {
|
class BarcodeScanHandler extends BarcodeHandler {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getOverlayText(BuildContext context) => L10().barcodeScanGeneral;
|
String getOverlayText(BuildContext context) => L10().barcodeScanGeneral;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onBarcodeUnknown(Map<String, dynamic> data) async {
|
Future<void> onBarcodeUnknown(Map<String, dynamic> data) async {
|
||||||
|
|
||||||
barcodeFailureTone();
|
barcodeFailureTone();
|
||||||
|
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
@ -136,12 +133,13 @@ class BarcodeScanHandler extends BarcodeHandler {
|
|||||||
* Response when a "Part" instance is scanned
|
* Response when a "Part" instance is scanned
|
||||||
*/
|
*/
|
||||||
Future<void> handlePart(int pk) async {
|
Future<void> handlePart(int pk) async {
|
||||||
|
|
||||||
var part = await InvenTreePart().get(pk);
|
var part = await InvenTreePart().get(pk);
|
||||||
|
|
||||||
if (part is InvenTreePart) {
|
if (part is InvenTreePart) {
|
||||||
OneContext().pop();
|
OneContext().pop();
|
||||||
OneContext().push(MaterialPageRoute(builder: (context) => PartDetailWidget(part)));
|
OneContext().push(
|
||||||
|
MaterialPageRoute(builder: (context) => PartDetailWidget(part)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,13 +147,13 @@ class BarcodeScanHandler extends BarcodeHandler {
|
|||||||
* Response when a "StockItem" instance is scanned
|
* Response when a "StockItem" instance is scanned
|
||||||
*/
|
*/
|
||||||
Future<void> handleStockItem(int pk) async {
|
Future<void> handleStockItem(int pk) async {
|
||||||
|
|
||||||
var item = await InvenTreeStockItem().get(pk);
|
var item = await InvenTreeStockItem().get(pk);
|
||||||
|
|
||||||
if (item is InvenTreeStockItem) {
|
if (item is InvenTreeStockItem) {
|
||||||
OneContext().pop();
|
OneContext().pop();
|
||||||
OneContext().push(MaterialPageRoute(
|
OneContext().push(
|
||||||
builder: (context) => StockDetailWidget(item)));
|
MaterialPageRoute(builder: (context) => StockDetailWidget(item)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,13 +161,13 @@ class BarcodeScanHandler extends BarcodeHandler {
|
|||||||
* Response when a "StockLocation" instance is scanned
|
* Response when a "StockLocation" instance is scanned
|
||||||
*/
|
*/
|
||||||
Future<void> handleStockLocation(int pk) async {
|
Future<void> handleStockLocation(int pk) async {
|
||||||
|
|
||||||
var loc = await InvenTreeStockLocation().get(pk);
|
var loc = await InvenTreeStockLocation().get(pk);
|
||||||
|
|
||||||
if (loc is InvenTreeStockLocation) {
|
if (loc is InvenTreeStockLocation) {
|
||||||
OneContext().pop();
|
OneContext().pop();
|
||||||
OneContext().navigator.push(MaterialPageRoute(
|
OneContext().navigator.push(
|
||||||
builder: (context) => LocationDisplayWidget(loc)));
|
MaterialPageRoute(builder: (context) => LocationDisplayWidget(loc)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,13 +175,15 @@ class BarcodeScanHandler extends BarcodeHandler {
|
|||||||
* Response when a "SupplierPart" instance is scanned
|
* Response when a "SupplierPart" instance is scanned
|
||||||
*/
|
*/
|
||||||
Future<void> handleSupplierPart(int pk) async {
|
Future<void> handleSupplierPart(int pk) async {
|
||||||
|
|
||||||
var supplierPart = await InvenTreeSupplierPart().get(pk);
|
var supplierPart = await InvenTreeSupplierPart().get(pk);
|
||||||
|
|
||||||
if (supplierPart is InvenTreeSupplierPart) {
|
if (supplierPart is InvenTreeSupplierPart) {
|
||||||
OneContext().pop();
|
OneContext().pop();
|
||||||
OneContext().push(MaterialPageRoute(
|
OneContext().push(
|
||||||
builder: (context) => SupplierPartDetailWidget(supplierPart)));
|
MaterialPageRoute(
|
||||||
|
builder: (context) => SupplierPartDetailWidget(supplierPart),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,8 +195,11 @@ class BarcodeScanHandler extends BarcodeHandler {
|
|||||||
|
|
||||||
if (manufacturerPart is InvenTreeManufacturerPart) {
|
if (manufacturerPart is InvenTreeManufacturerPart) {
|
||||||
OneContext().pop();
|
OneContext().pop();
|
||||||
OneContext().push(MaterialPageRoute(
|
OneContext().push(
|
||||||
builder: (context) => ManufacturerPartDetailWidget(manufacturerPart)));
|
MaterialPageRoute(
|
||||||
|
builder: (context) => ManufacturerPartDetailWidget(manufacturerPart),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,8 +208,9 @@ class BarcodeScanHandler extends BarcodeHandler {
|
|||||||
|
|
||||||
if (company is InvenTreeCompany) {
|
if (company is InvenTreeCompany) {
|
||||||
OneContext().pop();
|
OneContext().pop();
|
||||||
OneContext().push(MaterialPageRoute(
|
OneContext().push(
|
||||||
builder: (context) => CompanyDetailWidget(company)));
|
MaterialPageRoute(builder: (context) => CompanyDetailWidget(company)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,8 +222,11 @@ class BarcodeScanHandler extends BarcodeHandler {
|
|||||||
|
|
||||||
if (order is InvenTreePurchaseOrder) {
|
if (order is InvenTreePurchaseOrder) {
|
||||||
OneContext().pop();
|
OneContext().pop();
|
||||||
OneContext().push(MaterialPageRoute(
|
OneContext().push(
|
||||||
builder: (context) => PurchaseOrderDetailWidget(order)));
|
MaterialPageRoute(
|
||||||
|
builder: (context) => PurchaseOrderDetailWidget(order),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,8 +236,9 @@ class BarcodeScanHandler extends BarcodeHandler {
|
|||||||
|
|
||||||
if (order is InvenTreeSalesOrder) {
|
if (order is InvenTreeSalesOrder) {
|
||||||
OneContext().pop();
|
OneContext().pop();
|
||||||
OneContext().push(MaterialPageRoute(
|
OneContext().push(
|
||||||
builder: (context) => SalesOrderDetailWidget(order)));
|
MaterialPageRoute(builder: (context) => SalesOrderDetailWidget(order)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +258,6 @@ class BarcodeScanHandler extends BarcodeHandler {
|
|||||||
InvenTreeManufacturerPart.MODEL_TYPE,
|
InvenTreeManufacturerPart.MODEL_TYPE,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
if (InvenTreeAPI().supportsOrderBarcodes) {
|
if (InvenTreeAPI().supportsOrderBarcodes) {
|
||||||
validModels.add(InvenTreePurchaseOrder.MODEL_TYPE);
|
validModels.add(InvenTreePurchaseOrder.MODEL_TYPE);
|
||||||
validModels.add(InvenTreeSalesOrder.MODEL_TYPE);
|
validModels.add(InvenTreeSalesOrder.MODEL_TYPE);
|
||||||
@ -274,7 +281,6 @@ class BarcodeScanHandler extends BarcodeHandler {
|
|||||||
|
|
||||||
// A valid result has been found
|
// A valid result has been found
|
||||||
if (pk > 0 && model.isNotEmpty) {
|
if (pk > 0 && model.isNotEmpty) {
|
||||||
|
|
||||||
barcodeSuccessTone();
|
barcodeSuccessTone();
|
||||||
|
|
||||||
switch (model) {
|
switch (model) {
|
||||||
@ -315,32 +321,28 @@ class BarcodeScanHandler extends BarcodeHandler {
|
|||||||
L10().barcodeUnknown,
|
L10().barcodeUnknown,
|
||||||
success: false,
|
success: false,
|
||||||
onAction: () {
|
onAction: () {
|
||||||
|
|
||||||
if (hasContext()) {
|
if (hasContext()) {
|
||||||
OneContext().showDialog(
|
OneContext().showDialog(
|
||||||
builder: (BuildContext context) =>
|
builder: (BuildContext context) => SimpleDialog(
|
||||||
SimpleDialog(
|
|
||||||
title: Text(L10().unknownResponse),
|
title: Text(L10().unknownResponse),
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().responseData),
|
title: Text(L10().responseData),
|
||||||
subtitle: Text(data.toString()),
|
subtitle: Text(data.toString()),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
)
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Barcode handler for finding a "unique" barcode (one that does not match an item in the database)
|
* Barcode handler for finding a "unique" barcode (one that does not match an item in the database)
|
||||||
*/
|
*/
|
||||||
class UniqueBarcodeHandler extends BarcodeHandler {
|
class UniqueBarcodeHandler extends BarcodeHandler {
|
||||||
|
|
||||||
UniqueBarcodeHandler(this.callback, {this.overlayText = ""});
|
UniqueBarcodeHandler(this.callback, {this.overlayText = ""});
|
||||||
|
|
||||||
// Callback function when a "unique" barcode hash is found
|
// Callback function when a "unique" barcode hash is found
|
||||||
@ -360,11 +362,7 @@ class UniqueBarcodeHandler extends BarcodeHandler {
|
|||||||
@override
|
@override
|
||||||
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
|
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
|
||||||
if (!data.containsKey("hash") && !data.containsKey("barcode_hash")) {
|
if (!data.containsKey("hash") && !data.containsKey("barcode_hash")) {
|
||||||
showServerError(
|
showServerError("barcode/", L10().missingData, L10().barcodeMissingHash);
|
||||||
"barcode/",
|
|
||||||
L10().missingData,
|
|
||||||
L10().barcodeMissingHash,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
String barcode;
|
String barcode;
|
||||||
|
|
||||||
@ -373,12 +371,8 @@ class UniqueBarcodeHandler extends BarcodeHandler {
|
|||||||
if (barcode.isEmpty) {
|
if (barcode.isEmpty) {
|
||||||
barcodeFailureTone();
|
barcodeFailureTone();
|
||||||
|
|
||||||
showSnackIcon(
|
showSnackIcon(L10().barcodeError, success: false);
|
||||||
L10().barcodeError,
|
|
||||||
success: false,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
barcodeSuccessTone();
|
barcodeSuccessTone();
|
||||||
|
|
||||||
// Close the barcode scanner
|
// Close the barcode scanner
|
||||||
@ -395,41 +389,43 @@ class UniqueBarcodeHandler extends BarcodeHandler {
|
|||||||
Future<void> onBarcodeUnknown(Map<String, dynamic> data) async {
|
Future<void> onBarcodeUnknown(Map<String, dynamic> data) async {
|
||||||
await onBarcodeMatched(data);
|
await onBarcodeMatched(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SpeedDialChild customBarcodeAction(
|
||||||
SpeedDialChild customBarcodeAction(BuildContext context, RefreshableState state, String barcode, String model, int pk) {
|
BuildContext context,
|
||||||
|
RefreshableState state,
|
||||||
|
String barcode,
|
||||||
|
String model,
|
||||||
|
int pk,
|
||||||
|
) {
|
||||||
if (barcode.isEmpty) {
|
if (barcode.isEmpty) {
|
||||||
return SpeedDialChild(
|
return SpeedDialChild(
|
||||||
label: L10().barcodeAssign,
|
label: L10().barcodeAssign,
|
||||||
child: Icon(Icons.barcode_reader),
|
child: Icon(Icons.barcode_reader),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
var handler = UniqueBarcodeHandler((String barcode) {
|
var handler = UniqueBarcodeHandler((String barcode) {
|
||||||
InvenTreeAPI().linkBarcode({
|
InvenTreeAPI()
|
||||||
model: pk.toString(),
|
.linkBarcode({model: pk.toString(), "barcode": barcode})
|
||||||
"barcode": barcode,
|
.then((bool result) {
|
||||||
}).then((bool result) {
|
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
result ? L10().barcodeAssigned : L10().barcodeNotAssigned,
|
result ? L10().barcodeAssigned : L10().barcodeNotAssigned,
|
||||||
success: result
|
success: result,
|
||||||
);
|
);
|
||||||
|
|
||||||
state.refresh(context);
|
state.refresh(context);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
scanBarcode(context, handler: handler);
|
scanBarcode(context, handler: handler);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return SpeedDialChild(
|
return SpeedDialChild(
|
||||||
child: Icon(Icons.barcode_reader),
|
child: Icon(Icons.barcode_reader),
|
||||||
label: L10().barcodeUnassign,
|
label: L10().barcodeUnassign,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
InvenTreeAPI().unlinkBarcode({
|
InvenTreeAPI().unlinkBarcode({model: pk.toString()}).then((
|
||||||
model: pk.toString()
|
bool result,
|
||||||
}).then((bool result) {
|
) {
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
result ? L10().requestSuccessful : L10().requestFailed,
|
result ? L10().requestSuccessful : L10().requestFailed,
|
||||||
success: result,
|
success: result,
|
||||||
@ -437,7 +433,7 @@ SpeedDialChild customBarcodeAction(BuildContext context, RefreshableState state,
|
|||||||
|
|
||||||
state.refresh(context);
|
state.refresh(context);
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -273,8 +273,9 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget bottomCenterOverlay() {
|
Widget bottomCenterOverlay() {
|
||||||
String info_text =
|
String info_text = scanning_paused
|
||||||
scanning_paused ? L10().barcodeScanPaused : L10().barcodeScanPause;
|
? L10().barcodeScanPaused
|
||||||
|
: L10().barcodeScanPause;
|
||||||
|
|
||||||
String text = scanned_code.isNotEmpty ? scanned_code : info_text;
|
String text = scanned_code.isNotEmpty ? scanned_code : info_text;
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ import "package:inventree/widget/progress.dart";
|
|||||||
* which is used to process the scanned barcode.
|
* which is used to process the scanned barcode.
|
||||||
*/
|
*/
|
||||||
class InvenTreeBarcodeController extends StatefulWidget {
|
class InvenTreeBarcodeController extends StatefulWidget {
|
||||||
|
|
||||||
const InvenTreeBarcodeController(this.handler, {Key? key}) : super(key: key);
|
const InvenTreeBarcodeController(this.handler, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
final BarcodeHandler handler;
|
final BarcodeHandler handler;
|
||||||
@ -20,16 +19,17 @@ class InvenTreeBarcodeController extends StatefulWidget {
|
|||||||
State<StatefulWidget> createState() => InvenTreeBarcodeControllerState();
|
State<StatefulWidget> createState() => InvenTreeBarcodeControllerState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Base state widget for the barcode controller.
|
* Base state widget for the barcode controller.
|
||||||
* This defines the basic interface for the barcode controller.
|
* This defines the basic interface for the barcode controller.
|
||||||
*/
|
*/
|
||||||
class InvenTreeBarcodeControllerState extends State<InvenTreeBarcodeController> {
|
class InvenTreeBarcodeControllerState
|
||||||
|
extends State<InvenTreeBarcodeController> {
|
||||||
InvenTreeBarcodeControllerState() : super();
|
InvenTreeBarcodeControllerState() : super();
|
||||||
|
|
||||||
final GlobalKey barcodeControllerKey = GlobalKey(debugLabel: "barcodeController");
|
final GlobalKey barcodeControllerKey = GlobalKey(
|
||||||
|
debugLabel: "barcodeController",
|
||||||
|
);
|
||||||
|
|
||||||
// Internal state flag to test if we are currently processing a barcode
|
// Internal state flag to test if we are currently processing a barcode
|
||||||
bool processingBarcode = false;
|
bool processingBarcode = false;
|
||||||
@ -40,7 +40,6 @@ class InvenTreeBarcodeControllerState extends State<InvenTreeBarcodeController>
|
|||||||
* Barcode data should be passed as a string
|
* Barcode data should be passed as a string
|
||||||
*/
|
*/
|
||||||
Future<void> handleBarcodeData(String? data) async {
|
Future<void> handleBarcodeData(String? data) async {
|
||||||
|
|
||||||
// Check that the data is valid, and this view is still mounted
|
// Check that the data is valid, and this view is still mounted
|
||||||
if (!mounted || data == null || data.isEmpty) {
|
if (!mounted || data == null || data.isEmpty) {
|
||||||
return;
|
return;
|
||||||
@ -66,7 +65,9 @@ class InvenTreeBarcodeControllerState extends State<InvenTreeBarcodeController>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int delay = await InvenTreeSettingsManager().getValue(INV_BARCODE_SCAN_DELAY, 500) as int;
|
int delay =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_BARCODE_SCAN_DELAY, 500)
|
||||||
|
as int;
|
||||||
|
|
||||||
Future.delayed(Duration(milliseconds: delay), () {
|
Future.delayed(Duration(milliseconds: delay), () {
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
@ -99,5 +100,4 @@ class InvenTreeBarcodeControllerState extends State<InvenTreeBarcodeController>
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container();
|
return Container();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||||
|
|
||||||
@ -13,7 +12,6 @@ import "package:inventree/inventree/sentry.dart";
|
|||||||
import "package:inventree/widget/dialogs.dart";
|
import "package:inventree/widget/dialogs.dart";
|
||||||
import "package:inventree/widget/snacks.dart";
|
import "package:inventree/widget/snacks.dart";
|
||||||
|
|
||||||
|
|
||||||
/* Generic class which "handles" a barcode, by communicating with the InvenTree server,
|
/* Generic class which "handles" a barcode, by communicating with the InvenTree server,
|
||||||
* and handling match / unknown / error cases.
|
* and handling match / unknown / error cases.
|
||||||
*
|
*
|
||||||
@ -21,7 +19,6 @@ import "package:inventree/widget/snacks.dart";
|
|||||||
* based on the response returned from the InvenTree server
|
* based on the response returned from the InvenTree server
|
||||||
*/
|
*/
|
||||||
class BarcodeHandler {
|
class BarcodeHandler {
|
||||||
|
|
||||||
BarcodeHandler();
|
BarcodeHandler();
|
||||||
|
|
||||||
// Return the text to display on the barcode overlay
|
// Return the text to display on the barcode overlay
|
||||||
@ -57,23 +54,23 @@ class BarcodeHandler {
|
|||||||
*
|
*
|
||||||
* Returns true only if the barcode scanner should remain open
|
* Returns true only if the barcode scanner should remain open
|
||||||
*/
|
*/
|
||||||
Future<void> processBarcode(String barcode,
|
Future<void> processBarcode(
|
||||||
{String url = "barcode/",
|
String barcode, {
|
||||||
Map<String, dynamic> extra_data = const {}}) async {
|
String url = "barcode/",
|
||||||
|
Map<String, dynamic> extra_data = const {},
|
||||||
|
}) async {
|
||||||
debug("Scanned barcode data: '${barcode}'");
|
debug("Scanned barcode data: '${barcode}'");
|
||||||
|
|
||||||
barcode = barcode.trim();
|
barcode = barcode.trim();
|
||||||
|
|
||||||
// Empty barcode is invalid
|
// Empty barcode is invalid
|
||||||
if (barcode.isEmpty) {
|
if (barcode.isEmpty) {
|
||||||
|
|
||||||
barcodeFailureTone();
|
barcodeFailureTone();
|
||||||
|
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
L10().barcodeError,
|
L10().barcodeError,
|
||||||
icon: TablerIcons.exclamation_circle,
|
icon: TablerIcons.exclamation_circle,
|
||||||
success: false
|
success: false,
|
||||||
);
|
);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -84,10 +81,7 @@ class BarcodeHandler {
|
|||||||
try {
|
try {
|
||||||
response = await InvenTreeAPI().post(
|
response = await InvenTreeAPI().post(
|
||||||
url,
|
url,
|
||||||
body: {
|
body: {"barcode": barcode, ...extra_data},
|
||||||
"barcode": barcode,
|
|
||||||
...extra_data,
|
|
||||||
},
|
|
||||||
expectedStatusCode: null, // Do not show an error on "unexpected code"
|
expectedStatusCode: null, // Do not show an error on "unexpected code"
|
||||||
);
|
);
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
@ -123,7 +117,7 @@ class BarcodeHandler {
|
|||||||
"error": response.error,
|
"error": response.error,
|
||||||
"errorDetail": response.errorDetail,
|
"errorDetail": response.errorDetail,
|
||||||
"className": "${this}",
|
"className": "${this}",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
} else if (data.containsKey("success")) {
|
} else if (data.containsKey("success")) {
|
||||||
await onBarcodeMatched(data);
|
await onBarcodeMatched(data);
|
||||||
|
@ -20,7 +20,6 @@ import "package:inventree/widget/snacks.dart";
|
|||||||
* - If location or quantity information wasn't provided, show a form to fill it in
|
* - If location or quantity information wasn't provided, show a form to fill it in
|
||||||
*/
|
*/
|
||||||
class POReceiveBarcodeHandler extends BarcodeHandler {
|
class POReceiveBarcodeHandler extends BarcodeHandler {
|
||||||
|
|
||||||
POReceiveBarcodeHandler({this.purchaseOrder, this.location, this.lineItem});
|
POReceiveBarcodeHandler({this.purchaseOrder, this.location, this.lineItem});
|
||||||
|
|
||||||
InvenTreePurchaseOrder? purchaseOrder;
|
InvenTreePurchaseOrder? purchaseOrder;
|
||||||
@ -31,11 +30,15 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
|
|||||||
String getOverlayText(BuildContext context) => L10().barcodeReceivePart;
|
String getOverlayText(BuildContext context) => L10().barcodeReceivePart;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> processBarcode(String barcode,
|
Future<void> processBarcode(
|
||||||
{String url = "barcode/po-receive/",
|
String barcode, {
|
||||||
Map<String, dynamic> extra_data = const {}}) async {
|
String url = "barcode/po-receive/",
|
||||||
|
Map<String, dynamic> extra_data = const {},
|
||||||
final bool confirm = await InvenTreeSettingsManager().getBool(INV_PO_CONFIRM_SCAN, true);
|
}) async {
|
||||||
|
final bool confirm = await InvenTreeSettingsManager().getBool(
|
||||||
|
INV_PO_CONFIRM_SCAN,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
final po_extra_data = {
|
final po_extra_data = {
|
||||||
"purchase_order": purchaseOrder?.pk,
|
"purchase_order": purchaseOrder?.pk,
|
||||||
@ -50,7 +53,6 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
|
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
|
||||||
|
|
||||||
if (data.containsKey("lineitem") || data.containsKey("success")) {
|
if (data.containsKey("lineitem") || data.containsKey("success")) {
|
||||||
barcodeSuccess(L10().receivedItem);
|
barcodeSuccess(L10().receivedItem);
|
||||||
return;
|
return;
|
||||||
@ -66,7 +68,8 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final lineItemData = data["lineitem"] as Map<String, dynamic>;
|
final lineItemData = data["lineitem"] as Map<String, dynamic>;
|
||||||
if (!lineItemData.containsKey("pk") || !lineItemData.containsKey("purchase_order")) {
|
if (!lineItemData.containsKey("pk") ||
|
||||||
|
!lineItemData.containsKey("purchase_order")) {
|
||||||
barcodeFailureTone();
|
barcodeFailureTone();
|
||||||
showSnackIcon(L10().missingData, success: false);
|
showSnackIcon(L10().missingData, success: false);
|
||||||
}
|
}
|
||||||
@ -79,7 +82,8 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InvenTreePOLineItem? lineItem = await InvenTreePOLineItem().get(lineItemId) as InvenTreePOLineItem?;
|
InvenTreePOLineItem? lineItem =
|
||||||
|
await InvenTreePOLineItem().get(lineItemId) as InvenTreePOLineItem?;
|
||||||
|
|
||||||
if (lineItem == null) {
|
if (lineItem == null) {
|
||||||
barcodeFailureTone();
|
barcodeFailureTone();
|
||||||
@ -89,7 +93,9 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
|
|||||||
// Next, extract the "optional" fields
|
// Next, extract the "optional" fields
|
||||||
|
|
||||||
// Extract information from the returned server response
|
// Extract information from the returned server response
|
||||||
double? quantity = double.tryParse((lineItemData["quantity"] ?? "0").toString());
|
double? quantity = double.tryParse(
|
||||||
|
(lineItemData["quantity"] ?? "0").toString(),
|
||||||
|
);
|
||||||
int? destination = lineItemData["location"] as int?;
|
int? destination = lineItemData["location"] as int?;
|
||||||
String? barcode = data["barcode_data"] as String?;
|
String? barcode = data["barcode_data"] as String?;
|
||||||
|
|
||||||
@ -105,7 +111,7 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
|
|||||||
barcode: barcode,
|
barcode: barcode,
|
||||||
onSuccess: () {
|
onSuccess: () {
|
||||||
showSnackIcon(L10().receivedItem, success: true);
|
showSnackIcon(L10().receivedItem, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,17 +120,15 @@ class POReceiveBarcodeHandler extends BarcodeHandler {
|
|||||||
barcodeFailureTone();
|
barcodeFailureTone();
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
data["error"] as String? ?? L10().barcodeError,
|
data["error"] as String? ?? L10().barcodeError,
|
||||||
success: false
|
success: false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Barcode handler to add a line item to a purchase order
|
* Barcode handler to add a line item to a purchase order
|
||||||
*/
|
*/
|
||||||
class POAllocateBarcodeHandler extends BarcodeHandler {
|
class POAllocateBarcodeHandler extends BarcodeHandler {
|
||||||
|
|
||||||
POAllocateBarcodeHandler({this.purchaseOrder});
|
POAllocateBarcodeHandler({this.purchaseOrder});
|
||||||
|
|
||||||
InvenTreePurchaseOrder? purchaseOrder;
|
InvenTreePurchaseOrder? purchaseOrder;
|
||||||
@ -133,21 +137,14 @@ class POAllocateBarcodeHandler extends BarcodeHandler {
|
|||||||
String getOverlayText(BuildContext context) => L10().scanSupplierPart;
|
String getOverlayText(BuildContext context) => L10().scanSupplierPart;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> processBarcode(String barcode, {
|
Future<void> processBarcode(
|
||||||
|
String barcode, {
|
||||||
String url = "barcode/po-allocate/",
|
String url = "barcode/po-allocate/",
|
||||||
Map<String, dynamic> extra_data = const {}}
|
Map<String, dynamic> extra_data = const {},
|
||||||
) {
|
}) {
|
||||||
|
final po_extra_data = {"purchase_order": purchaseOrder?.pk, ...extra_data};
|
||||||
|
|
||||||
final po_extra_data = {
|
return super.processBarcode(barcode, url: url, extra_data: po_extra_data);
|
||||||
"purchase_order": purchaseOrder?.pk,
|
|
||||||
...extra_data,
|
|
||||||
};
|
|
||||||
|
|
||||||
return super.processBarcode(
|
|
||||||
barcode,
|
|
||||||
url: url,
|
|
||||||
extra_data: po_extra_data,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -189,7 +186,6 @@ class POAllocateBarcodeHandler extends BarcodeHandler {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onBarcodeUnhandled(Map<String, dynamic> data) async {
|
Future<void> onBarcodeUnhandled(Map<String, dynamic> data) async {
|
||||||
|
|
||||||
print("onBarcodeUnhandled:");
|
print("onBarcodeUnhandled:");
|
||||||
print(data.toString());
|
print(data.toString());
|
||||||
|
|
||||||
|
@ -14,13 +14,11 @@ import "package:inventree/barcode/tones.dart";
|
|||||||
|
|
||||||
import "package:inventree/widget/snacks.dart";
|
import "package:inventree/widget/snacks.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Barcode handler class for scanning a new part into a SalesOrder
|
* Barcode handler class for scanning a new part into a SalesOrder
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class SOAddItemBarcodeHandler extends BarcodeHandler {
|
class SOAddItemBarcodeHandler extends BarcodeHandler {
|
||||||
|
|
||||||
SOAddItemBarcodeHandler({this.salesOrder});
|
SOAddItemBarcodeHandler({this.salesOrder});
|
||||||
|
|
||||||
InvenTreeSalesOrder? salesOrder;
|
InvenTreeSalesOrder? salesOrder;
|
||||||
@ -30,7 +28,6 @@ class SOAddItemBarcodeHandler extends BarcodeHandler {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
|
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
|
||||||
|
|
||||||
// Extract the part ID from the returned data
|
// Extract the part ID from the returned data
|
||||||
int part_id = -1;
|
int part_id = -1;
|
||||||
|
|
||||||
@ -46,7 +43,6 @@ class SOAddItemBarcodeHandler extends BarcodeHandler {
|
|||||||
var part = await InvenTreePart().get(part_id);
|
var part = await InvenTreePart().get(part_id);
|
||||||
|
|
||||||
if (part is InvenTreePart) {
|
if (part is InvenTreePart) {
|
||||||
|
|
||||||
if (part.isSalable) {
|
if (part.isSalable) {
|
||||||
// Dispose of the barcode scanner
|
// Dispose of the barcode scanner
|
||||||
if (OneContext.hasContext) {
|
if (OneContext.hasContext) {
|
||||||
@ -68,23 +64,18 @@ class SOAddItemBarcodeHandler extends BarcodeHandler {
|
|||||||
L10().lineItemAdd,
|
L10().lineItemAdd,
|
||||||
fields: fields,
|
fields: fields,
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
barcodeFailureTone();
|
barcodeFailureTone();
|
||||||
showSnackIcon(L10().partNotSalable, success: false);
|
showSnackIcon(L10().partNotSalable, success: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Failed to fetch part
|
// Failed to fetch part
|
||||||
return onBarcodeUnknown(data);
|
return onBarcodeUnknown(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class SOAllocateStockHandler extends BarcodeHandler {
|
class SOAllocateStockHandler extends BarcodeHandler {
|
||||||
|
|
||||||
SOAllocateStockHandler({this.salesOrder, this.lineItem, this.shipment});
|
SOAllocateStockHandler({this.salesOrder, this.lineItem, this.shipment});
|
||||||
|
|
||||||
InvenTreeSalesOrder? salesOrder;
|
InvenTreeSalesOrder? salesOrder;
|
||||||
@ -95,16 +86,16 @@ class SOAllocateStockHandler extends BarcodeHandler {
|
|||||||
String getOverlayText(BuildContext context) => L10().allocateStock;
|
String getOverlayText(BuildContext context) => L10().allocateStock;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> processBarcode(String barcode,
|
Future<void> processBarcode(
|
||||||
{
|
String barcode, {
|
||||||
String url = "barcode/so-allocate/",
|
String url = "barcode/so-allocate/",
|
||||||
Map<String, dynamic> extra_data = const {}}) {
|
Map<String, dynamic> extra_data = const {},
|
||||||
|
}) {
|
||||||
final so_extra_data = {
|
final so_extra_data = {
|
||||||
"sales_order": salesOrder?.pk,
|
"sales_order": salesOrder?.pk,
|
||||||
"shipment": shipment?.pk,
|
"shipment": shipment?.pk,
|
||||||
"line": lineItem?.pk,
|
"line": lineItem?.pk,
|
||||||
...extra_data
|
...extra_data,
|
||||||
};
|
};
|
||||||
|
|
||||||
return super.processBarcode(barcode, url: url, extra_data: so_extra_data);
|
return super.processBarcode(barcode, url: url, extra_data: so_extra_data);
|
||||||
@ -121,8 +112,8 @@ class SOAllocateStockHandler extends BarcodeHandler {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onBarcodeUnhandled(Map<String, dynamic> data) async {
|
Future<void> onBarcodeUnhandled(Map<String, dynamic> data) async {
|
||||||
|
if (!data.containsKey("action_required") ||
|
||||||
if (!data.containsKey("action_required") || !data.containsKey("line_item")) {
|
!data.containsKey("line_item")) {
|
||||||
return super.onBarcodeUnhandled(data);
|
return super.onBarcodeUnhandled(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,10 +123,7 @@ class SOAllocateStockHandler extends BarcodeHandler {
|
|||||||
// Update fields with data gathered from the API response
|
// Update fields with data gathered from the API response
|
||||||
fields["line_item"]?["value"] = data["line_item"];
|
fields["line_item"]?["value"] = data["line_item"];
|
||||||
|
|
||||||
Map<String, dynamic> stock_filters = {
|
Map<String, dynamic> stock_filters = {"in_stock": true, "available": true};
|
||||||
"in_stock": true,
|
|
||||||
"available": true,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (data.containsKey("part")) {
|
if (data.containsKey("part")) {
|
||||||
stock_filters["part"] = data["part"];
|
stock_filters["part"] = data["part"];
|
||||||
@ -147,9 +135,7 @@ class SOAllocateStockHandler extends BarcodeHandler {
|
|||||||
fields["quantity"]?["value"] = data["quantity"];
|
fields["quantity"]?["value"] = data["quantity"];
|
||||||
|
|
||||||
fields["shipment"]?["value"] = data["shipment"];
|
fields["shipment"]?["value"] = data["shipment"];
|
||||||
fields["shipment"]?["filters"] = {
|
fields["shipment"]?["filters"] = {"order": salesOrder!.pk.toString()};
|
||||||
"order": salesOrder!.pk.toString()
|
|
||||||
};
|
|
||||||
|
|
||||||
final context = OneContext().context!;
|
final context = OneContext().context!;
|
||||||
|
|
||||||
@ -162,7 +148,8 @@ class SOAllocateStockHandler extends BarcodeHandler {
|
|||||||
icon: TablerIcons.transition_right,
|
icon: TablerIcons.transition_right,
|
||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
showSnackIcon(L10().allocated, success: true);
|
showSnackIcon(L10().allocated, success: true);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -170,7 +157,7 @@ class SOAllocateStockHandler extends BarcodeHandler {
|
|||||||
barcodeFailureTone();
|
barcodeFailureTone();
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
data["error"] as String? ?? L10().barcodeError,
|
data["error"] as String? ?? L10().barcodeError,
|
||||||
success: false
|
success: false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,7 +16,6 @@ import "package:inventree/inventree/stock.dart";
|
|||||||
import "package:inventree/widget/dialogs.dart";
|
import "package:inventree/widget/dialogs.dart";
|
||||||
import "package:inventree/widget/snacks.dart";
|
import "package:inventree/widget/snacks.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic class for scanning a StockLocation.
|
* Generic class for scanning a StockLocation.
|
||||||
*
|
*
|
||||||
@ -24,20 +23,17 @@ import "package:inventree/widget/snacks.dart";
|
|||||||
* - Runs a "callback" function if a valid StockLocation is found
|
* - Runs a "callback" function if a valid StockLocation is found
|
||||||
*/
|
*/
|
||||||
class BarcodeScanStockLocationHandler extends BarcodeHandler {
|
class BarcodeScanStockLocationHandler extends BarcodeHandler {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getOverlayText(BuildContext context) => L10().barcodeScanLocation;
|
String getOverlayText(BuildContext context) => L10().barcodeScanLocation;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
|
Future<void> onBarcodeMatched(Map<String, dynamic> data) async {
|
||||||
|
|
||||||
// We expect that the barcode points to a 'stocklocation'
|
// We expect that the barcode points to a 'stocklocation'
|
||||||
if (data.containsKey("stocklocation")) {
|
if (data.containsKey("stocklocation")) {
|
||||||
int _loc = (data["stocklocation"]?["pk"] ?? -1) as int;
|
int _loc = (data["stocklocation"]?["pk"] ?? -1) as int;
|
||||||
|
|
||||||
// A valid stock location!
|
// A valid stock location!
|
||||||
if (_loc > 0) {
|
if (_loc > 0) {
|
||||||
|
|
||||||
debug("Scanned stock location ${_loc}");
|
debug("Scanned stock location ${_loc}");
|
||||||
|
|
||||||
final bool result = await onLocationScanned(_loc);
|
final bool result = await onLocationScanned(_loc);
|
||||||
@ -52,10 +48,7 @@ class BarcodeScanStockLocationHandler extends BarcodeHandler {
|
|||||||
// If we get to this point, something went wrong during the scan process
|
// If we get to this point, something went wrong during the scan process
|
||||||
barcodeFailureTone();
|
barcodeFailureTone();
|
||||||
|
|
||||||
showSnackIcon(
|
showSnackIcon(L10().invalidStockLocation, success: false);
|
||||||
L10().invalidStockLocation,
|
|
||||||
success: false,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback function which runs when a valid StockLocation is scanned
|
// Callback function which runs when a valid StockLocation is scanned
|
||||||
@ -64,10 +57,8 @@ class BarcodeScanStockLocationHandler extends BarcodeHandler {
|
|||||||
// Re-implement this for particular subclass
|
// Re-implement this for particular subclass
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic class for scanning a StockItem
|
* Generic class for scanning a StockItem
|
||||||
*
|
*
|
||||||
@ -75,7 +66,6 @@ class BarcodeScanStockLocationHandler extends BarcodeHandler {
|
|||||||
* - Runs a "callback" function if a valid StockItem is found
|
* - Runs a "callback" function if a valid StockItem is found
|
||||||
*/
|
*/
|
||||||
class BarcodeScanStockItemHandler extends BarcodeHandler {
|
class BarcodeScanStockItemHandler extends BarcodeHandler {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getOverlayText(BuildContext context) => L10().barcodeScanItem;
|
String getOverlayText(BuildContext context) => L10().barcodeScanItem;
|
||||||
|
|
||||||
@ -87,7 +77,6 @@ class BarcodeScanStockItemHandler extends BarcodeHandler {
|
|||||||
|
|
||||||
// A valid stock location!
|
// A valid stock location!
|
||||||
if (_item > 0) {
|
if (_item > 0) {
|
||||||
|
|
||||||
barcodeSuccessTone();
|
barcodeSuccessTone();
|
||||||
|
|
||||||
bool result = await onItemScanned(_item);
|
bool result = await onItemScanned(_item);
|
||||||
@ -102,10 +91,7 @@ class BarcodeScanStockItemHandler extends BarcodeHandler {
|
|||||||
// If we get to this point, something went wrong during the scan process
|
// If we get to this point, something went wrong during the scan process
|
||||||
barcodeFailureTone();
|
barcodeFailureTone();
|
||||||
|
|
||||||
showSnackIcon(
|
showSnackIcon(L10().invalidStockItem, success: false);
|
||||||
L10().invalidStockItem,
|
|
||||||
success: false,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback function which runs when a valid StockItem is scanned
|
// Callback function which runs when a valid StockItem is scanned
|
||||||
@ -115,7 +101,6 @@ class BarcodeScanStockItemHandler extends BarcodeHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Barcode handler for scanning a provided StockItem into a scanned StockLocation.
|
* Barcode handler for scanning a provided StockItem into a scanned StockLocation.
|
||||||
*
|
*
|
||||||
@ -124,20 +109,20 @@ class BarcodeScanStockItemHandler extends BarcodeHandler {
|
|||||||
* - The StockItem is transferred into the scanned location
|
* - The StockItem is transferred into the scanned location
|
||||||
*/
|
*/
|
||||||
class StockItemScanIntoLocationHandler extends BarcodeScanStockLocationHandler {
|
class StockItemScanIntoLocationHandler extends BarcodeScanStockLocationHandler {
|
||||||
|
|
||||||
StockItemScanIntoLocationHandler(this.item);
|
StockItemScanIntoLocationHandler(this.item);
|
||||||
|
|
||||||
final InvenTreeStockItem item;
|
final InvenTreeStockItem item;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> onLocationScanned(int locationId) async {
|
Future<bool> onLocationScanned(int locationId) async {
|
||||||
|
final bool confirm = await InvenTreeSettingsManager().getBool(
|
||||||
final bool confirm = await InvenTreeSettingsManager().getBool(INV_STOCK_CONFIRM_SCAN, false);
|
INV_STOCK_CONFIRM_SCAN,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (confirm) {
|
if (confirm) {
|
||||||
|
|
||||||
Map<String, dynamic> fields = item.transferFields();
|
Map<String, dynamic> fields = item.transferFields();
|
||||||
|
|
||||||
// Override location with scanned value
|
// Override location with scanned value
|
||||||
@ -152,7 +137,7 @@ class StockItemScanIntoLocationHandler extends BarcodeScanStockLocationHandler {
|
|||||||
icon: TablerIcons.transfer,
|
icon: TablerIcons.transfer,
|
||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
showSnackIcon(L10().stockItemUpdated, success: true);
|
showSnackIcon(L10().stockItemUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -171,7 +156,6 @@ class StockItemScanIntoLocationHandler extends BarcodeScanStockLocationHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Barcode handler for scanning stock item(s) into the specified StockLocation.
|
* Barcode handler for scanning stock item(s) into the specified StockLocation.
|
||||||
*
|
*
|
||||||
@ -180,7 +164,6 @@ class StockItemScanIntoLocationHandler extends BarcodeScanStockLocationHandler {
|
|||||||
* - The scanned StockItem is transferred into the provided StockLocation
|
* - The scanned StockItem is transferred into the provided StockLocation
|
||||||
*/
|
*/
|
||||||
class StockLocationScanInItemsHandler extends BarcodeScanStockItemHandler {
|
class StockLocationScanInItemsHandler extends BarcodeScanStockItemHandler {
|
||||||
|
|
||||||
StockLocationScanInItemsHandler(this.location);
|
StockLocationScanInItemsHandler(this.location);
|
||||||
|
|
||||||
final InvenTreeStockLocation location;
|
final InvenTreeStockLocation location;
|
||||||
@ -190,14 +173,16 @@ class StockLocationScanInItemsHandler extends BarcodeScanStockItemHandler {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> onItemScanned(int itemId) async {
|
Future<bool> onItemScanned(int itemId) async {
|
||||||
|
final InvenTreeStockItem? item =
|
||||||
final InvenTreeStockItem? item = await InvenTreeStockItem().get(itemId) as InvenTreeStockItem?;
|
await InvenTreeStockItem().get(itemId) as InvenTreeStockItem?;
|
||||||
final bool confirm = await InvenTreeSettingsManager().getBool(INV_STOCK_CONFIRM_SCAN, false);
|
final bool confirm = await InvenTreeSettingsManager().getBool(
|
||||||
|
INV_STOCK_CONFIRM_SCAN,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
|
|
||||||
// Item is already *in* the specified location
|
// Item is already *in* the specified location
|
||||||
if (item.locationId == location.pk) {
|
if (item.locationId == location.pk) {
|
||||||
barcodeFailureTone();
|
barcodeFailureTone();
|
||||||
@ -219,17 +204,18 @@ class StockLocationScanInItemsHandler extends BarcodeScanStockItemHandler {
|
|||||||
icon: TablerIcons.transfer,
|
icon: TablerIcons.transfer,
|
||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
showSnackIcon(L10().stockItemUpdated, success: true);
|
showSnackIcon(L10().stockItemUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = await item.transferStock(location.pk);
|
result = await item.transferStock(location.pk);
|
||||||
|
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
result ? L10().barcodeScanIntoLocationSuccess : L10().barcodeScanIntoLocationFailure,
|
result
|
||||||
success: result
|
? L10().barcodeScanIntoLocationSuccess
|
||||||
|
: L10().barcodeScanIntoLocationFailure,
|
||||||
|
success: result,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,7 +226,6 @@ class StockLocationScanInItemsHandler extends BarcodeScanStockItemHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Barcode handler class for scanning a StockLocation into another StockLocation
|
* Barcode handler class for scanning a StockLocation into another StockLocation
|
||||||
*
|
*
|
||||||
@ -249,18 +234,14 @@ class StockLocationScanInItemsHandler extends BarcodeScanStockItemHandler {
|
|||||||
* - The scanned StockLocation is set as the "parent" of the provided StockLocation
|
* - The scanned StockLocation is set as the "parent" of the provided StockLocation
|
||||||
*/
|
*/
|
||||||
class ScanParentLocationHandler extends BarcodeScanStockLocationHandler {
|
class ScanParentLocationHandler extends BarcodeScanStockLocationHandler {
|
||||||
|
|
||||||
ScanParentLocationHandler(this.location);
|
ScanParentLocationHandler(this.location);
|
||||||
|
|
||||||
final InvenTreeStockLocation location;
|
final InvenTreeStockLocation location;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> onLocationScanned(int locationId) async {
|
Future<bool> onLocationScanned(int locationId) async {
|
||||||
|
|
||||||
final response = await location.update(
|
final response = await location.update(
|
||||||
values: {
|
values: {"parent": locationId.toString()},
|
||||||
"parent": locationId.toString(),
|
|
||||||
},
|
|
||||||
expectedStatusCode: null,
|
expectedStatusCode: null,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -280,11 +261,8 @@ class ScanParentLocationHandler extends BarcodeScanStockLocationHandler {
|
|||||||
success: false,
|
success: false,
|
||||||
actionText: L10().details,
|
actionText: L10().details,
|
||||||
onAction: () {
|
onAction: () {
|
||||||
showErrorDialog(
|
showErrorDialog(L10().barcodeError, response: response);
|
||||||
L10().barcodeError,
|
},
|
||||||
response: response,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,9 @@ import "package:inventree/preferences.dart";
|
|||||||
* Play an audible 'success' alert to the user.
|
* Play an audible 'success' alert to the user.
|
||||||
*/
|
*/
|
||||||
Future<void> barcodeSuccessTone() async {
|
Future<void> barcodeSuccessTone() async {
|
||||||
|
final bool en =
|
||||||
final bool en = await InvenTreeSettingsManager().getValue(INV_SOUNDS_BARCODE, true) as bool;
|
await InvenTreeSettingsManager().getValue(INV_SOUNDS_BARCODE, true)
|
||||||
|
as bool;
|
||||||
|
|
||||||
if (en) {
|
if (en) {
|
||||||
playAudioFile("sounds/barcode_scan.mp3");
|
playAudioFile("sounds/barcode_scan.mp3");
|
||||||
@ -14,8 +15,9 @@ Future<void> barcodeSuccessTone() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> barcodeFailureTone() async {
|
Future<void> barcodeFailureTone() async {
|
||||||
|
final bool en =
|
||||||
final bool en = await InvenTreeSettingsManager().getValue(INV_SOUNDS_BARCODE, true) as bool;
|
await InvenTreeSettingsManager().getValue(INV_SOUNDS_BARCODE, true)
|
||||||
|
as bool;
|
||||||
|
|
||||||
if (en) {
|
if (en) {
|
||||||
playAudioFile("sounds/barcode_error.mp3");
|
playAudioFile("sounds/barcode_error.mp3");
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter/services.dart";
|
import "package:flutter/services.dart";
|
||||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||||
@ -15,17 +14,14 @@ import "package:inventree/helpers.dart";
|
|||||||
* intercepting barcode data which is entered as rapid keyboard presses
|
* intercepting barcode data which is entered as rapid keyboard presses
|
||||||
*/
|
*/
|
||||||
class WedgeBarcodeController extends InvenTreeBarcodeController {
|
class WedgeBarcodeController extends InvenTreeBarcodeController {
|
||||||
|
const WedgeBarcodeController(BarcodeHandler handler, {Key? key})
|
||||||
const WedgeBarcodeController(BarcodeHandler handler, {Key? key}) : super(handler, key: key);
|
: super(handler, key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() => _WedgeBarcodeControllerState();
|
State<StatefulWidget> createState() => _WedgeBarcodeControllerState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
|
class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
|
||||||
|
|
||||||
_WedgeBarcodeControllerState() : super();
|
_WedgeBarcodeControllerState() : super();
|
||||||
|
|
||||||
bool canScan = true;
|
bool canScan = true;
|
||||||
@ -40,7 +36,6 @@ class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> pauseScan() async {
|
Future<void> pauseScan() async {
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
canScan = false;
|
canScan = false;
|
||||||
@ -50,7 +45,6 @@ class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> resumeScan() async {
|
Future<void> resumeScan() async {
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
canScan = true;
|
canScan = true;
|
||||||
@ -60,7 +54,6 @@ class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
|
|||||||
|
|
||||||
// Callback for a single key press / scan
|
// Callback for a single key press / scan
|
||||||
void handleKeyEvent(KeyEvent event) {
|
void handleKeyEvent(KeyEvent event) {
|
||||||
|
|
||||||
if (!scanning) {
|
if (!scanning) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -78,7 +71,8 @@ class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
|
|||||||
DateTime now = DateTime.now();
|
DateTime now = DateTime.now();
|
||||||
|
|
||||||
// Throw away old characters
|
// Throw away old characters
|
||||||
if (_lastScanTime == null || _lastScanTime!.isBefore(now.subtract(Duration(milliseconds: 250)))) {
|
if (_lastScanTime == null ||
|
||||||
|
_lastScanTime!.isBefore(now.subtract(Duration(milliseconds: 250)))) {
|
||||||
_scannedCharacters.clear();
|
_scannedCharacters.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +93,6 @@ class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor: COLOR_APP_BAR,
|
backgroundColor: COLOR_APP_BAR,
|
||||||
@ -118,7 +111,7 @@ class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
|
|||||||
focusNode: _focusNode,
|
focusNode: _focusNode,
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
color: scanning ? COLOR_ACTION : COLOR_PROGRESS
|
color: scanning ? COLOR_ACTION : COLOR_PROGRESS,
|
||||||
),
|
),
|
||||||
width: 64,
|
width: 64,
|
||||||
height: 64,
|
height: 64,
|
||||||
@ -140,14 +133,14 @@ class _WedgeBarcodeControllerState extends InvenTreeBarcodeControllerState {
|
|||||||
widget.handler.getOverlayText(context),
|
widget.handler.getOverlayText(context),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: Colors.white)
|
color: Colors.white,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
padding: EdgeInsets.all(20),
|
padding: EdgeInsets.all(20),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* For integration with sentry.io, fill out the SENTRY_DSN_KEY value below.
|
* For integration with sentry.io, fill out the SENTRY_DSN_KEY value below.
|
||||||
* This should be set to a valid DSN key, from your sentry.io account
|
* This should be set to a valid DSN key, from your sentry.io account
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
String SENTRY_DSN_KEY = "https://fea705aa4b8e4c598dcf9b146b3d1b86@o378676.ingest.sentry.io/5202450";
|
String SENTRY_DSN_KEY =
|
||||||
|
"https://fea705aa4b8e4c598dcf9b146b3d1b86@o378676.ingest.sentry.io/5202450";
|
||||||
|
@ -1,76 +0,0 @@
|
|||||||
|
|
||||||
import "dart:async';
|
|
||||||
|
|
||||||
import "package:flutter/foundation.dart';
|
|
||||||
import "package:flutter/material.dart';
|
|
||||||
// ignore_for_file: non_constant_identifier_names
|
|
||||||
// ignore_for_file: camel_case_types
|
|
||||||
// ignore_for_file: prefer_single_quotes
|
|
||||||
|
|
||||||
//This file is automatically generated. DO NOT EDIT, all your changes would be lost.
|
|
||||||
|
|
||||||
class S implements WidgetsLocalizations {
|
|
||||||
const S();
|
|
||||||
|
|
||||||
static const GeneratedLocalizationsDelegate delegate = GeneratedLocalizationsDelegate();
|
|
||||||
|
|
||||||
static S of(BuildContext context) => Localizations.of<S>(context, WidgetsLocalizations);
|
|
||||||
|
|
||||||
@override
|
|
||||||
TextDirection get textDirection => TextDirection.ltr;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class en extends S {
|
|
||||||
const en();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class GeneratedLocalizationsDelegate extends LocalizationsDelegate<WidgetsLocalizations> {
|
|
||||||
const GeneratedLocalizationsDelegate();
|
|
||||||
|
|
||||||
List<Locale> get supportedLocales {
|
|
||||||
return const <Locale>[
|
|
||||||
|
|
||||||
const Locale("en", ""),
|
|
||||||
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
LocaleResolutionCallback resolution({Locale fallback}) {
|
|
||||||
return (Locale locale, Iterable<Locale> supported) {
|
|
||||||
final Locale languageLocale = new Locale(locale.languageCode, "");
|
|
||||||
if (supported.contains(locale))
|
|
||||||
return locale;
|
|
||||||
else if (supported.contains(languageLocale))
|
|
||||||
return languageLocale;
|
|
||||||
else {
|
|
||||||
final Locale fallbackLocale = fallback ?? supported.first;
|
|
||||||
return fallbackLocale;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<WidgetsLocalizations> load(Locale locale) {
|
|
||||||
final String lang = getLang(locale);
|
|
||||||
switch (lang) {
|
|
||||||
|
|
||||||
case "en":
|
|
||||||
return new SynchronousFuture<WidgetsLocalizations>(const en());
|
|
||||||
|
|
||||||
default:
|
|
||||||
return new SynchronousFuture<WidgetsLocalizations>(const S());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool isSupported(Locale locale) => supportedLocales.contains(locale);
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool shouldReload(GeneratedLocalizationsDelegate old) => false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getLang(Locale l) => l.countryCode != null && l.countryCode.isEmpty
|
|
||||||
? l.languageCode
|
|
||||||
: l.toString();
|
|
@ -17,8 +17,6 @@ import "package:audioplayers/audioplayers.dart";
|
|||||||
import "package:inventree/l10.dart";
|
import "package:inventree/l10.dart";
|
||||||
import "package:inventree/widget/snacks.dart";
|
import "package:inventree/widget/snacks.dart";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<String> debug_messages = [];
|
List<String> debug_messages = [];
|
||||||
|
|
||||||
void clearDebugMessage() => debug_messages.clear();
|
void clearDebugMessage() => debug_messages.clear();
|
||||||
@ -44,14 +42,12 @@ bool debugContains(String msg, {bool raiseAssert = true}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (raiseAssert) {
|
if (raiseAssert) {
|
||||||
|
|
||||||
assert(result);
|
assert(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool isTesting() {
|
bool isTesting() {
|
||||||
return Platform.environment.containsKey("FLUTTER_TEST");
|
return Platform.environment.containsKey("FLUTTER_TEST");
|
||||||
}
|
}
|
||||||
@ -64,12 +60,10 @@ bool hasContext() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display a debug message if we are in testing mode, or running in debug mode
|
* Display a debug message if we are in testing mode, or running in debug mode
|
||||||
*/
|
*/
|
||||||
void debug(dynamic msg) {
|
void debug(dynamic msg) {
|
||||||
|
|
||||||
if (Platform.environment.containsKey("FLUTTER_TEST")) {
|
if (Platform.environment.containsKey("FLUTTER_TEST")) {
|
||||||
debug_messages.add(msg.toString());
|
debug_messages.add(msg.toString());
|
||||||
}
|
}
|
||||||
@ -77,13 +71,11 @@ void debug(dynamic msg) {
|
|||||||
print("DEBUG: ${msg.toString()}");
|
print("DEBUG: ${msg.toString()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Simplify string representation of a floating point value
|
* Simplify string representation of a floating point value
|
||||||
* Basically, don't display fractional component if it is an integer
|
* Basically, don't display fractional component if it is an integer
|
||||||
*/
|
*/
|
||||||
String simpleNumberString(double number) {
|
String simpleNumberString(double number) {
|
||||||
|
|
||||||
if (number.toInt() == number) {
|
if (number.toInt() == number) {
|
||||||
return number.toInt().toString();
|
return number.toInt().toString();
|
||||||
} else {
|
} else {
|
||||||
@ -98,7 +90,6 @@ String simpleNumberString(double number) {
|
|||||||
* we will not attempt to play the sound
|
* we will not attempt to play the sound
|
||||||
*/
|
*/
|
||||||
Future<void> playAudioFile(String path) async {
|
Future<void> playAudioFile(String path) async {
|
||||||
|
|
||||||
// Debug message for unit testing
|
// Debug message for unit testing
|
||||||
debug("Playing audio file: '${path}'");
|
debug("Playing audio file: '${path}'");
|
||||||
|
|
||||||
@ -110,21 +101,21 @@ Future<void> playAudioFile(String path) async {
|
|||||||
|
|
||||||
// Specify context options for the audio player
|
// Specify context options for the audio player
|
||||||
// Ref: https://github.com/inventree/inventree-app/issues/582
|
// Ref: https://github.com/inventree/inventree-app/issues/582
|
||||||
player.setAudioContext(AudioContext(
|
player.setAudioContext(
|
||||||
|
AudioContext(
|
||||||
android: AudioContextAndroid(
|
android: AudioContextAndroid(
|
||||||
usageType: AndroidUsageType.notification,
|
usageType: AndroidUsageType.notification,
|
||||||
audioFocus: AndroidAudioFocus.none,
|
audioFocus: AndroidAudioFocus.none,
|
||||||
),
|
),
|
||||||
iOS: AudioContextIOS()
|
iOS: AudioContextIOS(),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
|
|
||||||
player.play(AssetSource(path));
|
player.play(AssetSource(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Open an external URL
|
// Open an external URL
|
||||||
Future<void> openLink(String url) async {
|
Future<void> openLink(String url) async {
|
||||||
|
|
||||||
final link = Uri.parse(url);
|
final link = Uri.parse(url);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -134,24 +125,20 @@ Future<void> openLink(String url) async {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper function for rendering a money / currency object as a String
|
* Helper function for rendering a money / currency object as a String
|
||||||
*/
|
*/
|
||||||
String renderCurrency(double? amount, String currency, {int decimals = 2}) {
|
String renderCurrency(double? amount, String currency, {int decimals = 2}) {
|
||||||
|
|
||||||
if (amount == null || amount.isInfinite || amount.isNaN) return "-";
|
if (amount == null || amount.isInfinite || amount.isNaN) return "-";
|
||||||
|
|
||||||
currency = currency.trim();
|
currency = currency.trim();
|
||||||
|
|
||||||
if (currency.isEmpty) return "-";
|
if (currency.isEmpty) return "-";
|
||||||
|
|
||||||
CurrencyFormat fmt = CurrencyFormat.fromCode(currency.toLowerCase()) ?? CurrencyFormat.usd;
|
CurrencyFormat fmt =
|
||||||
|
CurrencyFormat.fromCode(currency.toLowerCase()) ?? CurrencyFormat.usd;
|
||||||
|
|
||||||
String value = CurrencyFormatter.format(
|
String value = CurrencyFormatter.format(amount, fmt);
|
||||||
amount,
|
|
||||||
fmt
|
|
||||||
);
|
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -163,8 +150,11 @@ bool isValidNumber(double? value) {
|
|||||||
/*
|
/*
|
||||||
* Render a "range" of prices between two values.
|
* Render a "range" of prices between two values.
|
||||||
*/
|
*/
|
||||||
String formatPriceRange(double? minPrice, double? maxPrice, { String? currency }) {
|
String formatPriceRange(
|
||||||
|
double? minPrice,
|
||||||
|
double? maxPrice, {
|
||||||
|
String? currency,
|
||||||
|
}) {
|
||||||
// Account for empty or null values
|
// Account for empty or null values
|
||||||
if (!isValidNumber(minPrice) && !isValidNumber(maxPrice)) {
|
if (!isValidNumber(minPrice) && !isValidNumber(maxPrice)) {
|
||||||
return "-";
|
return "-";
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:inventree/inventree/model.dart";
|
import "package:inventree/inventree/model.dart";
|
||||||
import "package:inventree/inventree/part.dart";
|
import "package:inventree/inventree/part.dart";
|
||||||
|
|
||||||
@ -6,13 +5,13 @@ import "package:inventree/inventree/part.dart";
|
|||||||
* Class representing the BomItem database model
|
* Class representing the BomItem database model
|
||||||
*/
|
*/
|
||||||
class InvenTreeBomItem extends InvenTreeModel {
|
class InvenTreeBomItem extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeBomItem() : super();
|
InvenTreeBomItem() : super();
|
||||||
|
|
||||||
InvenTreeBomItem.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeBomItem.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeBomItem.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeBomItem.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "bom/";
|
String get URL => "bom/";
|
||||||
|
@ -6,13 +6,11 @@ import "package:inventree/inventree/model.dart";
|
|||||||
import "package:inventree/inventree/purchase_order.dart";
|
import "package:inventree/inventree/purchase_order.dart";
|
||||||
import "package:inventree/widget/company/company_detail.dart";
|
import "package:inventree/widget/company/company_detail.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The InvenTreeCompany class represents the Company model in the InvenTree database.
|
* The InvenTreeCompany class represents the Company model in the InvenTree database.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class InvenTreeCompany extends InvenTreeModel {
|
class InvenTreeCompany extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeCompany() : super();
|
InvenTreeCompany() : super();
|
||||||
|
|
||||||
InvenTreeCompany.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeCompany.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
||||||
@ -26,14 +24,16 @@ class InvenTreeCompany extends InvenTreeModel {
|
|||||||
Future<Object?> goToDetailPage(BuildContext context) async {
|
Future<Object?> goToDetailPage(BuildContext context) async {
|
||||||
return Navigator.push(
|
return Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => CompanyDetailWidget(this)),
|
||||||
builder: (context) => CompanyDetailWidget(this)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get rolesRequired => ["purchase_order", "sales_order", "return_order"];
|
List<String> get rolesRequired => [
|
||||||
|
"purchase_order",
|
||||||
|
"sales_order",
|
||||||
|
"return_order",
|
||||||
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, Map<String, dynamic>> formFields() {
|
Map<String, Map<String, dynamic>> formFields() {
|
||||||
@ -54,9 +54,13 @@ class InvenTreeCompany extends InvenTreeModel {
|
|||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
String get image => (jsondata["image"] ?? jsondata["thumbnail"] ?? InvenTreeAPI.staticImage) as String;
|
String get image =>
|
||||||
|
(jsondata["image"] ?? jsondata["thumbnail"] ?? InvenTreeAPI.staticImage)
|
||||||
|
as String;
|
||||||
|
|
||||||
String get thumbnail => (jsondata["thumbnail"] ?? jsondata["image"] ?? InvenTreeAPI.staticThumb) as String;
|
String get thumbnail =>
|
||||||
|
(jsondata["thumbnail"] ?? jsondata["image"] ?? InvenTreeAPI.staticThumb)
|
||||||
|
as String;
|
||||||
|
|
||||||
String get website => getString("website");
|
String get website => getString("website");
|
||||||
|
|
||||||
@ -77,18 +81,17 @@ class InvenTreeCompany extends InvenTreeModel {
|
|||||||
int get partManufacturedCount => getInt("parts_manufactured");
|
int get partManufacturedCount => getInt("parts_manufactured");
|
||||||
|
|
||||||
// Request a list of purchase orders against this company
|
// Request a list of purchase orders against this company
|
||||||
Future<List<InvenTreePurchaseOrder>> getPurchaseOrders({bool? outstanding}) async {
|
Future<List<InvenTreePurchaseOrder>> getPurchaseOrders({
|
||||||
|
bool? outstanding,
|
||||||
Map<String, String> filters = {
|
}) async {
|
||||||
"supplier": "${pk}"
|
Map<String, String> filters = {"supplier": "${pk}"};
|
||||||
};
|
|
||||||
|
|
||||||
if (outstanding != null) {
|
if (outstanding != null) {
|
||||||
filters["outstanding"] = outstanding ? "true" : "false";
|
filters["outstanding"] = outstanding ? "true" : "false";
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<InvenTreeModel> results = await InvenTreePurchaseOrder().list(
|
final List<InvenTreeModel> results = await InvenTreePurchaseOrder().list(
|
||||||
filters: filters
|
filters: filters,
|
||||||
);
|
);
|
||||||
|
|
||||||
List<InvenTreePurchaseOrder> orders = [];
|
List<InvenTreePurchaseOrder> orders = [];
|
||||||
@ -103,18 +106,18 @@ class InvenTreeCompany extends InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeCompany.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeCompany.fromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing an attachment file against a Company object
|
* Class representing an attachment file against a Company object
|
||||||
*/
|
*/
|
||||||
class InvenTreeCompanyAttachment extends InvenTreeAttachment {
|
class InvenTreeCompanyAttachment extends InvenTreeAttachment {
|
||||||
|
|
||||||
InvenTreeCompanyAttachment() : super();
|
InvenTreeCompanyAttachment() : super();
|
||||||
|
|
||||||
InvenTreeCompanyAttachment.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeCompanyAttachment.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get REFERENCE_FIELD => "company";
|
String get REFERENCE_FIELD => "company";
|
||||||
@ -123,21 +126,23 @@ class InvenTreeCompanyAttachment extends InvenTreeAttachment {
|
|||||||
String get REF_MODEL_TYPE => "company";
|
String get REF_MODEL_TYPE => "company";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => InvenTreeAPI().supportsModernAttachments ? "attachment/" : "company/attachment/";
|
String get URL => InvenTreeAPI().supportsModernAttachments
|
||||||
|
? "attachment/"
|
||||||
|
: "company/attachment/";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeCompanyAttachment.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeCompanyAttachment.fromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The InvenTreeSupplierPart class represents the SupplierPart model in the InvenTree database
|
* The InvenTreeSupplierPart class represents the SupplierPart model in the InvenTree database
|
||||||
*/
|
*/
|
||||||
class InvenTreeSupplierPart extends InvenTreeModel {
|
class InvenTreeSupplierPart extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeSupplierPart() : super();
|
InvenTreeSupplierPart() : super();
|
||||||
|
|
||||||
InvenTreeSupplierPart.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeSupplierPart.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "company/part/";
|
String get URL => "company/part/";
|
||||||
@ -180,14 +185,18 @@ class InvenTreeSupplierPart extends InvenTreeModel {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int get manufacturerId => getInt("pk", subKey: "manufacturer_detail");
|
int get manufacturerId => getInt("pk", subKey: "manufacturer_detail");
|
||||||
|
|
||||||
String get manufacturerName => getString("name", subKey: "manufacturer_detail");
|
String get manufacturerName =>
|
||||||
|
getString("name", subKey: "manufacturer_detail");
|
||||||
|
|
||||||
String get MPN => getString("MPN", subKey: "manufacturer_part_detail");
|
String get MPN => getString("MPN", subKey: "manufacturer_part_detail");
|
||||||
|
|
||||||
String get manufacturerImage => (jsondata["manufacturer_detail"]?["image"] ?? jsondata["manufacturer_detail"]?["thumbnail"] ?? InvenTreeAPI.staticThumb) as String;
|
String get manufacturerImage =>
|
||||||
|
(jsondata["manufacturer_detail"]?["image"] ??
|
||||||
|
jsondata["manufacturer_detail"]?["thumbnail"] ??
|
||||||
|
InvenTreeAPI.staticThumb)
|
||||||
|
as String;
|
||||||
|
|
||||||
int get manufacturerPartId => getInt("manufacturer_part");
|
int get manufacturerPartId => getInt("manufacturer_part");
|
||||||
|
|
||||||
@ -195,7 +204,11 @@ class InvenTreeSupplierPart extends InvenTreeModel {
|
|||||||
|
|
||||||
String get supplierName => getString("name", subKey: "supplier_detail");
|
String get supplierName => getString("name", subKey: "supplier_detail");
|
||||||
|
|
||||||
String get supplierImage => (jsondata["supplier_detail"]?["image"] ?? jsondata["supplier_detail"]?["thumbnail"] ?? InvenTreeAPI.staticThumb) as String;
|
String get supplierImage =>
|
||||||
|
(jsondata["supplier_detail"]?["image"] ??
|
||||||
|
jsondata["supplier_detail"]?["thumbnail"] ??
|
||||||
|
InvenTreeAPI.staticThumb)
|
||||||
|
as String;
|
||||||
|
|
||||||
String get SKU => getString("SKU");
|
String get SKU => getString("SKU");
|
||||||
|
|
||||||
@ -203,7 +216,9 @@ class InvenTreeSupplierPart extends InvenTreeModel {
|
|||||||
|
|
||||||
int get partId => getInt("part");
|
int get partId => getInt("part");
|
||||||
|
|
||||||
String get partImage => (jsondata["part_detail"]?["thumbnail"] ?? InvenTreeAPI.staticThumb) as String;
|
String get partImage =>
|
||||||
|
(jsondata["part_detail"]?["thumbnail"] ?? InvenTreeAPI.staticThumb)
|
||||||
|
as String;
|
||||||
|
|
||||||
String get partName => getString("name", subKey: "part_detail");
|
String get partName => getString("name", subKey: "part_detail");
|
||||||
|
|
||||||
@ -224,15 +239,15 @@ class InvenTreeSupplierPart extends InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeSupplierPart.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeSupplierPart.fromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeManufacturerPart extends InvenTreeModel {
|
class InvenTreeManufacturerPart extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeManufacturerPart() : super();
|
InvenTreeManufacturerPart() : super();
|
||||||
|
|
||||||
InvenTreeManufacturerPart.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeManufacturerPart.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String URL = "company/part/manufacturer/";
|
String URL = "company/part/manufacturer/";
|
||||||
@ -255,10 +270,7 @@ class InvenTreeManufacturerPart extends InvenTreeModel {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, String> defaultFilters() {
|
Map<String, String> defaultFilters() {
|
||||||
return {
|
return {"manufacturer_detail": "true", "part_detail": "true"};
|
||||||
"manufacturer_detail": "true",
|
|
||||||
"part_detail": "true",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int get partId => getInt("part");
|
int get partId => getInt("part");
|
||||||
@ -269,18 +281,27 @@ class InvenTreeManufacturerPart extends InvenTreeModel {
|
|||||||
|
|
||||||
String get partIPN => getString("IPN", subKey: "part_detail");
|
String get partIPN => getString("IPN", subKey: "part_detail");
|
||||||
|
|
||||||
String get partImage => (jsondata["part_detail"]?["thumbnail"] ?? InvenTreeAPI.staticThumb) as String;
|
String get partImage =>
|
||||||
|
(jsondata["part_detail"]?["thumbnail"] ?? InvenTreeAPI.staticThumb)
|
||||||
|
as String;
|
||||||
|
|
||||||
int get manufacturerId => getInt("manufacturer");
|
int get manufacturerId => getInt("manufacturer");
|
||||||
|
|
||||||
String get manufacturerName => getString("name", subKey: "manufacturer_detail");
|
String get manufacturerName =>
|
||||||
|
getString("name", subKey: "manufacturer_detail");
|
||||||
|
|
||||||
String get manufacturerDescription => getString("description", subKey: "manufacturer_detail");
|
String get manufacturerDescription =>
|
||||||
|
getString("description", subKey: "manufacturer_detail");
|
||||||
|
|
||||||
String get manufacturerImage => (jsondata["manufacturer_detail"]?["image"] ?? jsondata["manufacturer_detail"]?["thumbnail"] ?? InvenTreeAPI.staticThumb) as String;
|
String get manufacturerImage =>
|
||||||
|
(jsondata["manufacturer_detail"]?["image"] ??
|
||||||
|
jsondata["manufacturer_detail"]?["thumbnail"] ??
|
||||||
|
InvenTreeAPI.staticThumb)
|
||||||
|
as String;
|
||||||
|
|
||||||
String get MPN => getString("MPN");
|
String get MPN => getString("MPN");
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeManufacturerPart.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeManufacturerPart.fromJson(json);
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,8 @@ import "package:inventree/inventree/sentry.dart";
|
|||||||
import "package:inventree/widget/dialogs.dart";
|
import "package:inventree/widget/dialogs.dart";
|
||||||
import "package:inventree/widget/fields.dart";
|
import "package:inventree/widget/fields.dart";
|
||||||
|
|
||||||
|
|
||||||
// Paginated response object
|
// Paginated response object
|
||||||
class InvenTreePageResponse {
|
class InvenTreePageResponse {
|
||||||
|
|
||||||
InvenTreePageResponse() {
|
InvenTreePageResponse() {
|
||||||
results = [];
|
results = [];
|
||||||
}
|
}
|
||||||
@ -42,7 +40,6 @@ class InvenTreePageResponse {
|
|||||||
* for interacting with InvenTree data.
|
* for interacting with InvenTree data.
|
||||||
*/
|
*/
|
||||||
class InvenTreeModel {
|
class InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeModel();
|
InvenTreeModel();
|
||||||
|
|
||||||
// Construct an InvenTreeModel from a JSON data object
|
// Construct an InvenTreeModel from a JSON data object
|
||||||
@ -87,7 +84,6 @@ class InvenTreeModel {
|
|||||||
|
|
||||||
// If a subKey is specified, we need to dig deeper into the JSON data
|
// If a subKey is specified, we need to dig deeper into the JSON data
|
||||||
if (subKey.isNotEmpty) {
|
if (subKey.isNotEmpty) {
|
||||||
|
|
||||||
if (!data.containsKey(subKey)) {
|
if (!data.containsKey(subKey)) {
|
||||||
debug("JSON data does not contain subKey '$subKey' for key '$key'");
|
debug("JSON data does not contain subKey '$subKey' for key '$key'");
|
||||||
return backup;
|
return backup;
|
||||||
@ -98,7 +94,6 @@ class InvenTreeModel {
|
|||||||
if (sub_data is Map<String, dynamic>) {
|
if (sub_data is Map<String, dynamic>) {
|
||||||
data = (data[subKey] ?? {}) as Map<String, dynamic>;
|
data = (data[subKey] ?? {}) as Map<String, dynamic>;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.containsKey(key)) {
|
if (data.containsKey(key)) {
|
||||||
@ -109,7 +104,11 @@ class InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to get sub-map from JSON data
|
// Helper function to get sub-map from JSON data
|
||||||
Map<String, dynamic> getMap(String key, {Map<String, dynamic> backup = const {}, String subKey = ""}) {
|
Map<String, dynamic> getMap(
|
||||||
|
String key, {
|
||||||
|
Map<String, dynamic> backup = const {},
|
||||||
|
String subKey = "",
|
||||||
|
}) {
|
||||||
dynamic value = getValue(key, backup: backup, subKey: subKey);
|
dynamic value = getValue(key, backup: backup, subKey: subKey);
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
@ -194,7 +193,6 @@ class InvenTreeModel {
|
|||||||
|
|
||||||
// Return the InvenTree web server URL for this object
|
// Return the InvenTree web server URL for this object
|
||||||
String get webUrl {
|
String get webUrl {
|
||||||
|
|
||||||
if (api.isConnected()) {
|
if (api.isConnected()) {
|
||||||
String web = InvenTreeAPI().baseUrl;
|
String web = InvenTreeAPI().baseUrl;
|
||||||
|
|
||||||
@ -205,7 +203,6 @@ class InvenTreeModel {
|
|||||||
web = web.replaceAll("//", "/");
|
web = web.replaceAll("//", "/");
|
||||||
|
|
||||||
return web;
|
return web;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -216,7 +213,9 @@ class InvenTreeModel {
|
|||||||
*/
|
*/
|
||||||
List<String> get rolesRequired {
|
List<String> get rolesRequired {
|
||||||
// Default implementation should not be called
|
// Default implementation should not be called
|
||||||
debug("rolesRequired() not implemented for model ${URL} - returning empty list");
|
debug(
|
||||||
|
"rolesRequired() not implemented for model ${URL} - returning empty list",
|
||||||
|
);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,12 +270,17 @@ class InvenTreeModel {
|
|||||||
// Fields for editing / creating this model
|
// Fields for editing / creating this model
|
||||||
// Override per-model
|
// Override per-model
|
||||||
Map<String, Map<String, dynamic>> formFields() {
|
Map<String, Map<String, dynamic>> formFields() {
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> createForm(BuildContext context, String title, {String fileField = "", Map<String, dynamic> fields=const{}, Map<String, dynamic> data=const {}, Function(dynamic)? onSuccess}) async {
|
Future<void> createForm(
|
||||||
|
BuildContext context,
|
||||||
|
String title, {
|
||||||
|
String fileField = "",
|
||||||
|
Map<String, dynamic> fields = const {},
|
||||||
|
Map<String, dynamic> data = const {},
|
||||||
|
Function(dynamic)? onSuccess,
|
||||||
|
}) async {
|
||||||
if (fields.isEmpty) {
|
if (fields.isEmpty) {
|
||||||
fields = formFields();
|
fields = formFields();
|
||||||
}
|
}
|
||||||
@ -291,14 +295,17 @@ class InvenTreeModel {
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
fileField: fileField,
|
fileField: fileField,
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Launch a modal form to edit the fields available to this model instance.
|
* Launch a modal form to edit the fields available to this model instance.
|
||||||
*/
|
*/
|
||||||
Future<void> editForm(BuildContext context, String title, {Map<String, dynamic> fields=const {}, Function(dynamic)? onSuccess}) async {
|
Future<void> editForm(
|
||||||
|
BuildContext context,
|
||||||
|
String title, {
|
||||||
|
Map<String, dynamic> fields = const {},
|
||||||
|
Function(dynamic)? onSuccess,
|
||||||
|
}) async {
|
||||||
if (fields.isEmpty) {
|
if (fields.isEmpty) {
|
||||||
fields = formFields();
|
fields = formFields();
|
||||||
}
|
}
|
||||||
@ -310,9 +317,8 @@ class InvenTreeModel {
|
|||||||
fields,
|
fields,
|
||||||
modelData: jsondata,
|
modelData: jsondata,
|
||||||
onSuccess: onSuccess,
|
onSuccess: onSuccess,
|
||||||
method: "PATCH"
|
method: "PATCH",
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSON data which defines this object
|
// JSON data which defines this object
|
||||||
@ -388,7 +394,6 @@ class InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> goToInvenTreePage() async {
|
Future<void> goToInvenTreePage() async {
|
||||||
|
|
||||||
var uri = Uri.tryParse(webUrl);
|
var uri = Uri.tryParse(webUrl);
|
||||||
if (uri != null && await canLaunchUrl(uri)) {
|
if (uri != null && await canLaunchUrl(uri)) {
|
||||||
await launchUrl(uri);
|
await launchUrl(uri);
|
||||||
@ -398,7 +403,6 @@ class InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> openLink() async {
|
Future<void> openLink() async {
|
||||||
|
|
||||||
if (link.isNotEmpty) {
|
if (link.isNotEmpty) {
|
||||||
var uri = Uri.tryParse(link);
|
var uri = Uri.tryParse(link);
|
||||||
if (uri != null && await canLaunchUrl(uri)) {
|
if (uri != null && await canLaunchUrl(uri)) {
|
||||||
@ -410,14 +414,19 @@ class InvenTreeModel {
|
|||||||
String get keywords => getString("keywords");
|
String get keywords => getString("keywords");
|
||||||
|
|
||||||
// Create a new object from JSON data (not a constructor!)
|
// Create a new object from JSON data (not a constructor!)
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeModel.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeModel.fromJson(json);
|
||||||
|
|
||||||
// Return the API detail endpoint for this Model object
|
// Return the API detail endpoint for this Model object
|
||||||
String get url => "${URL}/${pk}/".replaceAll("//", "/");
|
String get url => "${URL}/${pk}/".replaceAll("//", "/");
|
||||||
|
|
||||||
// Search this Model type in the database
|
// Search this Model type in the database
|
||||||
Future<List<InvenTreeModel>> search(String searchTerm, {Map<String, String> filters = const {}, int offset = 0, int limit = 25}) async {
|
Future<List<InvenTreeModel>> search(
|
||||||
|
String searchTerm, {
|
||||||
|
Map<String, String> filters = const {},
|
||||||
|
int offset = 0,
|
||||||
|
int limit = 25,
|
||||||
|
}) async {
|
||||||
Map<String, String> searchFilters = {};
|
Map<String, String> searchFilters = {};
|
||||||
|
|
||||||
for (String key in filters.keys) {
|
for (String key in filters.keys) {
|
||||||
@ -431,12 +440,13 @@ class InvenTreeModel {
|
|||||||
final results = list(filters: searchFilters);
|
final results = list(filters: searchFilters);
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the number of results that would meet a particular "query"
|
// Return the number of results that would meet a particular "query"
|
||||||
Future<int> count({Map<String, String> filters = const {}, String searchQuery = ""} ) async {
|
Future<int> count({
|
||||||
|
Map<String, String> filters = const {},
|
||||||
|
String searchQuery = "",
|
||||||
|
}) async {
|
||||||
var params = defaultListFilters();
|
var params = defaultListFilters();
|
||||||
|
|
||||||
filters.forEach((String key, String value) {
|
filters.forEach((String key, String value) {
|
||||||
@ -476,8 +486,11 @@ class InvenTreeModel {
|
|||||||
/*
|
/*
|
||||||
* Report error information to sentry, when a model operation fails.
|
* Report error information to sentry, when a model operation fails.
|
||||||
*/
|
*/
|
||||||
Future<void> reportModelError(String title, APIResponse response, {Map<String, String> context = const {}}) async {
|
Future<void> reportModelError(
|
||||||
|
String title,
|
||||||
|
APIResponse response, {
|
||||||
|
Map<String, String> context = const {},
|
||||||
|
}) async {
|
||||||
String dataString = response.data?.toString() ?? "null";
|
String dataString = response.data?.toString() ?? "null";
|
||||||
|
|
||||||
// If the response has "errorDetail" set, then the error has already been handled, and there is no need to continue
|
// If the response has "errorDetail" set, then the error has already been handled, and there is no need to continue
|
||||||
@ -506,16 +519,12 @@ class InvenTreeModel {
|
|||||||
context["dataType"] = response.data?.runtimeType.toString() ?? "null";
|
context["dataType"] = response.data?.runtimeType.toString() ?? "null";
|
||||||
context["model"] = URL;
|
context["model"] = URL;
|
||||||
|
|
||||||
await sentryReportMessage(
|
await sentryReportMessage(title, context: context);
|
||||||
title,
|
|
||||||
context: context,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delete the instance on the remote server
|
/// Delete the instance on the remote server
|
||||||
/// Returns true if the operation was successful, else false
|
/// Returns true if the operation was successful, else false
|
||||||
Future<bool> delete() async {
|
Future<bool> delete() async {
|
||||||
|
|
||||||
// Return if we do not have a valid pk
|
// Return if we do not have a valid pk
|
||||||
if (pk < 0) {
|
if (pk < 0) {
|
||||||
return false;
|
return false;
|
||||||
@ -523,18 +532,15 @@ class InvenTreeModel {
|
|||||||
|
|
||||||
var response = await api.delete(url);
|
var response = await api.delete(url);
|
||||||
|
|
||||||
if (!response.isValid() || response.data == null || (response.data is! Map)) {
|
if (!response.isValid() ||
|
||||||
|
response.data == null ||
|
||||||
|
(response.data is! Map)) {
|
||||||
reportModelError(
|
reportModelError(
|
||||||
"InvenTreeModel.delete() returned invalid response",
|
"InvenTreeModel.delete() returned invalid response",
|
||||||
response,
|
response,
|
||||||
);
|
);
|
||||||
|
|
||||||
showServerError(
|
showServerError(url, L10().serverError, L10().errorDelete);
|
||||||
url,
|
|
||||||
L10().serverError,
|
|
||||||
L10().errorDelete,
|
|
||||||
);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -547,52 +553,40 @@ class InvenTreeModel {
|
|||||||
* Reload this object, by requesting data from the server
|
* Reload this object, by requesting data from the server
|
||||||
*/
|
*/
|
||||||
Future<bool> reload() async {
|
Future<bool> reload() async {
|
||||||
|
|
||||||
// If we do not have a valid pk (for some reason), exit immediately
|
// If we do not have a valid pk (for some reason), exit immediately
|
||||||
if (pk < 0) {
|
if (pk < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = await api.get(url, params: defaultGetFilters(), expectedStatusCode: 200);
|
var response = await api.get(
|
||||||
|
url,
|
||||||
|
params: defaultGetFilters(),
|
||||||
|
expectedStatusCode: 200,
|
||||||
|
);
|
||||||
|
|
||||||
// A valid response has been returned
|
// A valid response has been returned
|
||||||
if (response.isValid() && response.statusCode == 200) {
|
if (response.isValid() && response.statusCode == 200) {
|
||||||
|
|
||||||
// Returned data was not a valid JSON object
|
// Returned data was not a valid JSON object
|
||||||
if (response.data == null || response.data is! Map) {
|
if (response.data == null || response.data is! Map) {
|
||||||
reportModelError(
|
reportModelError(
|
||||||
"InvenTreeModel.reload() returned invalid response",
|
"InvenTreeModel.reload() returned invalid response",
|
||||||
response,
|
response,
|
||||||
context: {
|
context: {"pk": pk.toString()},
|
||||||
"pk": pk.toString(),
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
showServerError(
|
showServerError(url, L10().serverError, L10().responseInvalid);
|
||||||
url,
|
|
||||||
L10().serverError,
|
|
||||||
L10().responseInvalid,
|
|
||||||
);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
switch (response.statusCode) {
|
switch (response.statusCode) {
|
||||||
case 404: // Object has been deleted
|
case 404: // Object has been deleted
|
||||||
showSnackIcon(
|
showSnackIcon(L10().itemDeleted, success: false);
|
||||||
L10().itemDeleted,
|
|
||||||
success: false,
|
|
||||||
);
|
|
||||||
default:
|
default:
|
||||||
String detail = L10().errorFetch;
|
String detail = L10().errorFetch;
|
||||||
detail += "\n${L10().statusCode}: ${response.statusCode}";
|
detail += "\n${L10().statusCode}: ${response.statusCode}";
|
||||||
|
|
||||||
showServerError(
|
showServerError(url, L10().serverError, detail);
|
||||||
url,
|
|
||||||
L10().serverError,
|
|
||||||
detail
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -606,15 +600,15 @@ class InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// POST data to update the model
|
// POST data to update the model
|
||||||
Future<APIResponse> update({Map<String, String> values = const {}, int? expectedStatusCode = 200}) async {
|
Future<APIResponse> update({
|
||||||
|
Map<String, String> values = const {},
|
||||||
|
int? expectedStatusCode = 200,
|
||||||
|
}) async {
|
||||||
var url = path.join(URL, pk.toString());
|
var url = path.join(URL, pk.toString());
|
||||||
|
|
||||||
// Return if we do not have a valid pk
|
// Return if we do not have a valid pk
|
||||||
if (pk < 0) {
|
if (pk < 0) {
|
||||||
return APIResponse(
|
return APIResponse(url: url);
|
||||||
url: url,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!url.endsWith("/")) {
|
if (!url.endsWith("/")) {
|
||||||
@ -631,8 +625,10 @@ class InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return the detail view for the associated pk
|
// Return the detail view for the associated pk
|
||||||
Future<InvenTreeModel?> getModel(String pk, {Map<String, String> filters = const {}}) async {
|
Future<InvenTreeModel?> getModel(
|
||||||
|
String pk, {
|
||||||
|
Map<String, String> filters = const {},
|
||||||
|
}) async {
|
||||||
var url = path.join(URL, pk.toString());
|
var url = path.join(URL, pk.toString());
|
||||||
|
|
||||||
if (!url.endsWith("/")) {
|
if (!url.endsWith("/")) {
|
||||||
@ -649,27 +645,18 @@ class InvenTreeModel {
|
|||||||
var response = await api.get(url, params: params);
|
var response = await api.get(url, params: params);
|
||||||
|
|
||||||
if (!response.isValid() || response.data == null || response.data is! Map) {
|
if (!response.isValid() || response.data == null || response.data is! Map) {
|
||||||
|
|
||||||
if (response.statusCode != -1) {
|
if (response.statusCode != -1) {
|
||||||
// Report error
|
// Report error
|
||||||
reportModelError(
|
reportModelError(
|
||||||
"InvenTreeModel.getModel() returned invalid response",
|
"InvenTreeModel.getModel() returned invalid response",
|
||||||
response,
|
response,
|
||||||
context: {
|
context: {"filters": filters.toString(), "pk": pk},
|
||||||
"filters": filters.toString(),
|
|
||||||
"pk": pk,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
showServerError(
|
showServerError(url, L10().serverError, L10().errorFetch);
|
||||||
url,
|
|
||||||
L10().serverError,
|
|
||||||
L10().errorFetch,
|
|
||||||
);
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lastReload = DateTime.now();
|
lastReload = DateTime.now();
|
||||||
@ -677,8 +664,10 @@ class InvenTreeModel {
|
|||||||
return createFromJson(response.asMap());
|
return createFromJson(response.asMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<InvenTreeModel?> get(int pk, {Map<String, String> filters = const {}}) async {
|
Future<InvenTreeModel?> get(
|
||||||
|
int pk, {
|
||||||
|
Map<String, String> filters = const {},
|
||||||
|
}) async {
|
||||||
if (pk < 0) {
|
if (pk < 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -687,7 +676,6 @@ class InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<InvenTreeModel?> create(Map<String, dynamic> data) async {
|
Future<InvenTreeModel?> create(Map<String, dynamic> data) async {
|
||||||
|
|
||||||
if (data.containsKey("pk")) {
|
if (data.containsKey("pk")) {
|
||||||
data.remove("pk");
|
data.remove("pk");
|
||||||
}
|
}
|
||||||
@ -700,20 +688,13 @@ class InvenTreeModel {
|
|||||||
|
|
||||||
// Invalid response returned from server
|
// Invalid response returned from server
|
||||||
if (!response.isValid() || response.data == null || response.data is! Map) {
|
if (!response.isValid() || response.data == null || response.data is! Map) {
|
||||||
|
|
||||||
reportModelError(
|
reportModelError(
|
||||||
"InvenTreeModel.create() returned invalid response",
|
"InvenTreeModel.create() returned invalid response",
|
||||||
response,
|
response,
|
||||||
context: {
|
context: {"pk": pk.toString()},
|
||||||
"pk": pk.toString(),
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
showServerError(
|
showServerError(URL, L10().serverError, L10().errorCreate);
|
||||||
URL,
|
|
||||||
L10().serverError,
|
|
||||||
L10().errorCreate,
|
|
||||||
);
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -721,7 +702,11 @@ class InvenTreeModel {
|
|||||||
return createFromJson(response.asMap());
|
return createFromJson(response.asMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<InvenTreePageResponse?> listPaginated(int limit, int offset, {Map<String, String> filters = const {}}) async {
|
Future<InvenTreePageResponse?> listPaginated(
|
||||||
|
int limit,
|
||||||
|
int offset, {
|
||||||
|
Map<String, String> filters = const {},
|
||||||
|
}) async {
|
||||||
var params = defaultListFilters();
|
var params = defaultListFilters();
|
||||||
|
|
||||||
for (String key in filters.keys) {
|
for (String key in filters.keys) {
|
||||||
@ -737,7 +722,6 @@ class InvenTreeModel {
|
|||||||
* - In such a case, we want to concatenate them together
|
* - In such a case, we want to concatenate them together
|
||||||
*/
|
*/
|
||||||
if (params.containsKey("original_search")) {
|
if (params.containsKey("original_search")) {
|
||||||
|
|
||||||
String search = params["search"] ?? "";
|
String search = params["search"] ?? "";
|
||||||
String original = params["original_search"] ?? "";
|
String original = params["original_search"] ?? "";
|
||||||
|
|
||||||
@ -759,7 +743,9 @@ class InvenTreeModel {
|
|||||||
|
|
||||||
// First attempt is to look for paginated data, returned as a map
|
// First attempt is to look for paginated data, returned as a map
|
||||||
|
|
||||||
if (dataMap.isNotEmpty && dataMap.containsKey("count") && dataMap.containsKey("results")) {
|
if (dataMap.isNotEmpty &&
|
||||||
|
dataMap.containsKey("count") &&
|
||||||
|
dataMap.containsKey("results")) {
|
||||||
page.count = (dataMap["count"] ?? 0) as int;
|
page.count = (dataMap["count"] ?? 0) as int;
|
||||||
|
|
||||||
page.results = [];
|
page.results = [];
|
||||||
@ -792,7 +778,9 @@ class InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return list of objects from the database, with optional filters
|
// Return list of objects from the database, with optional filters
|
||||||
Future<List<InvenTreeModel>> list({Map<String, String> filters = const {}}) async {
|
Future<List<InvenTreeModel>> list({
|
||||||
|
Map<String, String> filters = const {},
|
||||||
|
}) async {
|
||||||
var params = defaultListFilters();
|
var params = defaultListFilters();
|
||||||
|
|
||||||
for (String key in filters.keys) {
|
for (String key in filters.keys) {
|
||||||
@ -821,7 +809,6 @@ class InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (var d in data) {
|
for (var d in data) {
|
||||||
|
|
||||||
// Create a new object (of the current class type
|
// Create a new object (of the current class type
|
||||||
InvenTreeModel obj = createFromJson(d as Map<String, dynamic>);
|
InvenTreeModel obj = createFromJson(d as Map<String, dynamic>);
|
||||||
|
|
||||||
@ -847,7 +834,6 @@ class InvenTreeModel {
|
|||||||
// Each filter must be matched
|
// Each filter must be matched
|
||||||
// Used for (e.g.) filtering returned results
|
// Used for (e.g.) filtering returned results
|
||||||
bool filter(String filterString) {
|
bool filter(String filterString) {
|
||||||
|
|
||||||
List<String> filters = filterString.trim().toLowerCase().split(" ");
|
List<String> filters = filterString.trim().toLowerCase().split(" ");
|
||||||
|
|
||||||
for (var f in filters) {
|
for (var f in filters) {
|
||||||
@ -860,22 +846,20 @@ class InvenTreeModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing a single plugin instance
|
* Class representing a single plugin instance
|
||||||
*/
|
*/
|
||||||
class InvenTreePlugin extends InvenTreeModel {
|
class InvenTreePlugin extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreePlugin() : super();
|
InvenTreePlugin() : super();
|
||||||
|
|
||||||
InvenTreePlugin.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreePlugin.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePlugin.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreePlugin.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL {
|
String get URL {
|
||||||
|
|
||||||
/* Note: The plugin API endpoint changed at API version 90,
|
/* Note: The plugin API endpoint changed at API version 90,
|
||||||
* < 90 = 'plugin'
|
* < 90 = 'plugin'
|
||||||
* >= 90 = 'plugins'
|
* >= 90 = 'plugins'
|
||||||
@ -893,19 +877,20 @@ class InvenTreePlugin extends InvenTreeModel {
|
|||||||
bool get active => getBool("active");
|
bool get active => getBool("active");
|
||||||
|
|
||||||
// Return the metadata struct for this plugin
|
// Return the metadata struct for this plugin
|
||||||
Map<String, dynamic> get _meta => (jsondata["meta"] ?? {}) as Map<String, dynamic>;
|
Map<String, dynamic> get _meta =>
|
||||||
|
(jsondata["meta"] ?? {}) as Map<String, dynamic>;
|
||||||
|
|
||||||
String get humanName => (_meta["human_name"] ?? "") as String;
|
String get humanName => (_meta["human_name"] ?? "") as String;
|
||||||
|
|
||||||
// Return the mixins struct for this plugin
|
// Return the mixins struct for this plugin
|
||||||
Map<String, dynamic> get _mixins => (jsondata["mixins"] ?? {}) as Map<String, dynamic>;
|
Map<String, dynamic> get _mixins =>
|
||||||
|
(jsondata["mixins"] ?? {}) as Map<String, dynamic>;
|
||||||
|
|
||||||
bool supportsMixin(String mixin) {
|
bool supportsMixin(String mixin) {
|
||||||
return _mixins.containsKey(mixin);
|
return _mixins.containsKey(mixin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing a 'setting' object on the InvenTree server.
|
* Class representing a 'setting' object on the InvenTree server.
|
||||||
* There are two sorts of settings available from the server, via the API:
|
* There are two sorts of settings available from the server, via the API:
|
||||||
@ -913,10 +898,10 @@ class InvenTreePlugin extends InvenTreeModel {
|
|||||||
* - UserSetting (applicable only to the current user)
|
* - UserSetting (applicable only to the current user)
|
||||||
*/
|
*/
|
||||||
class InvenTreeGlobalSetting extends InvenTreeModel {
|
class InvenTreeGlobalSetting extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeGlobalSetting() : super();
|
InvenTreeGlobalSetting() : super();
|
||||||
|
|
||||||
InvenTreeGlobalSetting.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeGlobalSetting.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeGlobalSetting createFromJson(Map<String, dynamic> json) {
|
InvenTreeGlobalSetting createFromJson(Map<String, dynamic> json) {
|
||||||
@ -931,14 +916,13 @@ class InvenTreeGlobalSetting extends InvenTreeModel {
|
|||||||
String get value => getString("value");
|
String get value => getString("value");
|
||||||
|
|
||||||
String get type => getString("type");
|
String get type => getString("type");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class InvenTreeUserSetting extends InvenTreeGlobalSetting {
|
class InvenTreeUserSetting extends InvenTreeGlobalSetting {
|
||||||
|
|
||||||
InvenTreeUserSetting() : super();
|
InvenTreeUserSetting() : super();
|
||||||
|
|
||||||
InvenTreeUserSetting.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeUserSetting.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeGlobalSetting createFromJson(Map<String, dynamic> json) {
|
InvenTreeGlobalSetting createFromJson(Map<String, dynamic> json) {
|
||||||
@ -949,22 +933,19 @@ class InvenTreeUserSetting extends InvenTreeGlobalSetting {
|
|||||||
String get URL => "settings/user/";
|
String get URL => "settings/user/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeAttachment extends InvenTreeModel {
|
class InvenTreeAttachment extends InvenTreeModel {
|
||||||
// Class representing an "attachment" file
|
// Class representing an "attachment" file
|
||||||
InvenTreeAttachment() : super();
|
InvenTreeAttachment() : super();
|
||||||
|
|
||||||
InvenTreeAttachment.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeAttachment.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "attachment/";
|
String get URL => "attachment/";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, Map<String, dynamic>> formFields() {
|
Map<String, Map<String, dynamic>> formFields() {
|
||||||
Map<String, Map<String, dynamic>> fields = {
|
Map<String, Map<String, dynamic>> fields = {"link": {}, "comment": {}};
|
||||||
"link": {},
|
|
||||||
"comment": {}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!hasLink) {
|
if (!hasLink) {
|
||||||
fields.remove("link");
|
fields.remove("link");
|
||||||
@ -1004,13 +985,7 @@ class InvenTreeAttachment extends InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Image formats
|
// Image formats
|
||||||
final List<String> img_formats = [
|
final List<String> img_formats = [".png", ".jpg", ".gif", ".bmp", ".svg"];
|
||||||
".png",
|
|
||||||
".jpg",
|
|
||||||
".gif",
|
|
||||||
".bmp",
|
|
||||||
".svg",
|
|
||||||
];
|
|
||||||
|
|
||||||
for (String fmt in img_formats) {
|
for (String fmt in img_formats) {
|
||||||
if (fn.endsWith(fmt)) {
|
if (fn.endsWith(fmt)) {
|
||||||
@ -1033,7 +1008,6 @@ class InvenTreeAttachment extends InvenTreeModel {
|
|||||||
|
|
||||||
// Return a count of how many attachments exist against the specified model ID
|
// Return a count of how many attachments exist against the specified model ID
|
||||||
Future<int> countAttachments(int modelId) {
|
Future<int> countAttachments(int modelId) {
|
||||||
|
|
||||||
Map<String, String> filters = {};
|
Map<String, String> filters = {};
|
||||||
|
|
||||||
if (InvenTreeAPI().supportsModernAttachments) {
|
if (InvenTreeAPI().supportsModernAttachments) {
|
||||||
@ -1046,8 +1020,12 @@ class InvenTreeAttachment extends InvenTreeModel {
|
|||||||
return count(filters: filters);
|
return count(filters: filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> uploadAttachment(File attachment, int modelId, {String comment = "", Map<String, String> fields = const {}}) async {
|
Future<bool> uploadAttachment(
|
||||||
|
File attachment,
|
||||||
|
int modelId, {
|
||||||
|
String comment = "",
|
||||||
|
Map<String, String> fields = const {},
|
||||||
|
}) async {
|
||||||
// Ensure that the correct reference field is set
|
// Ensure that the correct reference field is set
|
||||||
Map<String, String> data = Map<String, String>.from(fields);
|
Map<String, String> data = Map<String, String>.from(fields);
|
||||||
|
|
||||||
@ -1058,15 +1036,14 @@ class InvenTreeAttachment extends InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (InvenTreeAPI().supportsModernAttachments) {
|
if (InvenTreeAPI().supportsModernAttachments) {
|
||||||
|
|
||||||
url = "attachment/";
|
url = "attachment/";
|
||||||
data["model_id"] = modelId.toString();
|
data["model_id"] = modelId.toString();
|
||||||
data["model_type"] = REF_MODEL_TYPE;
|
data["model_type"] = REF_MODEL_TYPE;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (REFERENCE_FIELD.isEmpty) {
|
if (REFERENCE_FIELD.isEmpty) {
|
||||||
sentryReportMessage("uploadAttachment called with empty 'REFERENCE_FIELD'");
|
sentryReportMessage(
|
||||||
|
"uploadAttachment called with empty 'REFERENCE_FIELD'",
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1078,20 +1055,17 @@ class InvenTreeAttachment extends InvenTreeModel {
|
|||||||
attachment,
|
attachment,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
name: "attachment",
|
name: "attachment",
|
||||||
fields: data
|
fields: data,
|
||||||
);
|
);
|
||||||
|
|
||||||
return response.successful();
|
return response.successful();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Future<bool> uploadImage(int modelId, {String prefix = "InvenTree"}) async {
|
Future<bool> uploadImage(int modelId, {String prefix = "InvenTree"}) async {
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
await FilePickerDialog.pickImageFromCamera().then((File? file) {
|
await FilePickerDialog.pickImageFromCamera().then((File? file) {
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
|
|
||||||
String dir = path.dirname(file.path);
|
String dir = path.dirname(file.path);
|
||||||
String ext = path.extension(file.path);
|
String ext = path.extension(file.path);
|
||||||
String now = DateTime.now().toIso8601String().replaceAll(":", "-");
|
String now = DateTime.now().toIso8601String().replaceAll(":", "-");
|
||||||
@ -1105,7 +1079,8 @@ class InvenTreeAttachment extends InvenTreeModel {
|
|||||||
result = success;
|
result = success;
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
result ? L10().imageUploadSuccess : L10().imageUploadFailure,
|
result ? L10().imageUploadSuccess : L10().imageUploadFailure,
|
||||||
success: result);
|
success: result,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
@ -1118,14 +1093,10 @@ class InvenTreeAttachment extends InvenTreeModel {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Download this attachment file
|
* Download this attachment file
|
||||||
*/
|
*/
|
||||||
Future<void> downloadAttachment() async {
|
Future<void> downloadAttachment() async {
|
||||||
await InvenTreeAPI().downloadFile(attachment);
|
await InvenTreeAPI().downloadFile(attachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,10 +5,10 @@ import "package:inventree/inventree/model.dart";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class InvenTreeNotification extends InvenTreeModel {
|
class InvenTreeNotification extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeNotification() : super();
|
InvenTreeNotification() : super();
|
||||||
|
|
||||||
InvenTreeNotification.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeNotification.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeNotification createFromJson(Map<String, dynamic> json) {
|
InvenTreeNotification createFromJson(Map<String, dynamic> json) {
|
||||||
@ -20,11 +20,8 @@ class InvenTreeNotification extends InvenTreeModel {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, String> defaultListFilters() {
|
Map<String, String> defaultListFilters() {
|
||||||
|
|
||||||
// By default, only return 'unread' notifications
|
// By default, only return 'unread' notifications
|
||||||
return {
|
return {"read": "false"};
|
||||||
"read": "false",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String get message => getString("message");
|
String get message => getString("message");
|
||||||
@ -41,7 +38,6 @@ class InvenTreeNotification extends InvenTreeModel {
|
|||||||
* Dismiss this notification (mark as read)
|
* Dismiss this notification (mark as read)
|
||||||
*/
|
*/
|
||||||
Future<void> dismiss() async {
|
Future<void> dismiss() async {
|
||||||
|
|
||||||
if (api.apiVersion >= 82) {
|
if (api.apiVersion >= 82) {
|
||||||
// "Modern" API endpoint operates a little differently
|
// "Modern" API endpoint operates a little differently
|
||||||
await update(values: {"read": "true"});
|
await update(values: {"read": "true"});
|
||||||
@ -49,5 +45,4 @@ class InvenTreeNotification extends InvenTreeModel {
|
|||||||
await api.post("${url}read/");
|
await api.post("${url}read/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -2,16 +2,13 @@
|
|||||||
* Base model for various "orders" which share common properties
|
* Base model for various "orders" which share common properties
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import "package:inventree/inventree/model.dart";
|
import "package:inventree/inventree/model.dart";
|
||||||
import "package:inventree/inventree/part.dart";
|
import "package:inventree/inventree/part.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic class representing an "order"
|
* Generic class representing an "order"
|
||||||
*/
|
*/
|
||||||
class InvenTreeOrder extends InvenTreeModel {
|
class InvenTreeOrder extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeOrder() : super();
|
InvenTreeOrder() : super();
|
||||||
|
|
||||||
InvenTreeOrder.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeOrder.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
||||||
@ -34,7 +31,8 @@ class InvenTreeOrder extends InvenTreeModel {
|
|||||||
|
|
||||||
int get shipmentCount => getInt("shipments_count", backup: 0);
|
int get shipmentCount => getInt("shipments_count", backup: 0);
|
||||||
|
|
||||||
int get completedShipmentCount => getInt("completed_shipments_count", backup: 0);
|
int get completedShipmentCount =>
|
||||||
|
getInt("completed_shipments_count", backup: 0);
|
||||||
|
|
||||||
bool get complete => completedLineItemCount >= lineItemCount;
|
bool get complete => completedLineItemCount >= lineItemCount;
|
||||||
|
|
||||||
@ -46,14 +44,16 @@ class InvenTreeOrder extends InvenTreeModel {
|
|||||||
|
|
||||||
String get responsibleName => getString("name", subKey: "responsible_detail");
|
String get responsibleName => getString("name", subKey: "responsible_detail");
|
||||||
|
|
||||||
String get responsibleLabel => getString("label", subKey: "responsible_detail");
|
String get responsibleLabel =>
|
||||||
|
getString("label", subKey: "responsible_detail");
|
||||||
|
|
||||||
// Project code information
|
// Project code information
|
||||||
int get projectCodeId => getInt("project_code");
|
int get projectCodeId => getInt("project_code");
|
||||||
|
|
||||||
String get projectCode => getString("code", subKey: "project_code_detail");
|
String get projectCode => getString("code", subKey: "project_code_detail");
|
||||||
|
|
||||||
String get projectCodeDescription => getString("description", subKey: "project_code_detail");
|
String get projectCodeDescription =>
|
||||||
|
getString("description", subKey: "project_code_detail");
|
||||||
|
|
||||||
bool get hasProjectCode => projectCode.isNotEmpty;
|
bool get hasProjectCode => projectCode.isNotEmpty;
|
||||||
|
|
||||||
@ -84,12 +84,10 @@ class InvenTreeOrder extends InvenTreeModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic class representing an "order line"
|
* Generic class representing an "order line"
|
||||||
*/
|
*/
|
||||||
class InvenTreeOrderLine extends InvenTreeModel {
|
class InvenTreeOrderLine extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeOrderLine() : super();
|
InvenTreeOrderLine() : super();
|
||||||
|
|
||||||
InvenTreeOrderLine.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeOrderLine.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
||||||
@ -121,15 +119,14 @@ class InvenTreeOrderLine extends InvenTreeModel {
|
|||||||
String get targetDate => getDateString("target_date");
|
String get targetDate => getDateString("target_date");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic class representing an "ExtraLineItem"
|
* Generic class representing an "ExtraLineItem"
|
||||||
*/
|
*/
|
||||||
class InvenTreeExtraLineItem extends InvenTreeModel {
|
class InvenTreeExtraLineItem extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeExtraLineItem() : super();
|
InvenTreeExtraLineItem() : super();
|
||||||
|
|
||||||
InvenTreeExtraLineItem.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeExtraLineItem.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
int get orderId => getInt("order");
|
int get orderId => getInt("order");
|
||||||
|
|
||||||
@ -157,5 +154,4 @@ class InvenTreeExtraLineItem extends InvenTreeModel {
|
|||||||
"notes": {},
|
"notes": {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,15 +14,14 @@ import "package:inventree/inventree/model.dart";
|
|||||||
import "package:inventree/widget/part/category_display.dart";
|
import "package:inventree/widget/part/category_display.dart";
|
||||||
import "package:inventree/widget/part/part_detail.dart";
|
import "package:inventree/widget/part/part_detail.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing the PartCategory database model
|
* Class representing the PartCategory database model
|
||||||
*/
|
*/
|
||||||
class InvenTreePartCategory extends InvenTreeModel {
|
class InvenTreePartCategory extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreePartCategory() : super();
|
InvenTreePartCategory() : super();
|
||||||
|
|
||||||
InvenTreePartCategory.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreePartCategory.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "part/category/";
|
String get URL => "part/category/";
|
||||||
@ -38,15 +37,12 @@ class InvenTreePartCategory extends InvenTreeModel {
|
|||||||
// Default implementation does not do anything...
|
// Default implementation does not do anything...
|
||||||
return Navigator.push(
|
return Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => CategoryDisplayWidget(this)),
|
||||||
builder: (context) => CategoryDisplayWidget(this)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, Map<String, dynamic>> formFields() {
|
Map<String, Map<String, dynamic>> formFields() {
|
||||||
|
|
||||||
Map<String, Map<String, dynamic>> fields = {
|
Map<String, Map<String, dynamic>> fields = {
|
||||||
"name": {},
|
"name": {},
|
||||||
"description": {},
|
"description": {},
|
||||||
@ -60,7 +56,6 @@ class InvenTreePartCategory extends InvenTreeModel {
|
|||||||
String get pathstring => getString("pathstring");
|
String get pathstring => getString("pathstring");
|
||||||
|
|
||||||
String get parentPathString {
|
String get parentPathString {
|
||||||
|
|
||||||
List<String> psplit = pathstring.split("/");
|
List<String> psplit = pathstring.split("/");
|
||||||
|
|
||||||
if (psplit.isNotEmpty) {
|
if (psplit.isNotEmpty) {
|
||||||
@ -78,21 +73,22 @@ class InvenTreePartCategory extends InvenTreeModel {
|
|||||||
|
|
||||||
// Return the number of parts in this category
|
// Return the number of parts in this category
|
||||||
// Note that the API changed from 'parts' to 'part_count' (v69)
|
// Note that the API changed from 'parts' to 'part_count' (v69)
|
||||||
int get partcount => (jsondata["part_count"] ?? jsondata["parts"] ?? 0) as int;
|
int get partcount =>
|
||||||
|
(jsondata["part_count"] ?? jsondata["parts"] ?? 0) as int;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePartCategory.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreePartCategory.fromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing the PartTestTemplate database model
|
* Class representing the PartTestTemplate database model
|
||||||
*/
|
*/
|
||||||
class InvenTreePartTestTemplate extends InvenTreeModel {
|
class InvenTreePartTestTemplate extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreePartTestTemplate() : super();
|
InvenTreePartTestTemplate() : super();
|
||||||
|
|
||||||
InvenTreePartTestTemplate.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreePartTestTemplate.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "part/test-template/";
|
String get URL => "part/test-template/";
|
||||||
@ -110,10 +106,10 @@ class InvenTreePartTestTemplate extends InvenTreeModel {
|
|||||||
bool get requiresAttachment => getBool("requires_attachment");
|
bool get requiresAttachment => getBool("requires_attachment");
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePartTestTemplate.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreePartTestTemplate.fromJson(json);
|
||||||
|
|
||||||
bool passFailStatus() {
|
bool passFailStatus() {
|
||||||
|
|
||||||
var result = latestResult();
|
var result = latestResult();
|
||||||
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
@ -134,17 +130,16 @@ class InvenTreePartTestTemplate extends InvenTreeModel {
|
|||||||
|
|
||||||
return results.last;
|
return results.last;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Class representing the PartParameter database model
|
Class representing the PartParameter database model
|
||||||
*/
|
*/
|
||||||
class InvenTreePartParameter extends InvenTreeModel {
|
class InvenTreePartParameter extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreePartParameter() : super();
|
InvenTreePartParameter() : super();
|
||||||
|
|
||||||
InvenTreePartParameter.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreePartParameter.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "part/parameter/";
|
String get URL => "part/parameter/";
|
||||||
@ -153,11 +148,11 @@ class InvenTreePartParameter extends InvenTreeModel {
|
|||||||
List<String> get rolesRequired => ["part"];
|
List<String> get rolesRequired => ["part"];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePartParameter.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreePartParameter.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, Map<String, dynamic>> formFields() {
|
Map<String, Map<String, dynamic>> formFields() {
|
||||||
|
|
||||||
Map<String, Map<String, dynamic>> fields = {
|
Map<String, Map<String, dynamic>> fields = {
|
||||||
"header": {
|
"header": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -166,9 +161,7 @@ class InvenTreePartParameter extends InvenTreeModel {
|
|||||||
"help_text": description,
|
"help_text": description,
|
||||||
"value": "",
|
"value": "",
|
||||||
},
|
},
|
||||||
"data": {
|
"data": {"type": "string"},
|
||||||
"type": "string",
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
@ -197,14 +190,14 @@ class InvenTreePartParameter extends InvenTreeModel {
|
|||||||
|
|
||||||
String get units => getString("units", subKey: "template_detail");
|
String get units => getString("units", subKey: "template_detail");
|
||||||
|
|
||||||
bool get is_checkbox => getBool("checkbox", subKey: "template_detail", backup: false);
|
bool get is_checkbox =>
|
||||||
|
getBool("checkbox", subKey: "template_detail", backup: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing the Part database model
|
* Class representing the Part database model
|
||||||
*/
|
*/
|
||||||
class InvenTreePart extends InvenTreeModel {
|
class InvenTreePart extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreePart() : super();
|
InvenTreePart() : super();
|
||||||
|
|
||||||
InvenTreePart.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreePart.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
||||||
@ -223,9 +216,7 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
// Default implementation does not do anything...
|
// Default implementation does not do anything...
|
||||||
return Navigator.push(
|
return Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => PartDetailWidget(this)),
|
||||||
builder: (context) => PartDetailWidget(this)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,9 +250,7 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, String> defaultFilters() {
|
Map<String, String> defaultFilters() {
|
||||||
return {
|
return {"category_detail": "true"};
|
||||||
"category_detail": "true",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cached list of stock items
|
// Cached list of stock items
|
||||||
@ -270,14 +259,13 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
int get stockItemCount => stockItems.length;
|
int get stockItemCount => stockItems.length;
|
||||||
|
|
||||||
// Request stock items for this part
|
// Request stock items for this part
|
||||||
Future<void> getStockItems(BuildContext context, {bool showDialog=false}) async {
|
Future<void> getStockItems(
|
||||||
|
BuildContext context, {
|
||||||
await InvenTreeStockItem().list(
|
bool showDialog = false,
|
||||||
filters: {
|
}) async {
|
||||||
"part": "${pk}",
|
await InvenTreeStockItem()
|
||||||
"in_stock": "true",
|
.list(filters: {"part": "${pk}", "in_stock": "true"})
|
||||||
},
|
.then((var items) {
|
||||||
).then((var items) {
|
|
||||||
stockItems.clear();
|
stockItems.clear();
|
||||||
|
|
||||||
for (var item in items) {
|
for (var item in items) {
|
||||||
@ -290,7 +278,6 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
|
|
||||||
// Request pricing data for this part
|
// Request pricing data for this part
|
||||||
Future<InvenTreePartPricing?> getPricing() async {
|
Future<InvenTreePartPricing?> getPricing() async {
|
||||||
|
|
||||||
print("REQUEST PRICING FOR: ${pk}");
|
print("REQUEST PRICING FOR: ${pk}");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -317,9 +304,7 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
List<InvenTreeSupplierPart> _supplierParts = [];
|
List<InvenTreeSupplierPart> _supplierParts = [];
|
||||||
|
|
||||||
final parts = await InvenTreeSupplierPart().list(
|
final parts = await InvenTreeSupplierPart().list(
|
||||||
filters: {
|
filters: {"part": "${pk}"},
|
||||||
"part": "${pk}",
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
for (var result in parts) {
|
for (var result in parts) {
|
||||||
@ -338,13 +323,9 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
|
|
||||||
// Request test templates from the serve
|
// Request test templates from the serve
|
||||||
Future<void> getTestTemplates() async {
|
Future<void> getTestTemplates() async {
|
||||||
|
InvenTreePartTestTemplate().list(filters: {"part": "${pk}"}).then((
|
||||||
InvenTreePartTestTemplate().list(
|
var templates,
|
||||||
filters: {
|
) {
|
||||||
"part": "${pk}",
|
|
||||||
},
|
|
||||||
).then((var templates) {
|
|
||||||
|
|
||||||
testingTemplates.clear();
|
testingTemplates.clear();
|
||||||
|
|
||||||
for (var t in templates) {
|
for (var t in templates) {
|
||||||
@ -373,12 +354,12 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
|
|
||||||
// Get the 'available stock' for this Part
|
// Get the 'available stock' for this Part
|
||||||
double get unallocatedStock {
|
double get unallocatedStock {
|
||||||
|
|
||||||
double unallocated = 0;
|
double unallocated = 0;
|
||||||
|
|
||||||
// Note that the 'available_stock' was not added until API v35
|
// Note that the 'available_stock' was not added until API v35
|
||||||
if (jsondata.containsKey("unallocated_stock")) {
|
if (jsondata.containsKey("unallocated_stock")) {
|
||||||
unallocated = double.tryParse(jsondata["unallocated_stock"].toString()) ?? 0;
|
unallocated =
|
||||||
|
double.tryParse(jsondata["unallocated_stock"].toString()) ?? 0;
|
||||||
} else {
|
} else {
|
||||||
unallocated = inStock;
|
unallocated = inStock;
|
||||||
}
|
}
|
||||||
@ -411,7 +392,8 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
double get building => getDouble("building");
|
double get building => getDouble("building");
|
||||||
|
|
||||||
// Get the number of BOMs this Part is used in (if it is a component)
|
// Get the number of BOMs this Part is used in (if it is a component)
|
||||||
int get usedInCount => jsondata.containsKey("used_in") ? getInt("used_in", backup: 0) : 0;
|
int get usedInCount =>
|
||||||
|
jsondata.containsKey("used_in") ? getInt("used_in", backup: 0) : 0;
|
||||||
|
|
||||||
bool get isAssembly => getBool("assembly");
|
bool get isAssembly => getBool("assembly");
|
||||||
|
|
||||||
@ -457,6 +439,7 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
|
|
||||||
return (jsondata["category_detail"]?["description"] ?? "") as String;
|
return (jsondata["category_detail"]?["description"] ?? "") as String;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the image URL for the Part instance
|
// Get the image URL for the Part instance
|
||||||
String get _image => getString("image");
|
String get _image => getString("image");
|
||||||
|
|
||||||
@ -465,7 +448,6 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
|
|
||||||
// Return the fully-qualified name for the Part instance
|
// Return the fully-qualified name for the Part instance
|
||||||
String get fullname {
|
String get fullname {
|
||||||
|
|
||||||
String fn = getString("full_name");
|
String fn = getString("full_name");
|
||||||
|
|
||||||
if (fn.isNotEmpty) return fn;
|
if (fn.isNotEmpty) return fn;
|
||||||
@ -513,21 +495,22 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
bool get starred => getBool("starred");
|
bool get starred => getBool("starred");
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePart.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreePart.fromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class InvenTreePartPricing extends InvenTreeModel {
|
class InvenTreePartPricing extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreePartPricing() : super();
|
InvenTreePartPricing() : super();
|
||||||
|
|
||||||
InvenTreePartPricing.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreePartPricing.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get rolesRequired => ["part"];
|
List<String> get rolesRequired => ["part"];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePartPricing.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreePartPricing.fromJson(json);
|
||||||
|
|
||||||
// Price data accessors
|
// Price data accessors
|
||||||
String get currency => getString("currency", backup: "USD");
|
String get currency => getString("currency", backup: "USD");
|
||||||
@ -538,8 +521,10 @@ class InvenTreePartPricing extends InvenTreeModel {
|
|||||||
double? get overrideMin => getDoubleOrNull("override_min");
|
double? get overrideMin => getDoubleOrNull("override_min");
|
||||||
double? get overrideMax => getDoubleOrNull("override_max");
|
double? get overrideMax => getDoubleOrNull("override_max");
|
||||||
|
|
||||||
String get overrideMinCurrency => getString("override_min_currency", backup: currency);
|
String get overrideMinCurrency =>
|
||||||
String get overrideMaxCurrency => getString("override_max_currency", backup: currency);
|
getString("override_min_currency", backup: currency);
|
||||||
|
String get overrideMaxCurrency =>
|
||||||
|
getString("override_max_currency", backup: currency);
|
||||||
|
|
||||||
double? get bomCostMin => getDoubleOrNull("bom_cost_min");
|
double? get bomCostMin => getDoubleOrNull("bom_cost_min");
|
||||||
double? get bomCostMax => getDoubleOrNull("bom_cost_max");
|
double? get bomCostMax => getDoubleOrNull("bom_cost_max");
|
||||||
@ -563,15 +548,14 @@ class InvenTreePartPricing extends InvenTreeModel {
|
|||||||
double? get saleHistoryMax => getDoubleOrNull("sale_history_max");
|
double? get saleHistoryMax => getDoubleOrNull("sale_history_max");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing an attachment file against a Part object
|
* Class representing an attachment file against a Part object
|
||||||
*/
|
*/
|
||||||
class InvenTreePartAttachment extends InvenTreeAttachment {
|
class InvenTreePartAttachment extends InvenTreeAttachment {
|
||||||
|
|
||||||
InvenTreePartAttachment() : super();
|
InvenTreePartAttachment() : super();
|
||||||
|
|
||||||
InvenTreePartAttachment.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreePartAttachment.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get REFERENCE_FIELD => "part";
|
String get REFERENCE_FIELD => "part";
|
||||||
@ -580,9 +564,11 @@ class InvenTreePartAttachment extends InvenTreeAttachment {
|
|||||||
String get REF_MODEL_TYPE => "part";
|
String get REF_MODEL_TYPE => "part";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => InvenTreeAPI().supportsModernAttachments ? "attachment/" : "part/attachment/";
|
String get URL => InvenTreeAPI().supportsModernAttachments
|
||||||
|
? "attachment/"
|
||||||
|
: "part/attachment/";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePartAttachment.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreePartAttachment.fromJson(json);
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
import "package:inventree/inventree/model.dart";
|
import "package:inventree/inventree/model.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing the ProjectCode database model
|
* Class representing the ProjectCode database model
|
||||||
*/
|
*/
|
||||||
class InvenTreeProjectCode extends InvenTreeModel {
|
class InvenTreeProjectCode extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeProjectCode() : super();
|
InvenTreeProjectCode() : super();
|
||||||
|
|
||||||
InvenTreeProjectCode.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeProjectCode.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeProjectCode.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeProjectCode.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "project-code/";
|
String get URL => "project-code/";
|
||||||
@ -20,10 +20,7 @@ class InvenTreeProjectCode extends InvenTreeModel {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, Map<String, dynamic>> formFields() {
|
Map<String, Map<String, dynamic>> formFields() {
|
||||||
return {
|
return {"code": {}, "description": {}};
|
||||||
"code": {},
|
|
||||||
"description": {},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String get code => getString("code");
|
String get code => getString("code");
|
||||||
|
@ -12,18 +12,18 @@ import "package:inventree/widget/progress.dart";
|
|||||||
import "package:inventree/api_form.dart";
|
import "package:inventree/api_form.dart";
|
||||||
import "package:inventree/l10.dart";
|
import "package:inventree/l10.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing an individual PurchaseOrder instance
|
* Class representing an individual PurchaseOrder instance
|
||||||
*/
|
*/
|
||||||
class InvenTreePurchaseOrder extends InvenTreeOrder {
|
class InvenTreePurchaseOrder extends InvenTreeOrder {
|
||||||
|
|
||||||
InvenTreePurchaseOrder() : super();
|
InvenTreePurchaseOrder() : super();
|
||||||
|
|
||||||
InvenTreePurchaseOrder.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreePurchaseOrder.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePurchaseOrder.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreePurchaseOrder.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "order/po/";
|
String get URL => "order/po/";
|
||||||
@ -32,9 +32,7 @@ class InvenTreePurchaseOrder extends InvenTreeOrder {
|
|||||||
Future<Object?> goToDetailPage(BuildContext context) async {
|
Future<Object?> goToDetailPage(BuildContext context) async {
|
||||||
return Navigator.push(
|
return Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => PurchaseOrderDetailWidget(this)),
|
||||||
builder: (context) => PurchaseOrderDetailWidget(this)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,9 +48,7 @@ class InvenTreePurchaseOrder extends InvenTreeOrder {
|
|||||||
Map<String, Map<String, dynamic>> fields = {
|
Map<String, Map<String, dynamic>> fields = {
|
||||||
"reference": {},
|
"reference": {},
|
||||||
"supplier": {
|
"supplier": {
|
||||||
"filters": {
|
"filters": {"is_supplier": true},
|
||||||
"is_supplier": true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
"supplier_reference": {},
|
"supplier_reference": {},
|
||||||
"description": {},
|
"description": {},
|
||||||
@ -63,9 +59,7 @@ class InvenTreePurchaseOrder extends InvenTreeOrder {
|
|||||||
"link": {},
|
"link": {},
|
||||||
"responsible": {},
|
"responsible": {},
|
||||||
"contact": {
|
"contact": {
|
||||||
"filters": {
|
"filters": {"company": supplierId},
|
||||||
"company": supplierId,
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -82,20 +76,16 @@ class InvenTreePurchaseOrder extends InvenTreeOrder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, String> defaultFilters() {
|
Map<String, String> defaultFilters() {
|
||||||
return {
|
return {"supplier_detail": "true"};
|
||||||
"supplier_detail": "true",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int get supplierId => getInt("supplier");
|
int get supplierId => getInt("supplier");
|
||||||
|
|
||||||
InvenTreeCompany? get supplier {
|
InvenTreeCompany? get supplier {
|
||||||
|
|
||||||
dynamic supplier_detail = jsondata["supplier_detail"];
|
dynamic supplier_detail = jsondata["supplier_detail"];
|
||||||
|
|
||||||
if (supplier_detail == null) {
|
if (supplier_detail == null) {
|
||||||
@ -109,20 +99,26 @@ class InvenTreePurchaseOrder extends InvenTreeOrder {
|
|||||||
|
|
||||||
int get destinationId => getInt("destination");
|
int get destinationId => getInt("destination");
|
||||||
|
|
||||||
bool get isOpen => api.PurchaseOrderStatus.isNameIn(status, ["PENDING", "PLACED", "ON_HOLD"]);
|
bool get isOpen => api.PurchaseOrderStatus.isNameIn(status, [
|
||||||
|
"PENDING",
|
||||||
|
"PLACED",
|
||||||
|
"ON_HOLD",
|
||||||
|
]);
|
||||||
|
|
||||||
bool get isPending => api.PurchaseOrderStatus.isNameIn(status, ["PENDING", "ON_HOLD"]);
|
bool get isPending =>
|
||||||
|
api.PurchaseOrderStatus.isNameIn(status, ["PENDING", "ON_HOLD"]);
|
||||||
|
|
||||||
bool get isPlaced => api.PurchaseOrderStatus.isNameIn(status, ["PLACED"]);
|
bool get isPlaced => api.PurchaseOrderStatus.isNameIn(status, ["PLACED"]);
|
||||||
|
|
||||||
bool get isFailed => api.PurchaseOrderStatus.isNameIn(status, ["CANCELLED", "LOST", "RETURNED"]);
|
bool get isFailed => api.PurchaseOrderStatus.isNameIn(status, [
|
||||||
|
"CANCELLED",
|
||||||
|
"LOST",
|
||||||
|
"RETURNED",
|
||||||
|
]);
|
||||||
|
|
||||||
Future<List<InvenTreePOLineItem>> getLineItems() async {
|
Future<List<InvenTreePOLineItem>> getLineItems() async {
|
||||||
|
|
||||||
final results = await InvenTreePOLineItem().list(
|
final results = await InvenTreePOLineItem().list(
|
||||||
filters: {
|
filters: {"order": "${pk}"},
|
||||||
"order": "${pk}",
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
List<InvenTreePOLineItem> items = [];
|
List<InvenTreePOLineItem> items = [];
|
||||||
@ -161,13 +157,14 @@ class InvenTreePurchaseOrder extends InvenTreeOrder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class InvenTreePOLineItem extends InvenTreeOrderLine {
|
class InvenTreePOLineItem extends InvenTreeOrderLine {
|
||||||
|
|
||||||
InvenTreePOLineItem() : super();
|
InvenTreePOLineItem() : super();
|
||||||
|
|
||||||
InvenTreePOLineItem.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreePOLineItem.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePOLineItem.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreePOLineItem.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "order/po-line/";
|
String get URL => "order/po-line/";
|
||||||
@ -198,10 +195,7 @@ class InvenTreePOLineItem extends InvenTreeOrderLine {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, String> defaultFilters() {
|
Map<String, String> defaultFilters() {
|
||||||
return {
|
return {"part_detail": "true", "order_detail": "true"};
|
||||||
"part_detail": "true",
|
|
||||||
"order_detail": "true",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double get received => getDouble("received");
|
double get received => getDouble("received");
|
||||||
@ -216,14 +210,14 @@ class InvenTreePOLineItem extends InvenTreeOrderLine {
|
|||||||
return received / quantity;
|
return received / quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
String get progressString => simpleNumberString(received) + " / " + simpleNumberString(quantity);
|
String get progressString =>
|
||||||
|
simpleNumberString(received) + " / " + simpleNumberString(quantity);
|
||||||
|
|
||||||
double get outstanding => quantity - received;
|
double get outstanding => quantity - received;
|
||||||
|
|
||||||
int get supplierPartId => getInt("part");
|
int get supplierPartId => getInt("part");
|
||||||
|
|
||||||
InvenTreeSupplierPart? get supplierPart {
|
InvenTreeSupplierPart? get supplierPart {
|
||||||
|
|
||||||
dynamic detail = jsondata["supplier_part_detail"];
|
dynamic detail = jsondata["supplier_part_detail"];
|
||||||
|
|
||||||
if (detail == null) {
|
if (detail == null) {
|
||||||
@ -256,7 +250,13 @@ class InvenTreePOLineItem extends InvenTreeOrderLine {
|
|||||||
Map<String, dynamic> get destinationDetail => getMap("destination_detail");
|
Map<String, dynamic> get destinationDetail => getMap("destination_detail");
|
||||||
|
|
||||||
// Receive this line item into stock
|
// Receive this line item into stock
|
||||||
Future<void> receive(BuildContext context, {int? destination, double? quantity, String? barcode, Function? onSuccess}) async {
|
Future<void> receive(
|
||||||
|
BuildContext context, {
|
||||||
|
int? destination,
|
||||||
|
double? quantity,
|
||||||
|
String? barcode,
|
||||||
|
Function? onSuccess,
|
||||||
|
}) async {
|
||||||
// Infer the destination location from the line item if not provided
|
// Infer the destination location from the line item if not provided
|
||||||
if (destinationId > 0) {
|
if (destinationId > 0) {
|
||||||
destination = destinationId;
|
destination = destinationId;
|
||||||
@ -274,20 +274,10 @@ class InvenTreePOLineItem extends InvenTreeOrderLine {
|
|||||||
"hidden": true,
|
"hidden": true,
|
||||||
"value": pk,
|
"value": pk,
|
||||||
},
|
},
|
||||||
"quantity": {
|
"quantity": {"parent": "items", "nested": true, "value": quantity},
|
||||||
"parent": "items",
|
|
||||||
"nested": true,
|
|
||||||
"value": quantity,
|
|
||||||
},
|
|
||||||
"location": {},
|
"location": {},
|
||||||
"status": {
|
"status": {"parent": "items", "nested": true},
|
||||||
"parent": "items",
|
"batch_code": {"parent": "items", "nested": true},
|
||||||
"nested": true,
|
|
||||||
},
|
|
||||||
"batch_code": {
|
|
||||||
"parent": "items",
|
|
||||||
"nested": true,
|
|
||||||
},
|
|
||||||
"barcode": {
|
"barcode": {
|
||||||
"parent": "items",
|
"parent": "items",
|
||||||
"nested": true,
|
"nested": true,
|
||||||
@ -295,7 +285,7 @@ class InvenTreePOLineItem extends InvenTreeOrderLine {
|
|||||||
"label": L10().barcodeAssign,
|
"label": L10().barcodeAssign,
|
||||||
"value": barcode,
|
"value": barcode,
|
||||||
"required": false,
|
"required": false,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (destination != null && destination > 0) {
|
if (destination != null && destination > 0) {
|
||||||
@ -316,21 +306,21 @@ class InvenTreePOLineItem extends InvenTreeOrderLine {
|
|||||||
if (onSuccess != null) {
|
if (onSuccess != null) {
|
||||||
onSuccess();
|
onSuccess();
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class InvenTreePOExtraLineItem extends InvenTreeExtraLineItem {
|
class InvenTreePOExtraLineItem extends InvenTreeExtraLineItem {
|
||||||
|
|
||||||
InvenTreePOExtraLineItem() : super();
|
InvenTreePOExtraLineItem() : super();
|
||||||
|
|
||||||
InvenTreePOExtraLineItem.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreePOExtraLineItem.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePOExtraLineItem.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreePOExtraLineItem.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "order/po-extra-line/";
|
String get URL => "order/po-extra-line/";
|
||||||
@ -342,23 +332,19 @@ class InvenTreePOExtraLineItem extends InvenTreeExtraLineItem {
|
|||||||
Future<Object?> goToDetailPage(BuildContext context) async {
|
Future<Object?> goToDetailPage(BuildContext context) async {
|
||||||
return Navigator.push(
|
return Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => ExtraLineDetailWidget(this)),
|
||||||
builder: (context) => ExtraLineDetailWidget(this)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing an attachment file against a PurchaseOrder object
|
* Class representing an attachment file against a PurchaseOrder object
|
||||||
*/
|
*/
|
||||||
class InvenTreePurchaseOrderAttachment extends InvenTreeAttachment {
|
class InvenTreePurchaseOrderAttachment extends InvenTreeAttachment {
|
||||||
|
|
||||||
InvenTreePurchaseOrderAttachment() : super();
|
InvenTreePurchaseOrderAttachment() : super();
|
||||||
|
|
||||||
InvenTreePurchaseOrderAttachment.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreePurchaseOrderAttachment.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get REFERENCE_FIELD => "order";
|
String get REFERENCE_FIELD => "order";
|
||||||
@ -367,9 +353,11 @@ class InvenTreePurchaseOrderAttachment extends InvenTreeAttachment {
|
|||||||
String get REF_MODEL_TYPE => "purchaseorder";
|
String get REF_MODEL_TYPE => "purchaseorder";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => InvenTreeAPI().supportsModernAttachments ? "attachment/" : "order/po/attachment/";
|
String get URL => InvenTreeAPI().supportsModernAttachments
|
||||||
|
? "attachment/"
|
||||||
|
: "order/po/attachment/";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreePurchaseOrderAttachment.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreePurchaseOrderAttachment.fromJson(json);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:inventree/api.dart";
|
import "package:inventree/api.dart";
|
||||||
import "package:inventree/helpers.dart";
|
import "package:inventree/helpers.dart";
|
||||||
@ -11,18 +9,18 @@ import "package:inventree/widget/progress.dart";
|
|||||||
import "package:inventree/widget/order/extra_line_detail.dart";
|
import "package:inventree/widget/order/extra_line_detail.dart";
|
||||||
import "package:inventree/widget/order/sales_order_detail.dart";
|
import "package:inventree/widget/order/sales_order_detail.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing an individual SalesOrder
|
* Class representing an individual SalesOrder
|
||||||
*/
|
*/
|
||||||
class InvenTreeSalesOrder extends InvenTreeOrder {
|
class InvenTreeSalesOrder extends InvenTreeOrder {
|
||||||
|
|
||||||
InvenTreeSalesOrder() : super();
|
InvenTreeSalesOrder() : super();
|
||||||
|
|
||||||
InvenTreeSalesOrder.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeSalesOrder.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeSalesOrder.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeSalesOrder.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "order/so/";
|
String get URL => "order/so/";
|
||||||
@ -38,9 +36,7 @@ class InvenTreeSalesOrder extends InvenTreeOrder {
|
|||||||
Future<Object?> goToDetailPage(BuildContext context) async {
|
Future<Object?> goToDetailPage(BuildContext context) async {
|
||||||
return Navigator.push(
|
return Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => SalesOrderDetailWidget(this)),
|
||||||
builder: (context) => SalesOrderDetailWidget(this)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,9 +45,7 @@ class InvenTreeSalesOrder extends InvenTreeOrder {
|
|||||||
Map<String, Map<String, dynamic>> fields = {
|
Map<String, Map<String, dynamic>> fields = {
|
||||||
"reference": {},
|
"reference": {},
|
||||||
"customer": {
|
"customer": {
|
||||||
"filters": {
|
"filters": {"is_customer": true},
|
||||||
"is_customer": true,
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"customer_reference": {},
|
"customer_reference": {},
|
||||||
"description": {},
|
"description": {},
|
||||||
@ -61,10 +55,8 @@ class InvenTreeSalesOrder extends InvenTreeOrder {
|
|||||||
"link": {},
|
"link": {},
|
||||||
"responsible": {},
|
"responsible": {},
|
||||||
"contact": {
|
"contact": {
|
||||||
"filters": {
|
"filters": {"company": customerId},
|
||||||
"company": customerId,
|
},
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!InvenTreeAPI().supportsProjectCodes) {
|
if (!InvenTreeAPI().supportsProjectCodes) {
|
||||||
@ -84,9 +76,7 @@ class InvenTreeSalesOrder extends InvenTreeOrder {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, String> defaultFilters() {
|
Map<String, String> defaultFilters() {
|
||||||
return {
|
return {"customer_detail": "true"};
|
||||||
"customer_detail": "true",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> issueOrder() async {
|
Future<void> issueOrder() async {
|
||||||
@ -124,28 +114,33 @@ class InvenTreeSalesOrder extends InvenTreeOrder {
|
|||||||
|
|
||||||
String get customerReference => getString("customer_reference");
|
String get customerReference => getString("customer_reference");
|
||||||
|
|
||||||
bool get isOpen => api.SalesOrderStatus.isNameIn(status, ["PENDING", "IN_PROGRESS", "ON_HOLD"]);
|
bool get isOpen => api.SalesOrderStatus.isNameIn(status, [
|
||||||
|
"PENDING",
|
||||||
|
"IN_PROGRESS",
|
||||||
|
"ON_HOLD",
|
||||||
|
]);
|
||||||
|
|
||||||
bool get isPending => api.SalesOrderStatus.isNameIn(status, ["PENDING", "ON_HOLD"]);
|
bool get isPending =>
|
||||||
|
api.SalesOrderStatus.isNameIn(status, ["PENDING", "ON_HOLD"]);
|
||||||
|
|
||||||
bool get isInProgress => api.SalesOrderStatus.isNameIn(status, ["IN_PROGRESS"]);
|
bool get isInProgress =>
|
||||||
|
api.SalesOrderStatus.isNameIn(status, ["IN_PROGRESS"]);
|
||||||
|
|
||||||
bool get isComplete => api.SalesOrderStatus.isNameIn(status, ["SHIPPED"]);
|
bool get isComplete => api.SalesOrderStatus.isNameIn(status, ["SHIPPED"]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing an individual line item in a SalesOrder
|
* Class representing an individual line item in a SalesOrder
|
||||||
*/
|
*/
|
||||||
class InvenTreeSOLineItem extends InvenTreeOrderLine {
|
class InvenTreeSOLineItem extends InvenTreeOrderLine {
|
||||||
|
|
||||||
InvenTreeSOLineItem() : super();
|
InvenTreeSOLineItem() : super();
|
||||||
|
|
||||||
InvenTreeSOLineItem.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeSOLineItem.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeSOLineItem.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeSOLineItem.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "order/so-line/";
|
String get URL => "order/so-line/";
|
||||||
@ -156,13 +151,9 @@ class InvenTreeSOLineItem extends InvenTreeOrderLine {
|
|||||||
@override
|
@override
|
||||||
Map<String, Map<String, dynamic>> formFields() {
|
Map<String, Map<String, dynamic>> formFields() {
|
||||||
return {
|
return {
|
||||||
"order": {
|
"order": {"hidden": true},
|
||||||
"hidden": true,
|
|
||||||
},
|
|
||||||
"part": {
|
"part": {
|
||||||
"filters": {
|
"filters": {"salable": true},
|
||||||
"salable": true,
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"quantity": {},
|
"quantity": {},
|
||||||
"reference": {},
|
"reference": {},
|
||||||
@ -172,33 +163,17 @@ class InvenTreeSOLineItem extends InvenTreeOrderLine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Map<String, dynamic>> allocateFormFields() {
|
Map<String, Map<String, dynamic>> allocateFormFields() {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"line_item": {
|
"line_item": {"parent": "items", "nested": true, "hidden": true},
|
||||||
"parent": "items",
|
"stock_item": {"parent": "items", "nested": true, "filters": {}},
|
||||||
"nested": true,
|
"quantity": {"parent": "items", "nested": true},
|
||||||
"hidden": true,
|
"shipment": {"filters": {}},
|
||||||
},
|
|
||||||
"stock_item": {
|
|
||||||
"parent": "items",
|
|
||||||
"nested": true,
|
|
||||||
"filters": {},
|
|
||||||
},
|
|
||||||
"quantity": {
|
|
||||||
"parent": "items",
|
|
||||||
"nested": true,
|
|
||||||
},
|
|
||||||
"shipment": {
|
|
||||||
"filters": {}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, String> defaultFilters() {
|
Map<String, String> defaultFilters() {
|
||||||
return {
|
return {"part_detail": "true"};
|
||||||
"part_detail": "true",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double get allocated => getDouble("allocated");
|
double get allocated => getDouble("allocated");
|
||||||
@ -223,7 +198,8 @@ class InvenTreeSOLineItem extends InvenTreeOrderLine {
|
|||||||
return unallocated;
|
return unallocated;
|
||||||
}
|
}
|
||||||
|
|
||||||
String get allocatedString => simpleNumberString(allocated) + " / " + simpleNumberString(quantity);
|
String get allocatedString =>
|
||||||
|
simpleNumberString(allocated) + " / " + simpleNumberString(quantity);
|
||||||
|
|
||||||
double get shipped => getDouble("shipped");
|
double get shipped => getDouble("shipped");
|
||||||
|
|
||||||
@ -239,26 +215,28 @@ class InvenTreeSOLineItem extends InvenTreeOrderLine {
|
|||||||
return shipped / quantity;
|
return shipped / quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
String get progressString => simpleNumberString(shipped) + " / " + simpleNumberString(quantity);
|
String get progressString =>
|
||||||
|
simpleNumberString(shipped) + " / " + simpleNumberString(quantity);
|
||||||
|
|
||||||
bool get isComplete => shipped >= quantity;
|
bool get isComplete => shipped >= quantity;
|
||||||
|
|
||||||
double get available => getDouble("available_stock") + getDouble("available_variant_stock");
|
double get available =>
|
||||||
|
getDouble("available_stock") + getDouble("available_variant_stock");
|
||||||
|
|
||||||
double get salePrice => getDouble("sale_price");
|
double get salePrice => getDouble("sale_price");
|
||||||
|
|
||||||
String get salePriceCurrency => getString("sale_price_currency");
|
String get salePriceCurrency => getString("sale_price_currency");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeSOExtraLineItem extends InvenTreeExtraLineItem {
|
class InvenTreeSOExtraLineItem extends InvenTreeExtraLineItem {
|
||||||
InvenTreeSOExtraLineItem() : super();
|
InvenTreeSOExtraLineItem() : super();
|
||||||
|
|
||||||
InvenTreeSOExtraLineItem.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeSOExtraLineItem.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeSOExtraLineItem.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeSOExtraLineItem.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "order/so-extra-line/";
|
String get URL => "order/so-extra-line/";
|
||||||
@ -270,9 +248,7 @@ class InvenTreeSOExtraLineItem extends InvenTreeExtraLineItem {
|
|||||||
Future<Object?> goToDetailPage(BuildContext context) async {
|
Future<Object?> goToDetailPage(BuildContext context) async {
|
||||||
return Navigator.push(
|
return Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => ExtraLineDetailWidget(this)),
|
||||||
builder: (context) => ExtraLineDetailWidget(this)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -281,13 +257,14 @@ class InvenTreeSOExtraLineItem extends InvenTreeExtraLineItem {
|
|||||||
* Class representing a sales order shipment
|
* Class representing a sales order shipment
|
||||||
*/
|
*/
|
||||||
class InvenTreeSalesOrderShipment extends InvenTreeModel {
|
class InvenTreeSalesOrderShipment extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeSalesOrderShipment() : super();
|
InvenTreeSalesOrderShipment() : super();
|
||||||
|
|
||||||
InvenTreeSalesOrderShipment.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeSalesOrderShipment.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeSalesOrderShipment.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeSalesOrderShipment.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "/order/so/shipment/";
|
String get URL => "/order/so/shipment/";
|
||||||
@ -318,19 +295,18 @@ class InvenTreeSalesOrderShipment extends InvenTreeModel {
|
|||||||
bool get shipped => shipment_date != null && shipment_date!.isNotEmpty;
|
bool get shipped => shipment_date != null && shipment_date!.isNotEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing an attachment file against a SalesOrder object
|
* Class representing an attachment file against a SalesOrder object
|
||||||
*/
|
*/
|
||||||
class InvenTreeSalesOrderAttachment extends InvenTreeAttachment {
|
class InvenTreeSalesOrderAttachment extends InvenTreeAttachment {
|
||||||
|
|
||||||
InvenTreeSalesOrderAttachment() : super();
|
InvenTreeSalesOrderAttachment() : super();
|
||||||
|
|
||||||
InvenTreeSalesOrderAttachment.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeSalesOrderAttachment.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeSalesOrderAttachment.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeSalesOrderAttachment.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get REFERENCE_FIELD => "order";
|
String get REFERENCE_FIELD => "order";
|
||||||
@ -339,6 +315,7 @@ class InvenTreeSalesOrderAttachment extends InvenTreeAttachment {
|
|||||||
String get REF_MODEL_TYPE => "salesorder";
|
String get REF_MODEL_TYPE => "salesorder";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => InvenTreeAPI().supportsModernAttachments ? "attachment/" : "order/so/attachment/";
|
String get URL => InvenTreeAPI().supportsModernAttachments
|
||||||
|
? "attachment/"
|
||||||
|
: "order/so/attachment/";
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import "package:inventree/dsn.dart";
|
|||||||
import "package:inventree/preferences.dart";
|
import "package:inventree/preferences.dart";
|
||||||
|
|
||||||
Future<Map<String, dynamic>> getDeviceInfo() async {
|
Future<Map<String, dynamic>> getDeviceInfo() async {
|
||||||
|
|
||||||
// Extract device information
|
// Extract device information
|
||||||
final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||||
|
|
||||||
@ -31,7 +30,6 @@ Future<Map<String, dynamic>> getDeviceInfo() async {
|
|||||||
"identifierForVendor": iosDeviceInfo.identifierForVendor,
|
"identifierForVendor": iosDeviceInfo.identifierForVendor,
|
||||||
"isPhysicalDevice": iosDeviceInfo.isPhysicalDevice,
|
"isPhysicalDevice": iosDeviceInfo.isPhysicalDevice,
|
||||||
};
|
};
|
||||||
|
|
||||||
} else if (Platform.isAndroid) {
|
} else if (Platform.isAndroid) {
|
||||||
final androidDeviceInfo = await deviceInfo.androidInfo;
|
final androidDeviceInfo = await deviceInfo.androidInfo;
|
||||||
|
|
||||||
@ -57,13 +55,11 @@ Future<Map<String, dynamic>> getDeviceInfo() async {
|
|||||||
return device_info;
|
return device_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Map<String, dynamic> getServerInfo() => {
|
Map<String, dynamic> getServerInfo() => {
|
||||||
"version": InvenTreeAPI().serverVersion,
|
"version": InvenTreeAPI().serverVersion,
|
||||||
"apiVersion": InvenTreeAPI().apiVersion,
|
"apiVersion": InvenTreeAPI().apiVersion,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Future<Map<String, dynamic>> getAppInfo() async {
|
Future<Map<String, dynamic>> getAppInfo() async {
|
||||||
// Add app info
|
// Add app info
|
||||||
final package_info = await PackageInfo.fromPlatform();
|
final package_info = await PackageInfo.fromPlatform();
|
||||||
@ -76,7 +72,6 @@ Future<Map<String, dynamic>> getAppInfo() async {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool isInDebugMode() {
|
bool isInDebugMode() {
|
||||||
bool inDebugMode = false;
|
bool inDebugMode = false;
|
||||||
|
|
||||||
@ -85,8 +80,10 @@ bool isInDebugMode() {
|
|||||||
return inDebugMode;
|
return inDebugMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> sentryReportMessage(String message, {Map<String, String>? context}) async {
|
Future<bool> sentryReportMessage(
|
||||||
|
String message, {
|
||||||
|
Map<String, String>? context,
|
||||||
|
}) async {
|
||||||
if (SENTRY_DSN_KEY.isEmpty) {
|
if (SENTRY_DSN_KEY.isEmpty) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -106,23 +103,22 @@ Future<bool> sentryReportMessage(String message, {Map<String, String>? context})
|
|||||||
// We don't care about the server address, only the path and query parameters!
|
// We don't care about the server address, only the path and query parameters!
|
||||||
// Overwrite the provided URL
|
// Overwrite the provided URL
|
||||||
context["url"] = uri.path + "?" + uri.query;
|
context["url"] = uri.path + "?" + uri.query;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Ignore if any errors are thrown here
|
// Ignore if any errors are thrown here
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print("Sending user message to Sentry: ${message}, ${context}");
|
print("Sending user message to Sentry: ${message}, ${context}");
|
||||||
|
|
||||||
if (isInDebugMode()) {
|
if (isInDebugMode()) {
|
||||||
|
|
||||||
print("----- In dev mode. Not sending message to Sentry.io -----");
|
print("----- In dev mode. Not sending message to Sentry.io -----");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final upload = await InvenTreeSettingsManager().getValue(INV_REPORT_ERRORS, true) as bool;
|
final upload =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_REPORT_ERRORS, true)
|
||||||
|
as bool;
|
||||||
|
|
||||||
if (!upload) {
|
if (!upload) {
|
||||||
print("----- Error reporting disabled -----");
|
print("----- Error reporting disabled -----");
|
||||||
@ -152,12 +148,15 @@ Future<bool> sentryReportMessage(String message, {Map<String, String>? context})
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Report an error message to sentry.io
|
* Report an error message to sentry.io
|
||||||
*/
|
*/
|
||||||
Future<void> sentryReportError(String source, dynamic error, StackTrace? stackTrace, {Map<String, String> context = const {}}) async {
|
Future<void> sentryReportError(
|
||||||
|
String source,
|
||||||
|
dynamic error,
|
||||||
|
StackTrace? stackTrace, {
|
||||||
|
Map<String, String> context = const {},
|
||||||
|
}) async {
|
||||||
if (sentryIgnoreError(error)) {
|
if (sentryIgnoreError(error)) {
|
||||||
// No action on this error
|
// No action on this error
|
||||||
return;
|
return;
|
||||||
@ -170,7 +169,6 @@ Future<void> sentryReportError(String source, dynamic error, StackTrace? stackTr
|
|||||||
// check if you are running in dev mode using an assertion and omit sending
|
// check if you are running in dev mode using an assertion and omit sending
|
||||||
// the report.
|
// the report.
|
||||||
if (isInDebugMode()) {
|
if (isInDebugMode()) {
|
||||||
|
|
||||||
print("----- In dev mode. Not sending report to Sentry.io -----");
|
print("----- In dev mode. Not sending report to Sentry.io -----");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -179,7 +177,9 @@ Future<void> sentryReportError(String source, dynamic error, StackTrace? stackTr
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final upload = await InvenTreeSettingsManager().getValue(INV_REPORT_ERRORS, true) as bool;
|
final upload =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_REPORT_ERRORS, true)
|
||||||
|
as bool;
|
||||||
|
|
||||||
if (!upload) {
|
if (!upload) {
|
||||||
print("----- Error reporting disabled -----");
|
print("----- Error reporting disabled -----");
|
||||||
@ -188,11 +188,12 @@ Future<void> sentryReportError(String source, dynamic error, StackTrace? stackTr
|
|||||||
|
|
||||||
// Some errors are outside our control, and we do not want to "pollute" the uploaded data
|
// Some errors are outside our control, and we do not want to "pollute" the uploaded data
|
||||||
if (source == "FlutterError.onError") {
|
if (source == "FlutterError.onError") {
|
||||||
|
|
||||||
String errorString = error.toString();
|
String errorString = error.toString();
|
||||||
|
|
||||||
// Missing media file
|
// Missing media file
|
||||||
if (errorString.contains("HttpException") && errorString.contains("404") && errorString.contains("/media/")) {
|
if (errorString.contains("HttpException") &&
|
||||||
|
errorString.contains("404") &&
|
||||||
|
errorString.contains("/media/")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,23 +226,25 @@ Future<void> sentryReportError(String source, dynamic error, StackTrace? stackTr
|
|||||||
scope.setContexts("context", context);
|
scope.setContexts("context", context);
|
||||||
});
|
});
|
||||||
|
|
||||||
Sentry.captureException(error, stackTrace: stackTrace).catchError((error) {
|
Sentry.captureException(error, stackTrace: stackTrace)
|
||||||
|
.catchError((error) {
|
||||||
print("Error uploading information to Sentry.io:");
|
print("Error uploading information to Sentry.io:");
|
||||||
print(error);
|
print(error);
|
||||||
return SentryId.empty();
|
return SentryId.empty();
|
||||||
}).then((response) {
|
})
|
||||||
|
.then((response) {
|
||||||
print("Uploaded information to Sentry.io : ${response.toString()}");
|
print("Uploaded information to Sentry.io : ${response.toString()}");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test if a certain error should be ignored by Sentry
|
* Test if a certain error should be ignored by Sentry
|
||||||
*/
|
*/
|
||||||
bool sentryIgnoreError(dynamic error) {
|
bool sentryIgnoreError(dynamic error) {
|
||||||
// Ignore 404 errors for media files
|
// Ignore 404 errors for media files
|
||||||
if (error is HttpException) {
|
if (error is HttpException) {
|
||||||
if (error.uri.toString().contains("/media/") && error.message.contains("404")) {
|
if (error.uri.toString().contains("/media/") &&
|
||||||
|
error.message.contains("404")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,10 @@ import "package:inventree/api.dart";
|
|||||||
import "package:inventree/app_colors.dart";
|
import "package:inventree/app_colors.dart";
|
||||||
import "package:inventree/helpers.dart";
|
import "package:inventree/helpers.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Base class definition for a "status code" definition.
|
* Base class definition for a "status code" definition.
|
||||||
*/
|
*/
|
||||||
class InvenTreeStatusCode {
|
class InvenTreeStatusCode {
|
||||||
|
|
||||||
InvenTreeStatusCode(this.URL);
|
InvenTreeStatusCode(this.URL);
|
||||||
|
|
||||||
final String URL;
|
final String URL;
|
||||||
@ -34,10 +32,7 @@ class InvenTreeStatusCode {
|
|||||||
dynamic _entry = data[key];
|
dynamic _entry = data[key];
|
||||||
|
|
||||||
if (_entry is Map<String, dynamic>) {
|
if (_entry is Map<String, dynamic>) {
|
||||||
_choices.add({
|
_choices.add({"value": _entry["key"], "display_name": _entry["label"]});
|
||||||
"value": _entry["key"],
|
|
||||||
"display_name": _entry["label"]
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +41,6 @@ class InvenTreeStatusCode {
|
|||||||
|
|
||||||
// Load status code information from the server
|
// Load status code information from the server
|
||||||
Future<void> load({bool forceReload = false}) async {
|
Future<void> load({bool forceReload = false}) async {
|
||||||
|
|
||||||
// Return internally cached data
|
// Return internally cached data
|
||||||
if (data.isNotEmpty && !forceReload) {
|
if (data.isNotEmpty && !forceReload) {
|
||||||
return;
|
return;
|
||||||
|
@ -10,16 +10,14 @@ import "package:inventree/inventree/model.dart";
|
|||||||
import "package:inventree/widget/stock/location_display.dart";
|
import "package:inventree/widget/stock/location_display.dart";
|
||||||
import "package:inventree/widget/stock/stock_detail.dart";
|
import "package:inventree/widget/stock/stock_detail.dart";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing a test result for a single stock item
|
* Class representing a test result for a single stock item
|
||||||
*/
|
*/
|
||||||
class InvenTreeStockItemTestResult extends InvenTreeModel {
|
class InvenTreeStockItemTestResult extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeStockItemTestResult() : super();
|
InvenTreeStockItemTestResult() : super();
|
||||||
|
|
||||||
InvenTreeStockItemTestResult.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeStockItemTestResult.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "stock/test/";
|
String get URL => "stock/test/";
|
||||||
@ -29,22 +27,16 @@ class InvenTreeStockItemTestResult extends InvenTreeModel {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, String> defaultFilters() {
|
Map<String, String> defaultFilters() {
|
||||||
return {
|
return {"user_detail": "true", "template_detail": "true"};
|
||||||
"user_detail": "true",
|
|
||||||
"template_detail": "true",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, Map<String, dynamic>> formFields() {
|
Map<String, Map<String, dynamic>> formFields() {
|
||||||
|
|
||||||
Map<String, Map<String, dynamic>> fields = {
|
Map<String, Map<String, dynamic>> fields = {
|
||||||
"stock_item": {"hidden": true},
|
"stock_item": {"hidden": true},
|
||||||
"test": {},
|
"test": {},
|
||||||
"template": {
|
"template": {
|
||||||
"filters": {
|
"filters": {"enabled": "true"},
|
||||||
"enabled": "true",
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"result": {},
|
"result": {},
|
||||||
"value": {},
|
"value": {},
|
||||||
@ -82,30 +74,25 @@ class InvenTreeStockItemTestResult extends InvenTreeModel {
|
|||||||
var result = InvenTreeStockItemTestResult.fromJson(json);
|
var result = InvenTreeStockItemTestResult.fromJson(json);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeStockItemHistory extends InvenTreeModel {
|
class InvenTreeStockItemHistory extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeStockItemHistory() : super();
|
InvenTreeStockItemHistory() : super();
|
||||||
|
|
||||||
InvenTreeStockItemHistory.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeStockItemHistory.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeStockItemHistory.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeStockItemHistory.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "stock/track/";
|
String get URL => "stock/track/";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, String> defaultFilters() {
|
Map<String, String> defaultFilters() {
|
||||||
|
|
||||||
// By default, order by decreasing date
|
// By default, order by decreasing date
|
||||||
return {
|
return {"ordering": "-date", "user_detail": "true"};
|
||||||
"ordering": "-date",
|
|
||||||
"user_detail": "true",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTime? get date => getDate("date");
|
DateTime? get date => getDate("date");
|
||||||
@ -133,7 +120,6 @@ class InvenTreeStockItemHistory extends InvenTreeModel {
|
|||||||
int? get user => getValue("user") as int?;
|
int? get user => getValue("user") as int?;
|
||||||
|
|
||||||
String get userString {
|
String get userString {
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
return getString("username", subKey: "user_detail");
|
return getString("username", subKey: "user_detail");
|
||||||
} else {
|
} else {
|
||||||
@ -142,12 +128,10 @@ class InvenTreeStockItemHistory extends InvenTreeModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing a StockItem database instance
|
* Class representing a StockItem database instance
|
||||||
*/
|
*/
|
||||||
class InvenTreeStockItem extends InvenTreeModel {
|
class InvenTreeStockItem extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeStockItem() : super();
|
InvenTreeStockItem() : super();
|
||||||
|
|
||||||
InvenTreeStockItem.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeStockItem.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
||||||
@ -164,39 +148,18 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
Future<Object?> goToDetailPage(BuildContext context) async {
|
Future<Object?> goToDetailPage(BuildContext context) async {
|
||||||
return Navigator.push(
|
return Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => StockDetailWidget(this)),
|
||||||
builder: (context) => StockDetailWidget(this)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a set of fields to transfer this stock item via dialog
|
// Return a set of fields to transfer this stock item via dialog
|
||||||
Map<String, dynamic> transferFields() {
|
Map<String, dynamic> transferFields() {
|
||||||
Map<String, dynamic> fields = {
|
Map<String, dynamic> fields = {
|
||||||
"pk": {
|
"pk": {"parent": "items", "nested": true, "hidden": true, "value": pk},
|
||||||
"parent": "items",
|
"quantity": {"parent": "items", "nested": true, "value": quantity},
|
||||||
"nested": true,
|
"location": {"value": locationId},
|
||||||
"hidden": true,
|
"status": {"parent": "items", "nested": true, "value": status},
|
||||||
"value": pk,
|
"packaging": {"parent": "items", "nested": true, "value": packaging},
|
||||||
},
|
|
||||||
"quantity": {
|
|
||||||
"parent": "items",
|
|
||||||
"nested": true,
|
|
||||||
"value": quantity,
|
|
||||||
},
|
|
||||||
"location": {
|
|
||||||
"value": locationId,
|
|
||||||
},
|
|
||||||
"status": {
|
|
||||||
"parent": "items",
|
|
||||||
"nested": true,
|
|
||||||
"value": status,
|
|
||||||
},
|
|
||||||
"packaging": {
|
|
||||||
"parent": "items",
|
|
||||||
"nested": true,
|
|
||||||
"value": packaging,
|
|
||||||
},
|
|
||||||
"notes": {},
|
"notes": {},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -233,10 +196,7 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
"location": {},
|
"location": {},
|
||||||
"quantity": {},
|
"quantity": {},
|
||||||
"serial": {},
|
"serial": {},
|
||||||
"serial_numbers": {
|
"serial_numbers": {"label": L10().serialNumbers, "type": "string"},
|
||||||
"label": L10().serialNumbers,
|
|
||||||
"type": "string",
|
|
||||||
},
|
|
||||||
"status": {},
|
"status": {},
|
||||||
"batch": {},
|
"batch": {},
|
||||||
"purchase_price": {},
|
"purchase_price": {},
|
||||||
@ -250,13 +210,12 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, String> defaultFilters() {
|
Map<String, String> defaultFilters() {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"part_detail": "true",
|
"part_detail": "true",
|
||||||
"location_detail": "true",
|
"location_detail": "true",
|
||||||
"supplier_detail": "true",
|
"supplier_detail": "true",
|
||||||
"supplier_part_detail": "true",
|
"supplier_part_detail": "true",
|
||||||
"cascade": "false"
|
"cascade": "false",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,12 +225,9 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
|
|
||||||
// Get all the test templates associated with this StockItem
|
// Get all the test templates associated with this StockItem
|
||||||
Future<void> getTestTemplates({bool showDialog = false}) async {
|
Future<void> getTestTemplates({bool showDialog = false}) async {
|
||||||
await InvenTreePartTestTemplate().list(
|
await InvenTreePartTestTemplate()
|
||||||
filters: {
|
.list(filters: {"part": "${partId}", "enabled": "true"})
|
||||||
"part": "${partId}",
|
.then((var templates) {
|
||||||
"enabled": "true",
|
|
||||||
},
|
|
||||||
).then((var templates) {
|
|
||||||
testTemplates.clear();
|
testTemplates.clear();
|
||||||
|
|
||||||
for (var t in templates) {
|
for (var t in templates) {
|
||||||
@ -287,13 +243,9 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
int get testResultCount => testResults.length;
|
int get testResultCount => testResults.length;
|
||||||
|
|
||||||
Future<void> getTestResults() async {
|
Future<void> getTestResults() async {
|
||||||
|
await InvenTreeStockItemTestResult()
|
||||||
await InvenTreeStockItemTestResult().list(
|
.list(filters: {"stock_item": "${pk}", "user_detail": "true"})
|
||||||
filters: {
|
.then((var results) {
|
||||||
"stock_item": "${pk}",
|
|
||||||
"user_detail": "true",
|
|
||||||
},
|
|
||||||
).then((var results) {
|
|
||||||
testResults.clear();
|
testResults.clear();
|
||||||
|
|
||||||
for (var r in results) {
|
for (var r in results) {
|
||||||
@ -363,7 +315,6 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
String get stocktakeDateString => getDateString("stocktake_date");
|
String get stocktakeDateString => getDateString("stocktake_date");
|
||||||
|
|
||||||
String get partName {
|
String get partName {
|
||||||
|
|
||||||
String nm = "";
|
String nm = "";
|
||||||
|
|
||||||
// Use the detailed part information as priority
|
// Use the detailed part information as priority
|
||||||
@ -412,7 +363,6 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
* Return the Part thumbnail for this stock item.
|
* Return the Part thumbnail for this stock item.
|
||||||
*/
|
*/
|
||||||
String get partThumbnail {
|
String get partThumbnail {
|
||||||
|
|
||||||
String thumb = "";
|
String thumb = "";
|
||||||
|
|
||||||
thumb = (jsondata["part_detail"]?["thumbnail"] ?? "") as String;
|
thumb = (jsondata["part_detail"]?["thumbnail"] ?? "") as String;
|
||||||
@ -439,7 +389,9 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
String thumb = "";
|
String thumb = "";
|
||||||
|
|
||||||
if (jsondata.containsKey("supplier_part_detail")) {
|
if (jsondata.containsKey("supplier_part_detail")) {
|
||||||
thumb = (jsondata["supplier_part_detail"]?["supplier_detail"]?["image"] ?? "") as String;
|
thumb =
|
||||||
|
(jsondata["supplier_part_detail"]?["supplier_detail"]?["image"] ?? "")
|
||||||
|
as String;
|
||||||
} else if (jsondata.containsKey("supplier_detail")) {
|
} else if (jsondata.containsKey("supplier_detail")) {
|
||||||
thumb = (jsondata["supplier_detail"]?["image"] ?? "") as String;
|
thumb = (jsondata["supplier_detail"]?["image"] ?? "") as String;
|
||||||
}
|
}
|
||||||
@ -447,7 +399,8 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
return thumb;
|
return thumb;
|
||||||
}
|
}
|
||||||
|
|
||||||
String get supplierName => getString("supplier_name", subKey: "supplier_detail");
|
String get supplierName =>
|
||||||
|
getString("supplier_name", subKey: "supplier_detail");
|
||||||
|
|
||||||
String get units => getString("units", subKey: "part_detail");
|
String get units => getString("units", subKey: "part_detail");
|
||||||
|
|
||||||
@ -458,7 +411,6 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
double get quantity => getDouble("quantity");
|
double get quantity => getDouble("quantity");
|
||||||
|
|
||||||
String quantityString({bool includeUnits = true}) {
|
String quantityString({bool includeUnits = true}) {
|
||||||
|
|
||||||
String q = "";
|
String q = "";
|
||||||
|
|
||||||
if (allocated > 0) {
|
if (allocated > 0) {
|
||||||
@ -494,8 +446,9 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String get locationName {
|
String get locationName {
|
||||||
|
if (locationId == -1 || !jsondata.containsKey("location_detail")) {
|
||||||
if (locationId == -1 || !jsondata.containsKey("location_detail")) return "Unknown Location";
|
return "Unknown Location";
|
||||||
|
}
|
||||||
|
|
||||||
String loc = getString("name", subKey: "location_detail");
|
String loc = getString("name", subKey: "location_detail");
|
||||||
|
|
||||||
@ -508,8 +461,9 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String get locationPathString {
|
String get locationPathString {
|
||||||
|
if (locationId == -1 || !jsondata.containsKey("location_detail")) {
|
||||||
if (locationId == -1 || !jsondata.containsKey("location_detail")) return L10().locationNotSet;
|
return L10().locationNotSet;
|
||||||
|
}
|
||||||
|
|
||||||
String _loc = getString("pathstring", subKey: "location_detail");
|
String _loc = getString("pathstring", subKey: "location_detail");
|
||||||
if (_loc.isNotEmpty) {
|
if (_loc.isNotEmpty) {
|
||||||
@ -536,7 +490,8 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeStockItem.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeStockItem.fromJson(json);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform stocktake action:
|
* Perform stocktake action:
|
||||||
@ -545,8 +500,12 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
* - Remove
|
* - Remove
|
||||||
* - Count
|
* - Count
|
||||||
*/
|
*/
|
||||||
Future<bool> adjustStock(String endpoint, double q, {String? notes, int? location}) async {
|
Future<bool> adjustStock(
|
||||||
|
String endpoint,
|
||||||
|
double q, {
|
||||||
|
String? notes,
|
||||||
|
int? location,
|
||||||
|
}) async {
|
||||||
// Serialized stock cannot be adjusted (unless it is a "transfer")
|
// Serialized stock cannot be adjusted (unless it is a "transfer")
|
||||||
if (isSerialized() && location == null) {
|
if (isSerialized() && location == null) {
|
||||||
return false;
|
return false;
|
||||||
@ -561,10 +520,7 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
|
|
||||||
data = {
|
data = {
|
||||||
"items": [
|
"items": [
|
||||||
{
|
{"pk": "${pk}", "quantity": "${quantity}"},
|
||||||
"pk": "${pk}",
|
|
||||||
"quantity": "${quantity}",
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
"notes": notes ?? "",
|
"notes": notes ?? "",
|
||||||
};
|
};
|
||||||
@ -573,37 +529,35 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
data["location"] = location;
|
data["location"] = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = await api.post(
|
var response = await api.post(endpoint, body: data);
|
||||||
endpoint,
|
|
||||||
body: data,
|
|
||||||
);
|
|
||||||
|
|
||||||
return response.isValid() && (response.statusCode == 200 || response.statusCode == 201);
|
return response.isValid() &&
|
||||||
|
(response.statusCode == 200 || response.statusCode == 201);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> countStock(double q, {String? notes}) async {
|
Future<bool> countStock(double q, {String? notes}) async {
|
||||||
|
|
||||||
final bool result = await adjustStock("/stock/count/", q, notes: notes);
|
final bool result = await adjustStock("/stock/count/", q, notes: notes);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> addStock(double q, {String? notes}) async {
|
Future<bool> addStock(double q, {String? notes}) async {
|
||||||
|
|
||||||
final bool result = await adjustStock("/stock/add/", q, notes: notes);
|
final bool result = await adjustStock("/stock/add/", q, notes: notes);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> removeStock(double q, {String? notes}) async {
|
Future<bool> removeStock(double q, {String? notes}) async {
|
||||||
|
|
||||||
final bool result = await adjustStock("/stock/remove/", q, notes: notes);
|
final bool result = await adjustStock("/stock/remove/", q, notes: notes);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> transferStock(int location, {double? quantity, String? notes}) async {
|
Future<bool> transferStock(
|
||||||
|
int location, {
|
||||||
|
double? quantity,
|
||||||
|
String? notes,
|
||||||
|
}) async {
|
||||||
double q = this.quantity;
|
double q = this.quantity;
|
||||||
|
|
||||||
if (quantity != null) {
|
if (quantity != null) {
|
||||||
@ -621,15 +575,14 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing an attachment file against a StockItem object
|
* Class representing an attachment file against a StockItem object
|
||||||
*/
|
*/
|
||||||
class InvenTreeStockItemAttachment extends InvenTreeAttachment {
|
class InvenTreeStockItemAttachment extends InvenTreeAttachment {
|
||||||
|
|
||||||
InvenTreeStockItemAttachment() : super();
|
InvenTreeStockItemAttachment() : super();
|
||||||
|
|
||||||
InvenTreeStockItemAttachment.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeStockItemAttachment.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get REFERENCE_FIELD => "stock_item";
|
String get REFERENCE_FIELD => "stock_item";
|
||||||
@ -638,18 +591,20 @@ class InvenTreeStockItemAttachment extends InvenTreeAttachment {
|
|||||||
String get REF_MODEL_TYPE => "stockitem";
|
String get REF_MODEL_TYPE => "stockitem";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => InvenTreeAPI().supportsModernAttachments ? "attachment/" : "stock/attachment/";
|
String get URL => InvenTreeAPI().supportsModernAttachments
|
||||||
|
? "attachment/"
|
||||||
|
: "stock/attachment/";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeStockItemAttachment.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeStockItemAttachment.fromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeStockLocation extends InvenTreeModel {
|
class InvenTreeStockLocation extends InvenTreeModel {
|
||||||
|
|
||||||
InvenTreeStockLocation() : super();
|
InvenTreeStockLocation() : super();
|
||||||
|
|
||||||
InvenTreeStockLocation.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeStockLocation.fromJson(Map<String, dynamic> json)
|
||||||
|
: super.fromJson(json);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get URL => "stock/location/";
|
String get URL => "stock/location/";
|
||||||
@ -665,9 +620,7 @@ class InvenTreeStockLocation extends InvenTreeModel {
|
|||||||
Future<Object?> goToDetailPage(BuildContext context) async {
|
Future<Object?> goToDetailPage(BuildContext context) async {
|
||||||
return Navigator.push(
|
return Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => LocationDisplayWidget(this)),
|
||||||
builder: (context) => LocationDisplayWidget(this)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -684,7 +637,6 @@ class InvenTreeStockLocation extends InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String get parentPathString {
|
String get parentPathString {
|
||||||
|
|
||||||
List<String> psplit = pathstring.split("/");
|
List<String> psplit = pathstring.split("/");
|
||||||
|
|
||||||
if (psplit.isNotEmpty) {
|
if (psplit.isNotEmpty) {
|
||||||
@ -703,6 +655,6 @@ class InvenTreeStockLocation extends InvenTreeModel {
|
|||||||
int get itemcount => (jsondata["items"] ?? 0) as int;
|
int get itemcount => (jsondata["items"] ?? 0) as int;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) => InvenTreeStockLocation.fromJson(json);
|
InvenTreeModel createFromJson(Map<String, dynamic> json) =>
|
||||||
|
InvenTreeStockLocation.fromJson(json);
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,7 @@ import "package:flutter/material.dart";
|
|||||||
import "package:inventree/helpers.dart";
|
import "package:inventree/helpers.dart";
|
||||||
|
|
||||||
// Shortcut function to reduce boilerplate!
|
// Shortcut function to reduce boilerplate!
|
||||||
I18N L10()
|
I18N L10() {
|
||||||
{
|
|
||||||
// Testing mode - ignore context
|
// Testing mode - ignore context
|
||||||
if (!hasContext()) {
|
if (!hasContext()) {
|
||||||
return I18NEn();
|
return I18NEn();
|
||||||
|
@ -90,6 +90,7 @@ def generate_locale_list(locales):
|
|||||||
output.write(
|
output.write(
|
||||||
"// This file is auto-generated by the 'collect_translations.py' script - do not edit it directly!\n\n"
|
"// This file is auto-generated by the 'collect_translations.py' script - do not edit it directly!\n\n"
|
||||||
)
|
)
|
||||||
|
output.write("// dart format off\n\n")
|
||||||
output.write('import "package:flutter/material.dart";\n\n')
|
output.write('import "package:flutter/material.dart";\n\n')
|
||||||
output.write("const List<Locale> supported_locales = [\n")
|
output.write("const List<Locale> supported_locales = [\n")
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ Future<void> selectAndPrintLabel(
|
|||||||
String labelType,
|
String labelType,
|
||||||
String labelQuery,
|
String labelQuery,
|
||||||
) async {
|
) async {
|
||||||
|
|
||||||
if (!InvenTreeAPI().isConnected()) {
|
if (!InvenTreeAPI().isConnected()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -44,10 +43,7 @@ Future<void> selectAndPrintLabel(
|
|||||||
int pk = (label["pk"] ?? -1) as int;
|
int pk = (label["pk"] ?? -1) as int;
|
||||||
|
|
||||||
if (name.isNotEmpty && pk > 0) {
|
if (name.isNotEmpty && pk > 0) {
|
||||||
label_options.add({
|
label_options.add({"display_name": name, "value": pk});
|
||||||
"display_name": name,
|
|
||||||
"value": pk,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,13 +53,12 @@ Future<void> selectAndPrintLabel(
|
|||||||
|
|
||||||
// Construct list of available plugins
|
// Construct list of available plugins
|
||||||
for (var plugin in plugins) {
|
for (var plugin in plugins) {
|
||||||
plugin_options.add({
|
plugin_options.add({"display_name": plugin.humanName, "value": plugin.key});
|
||||||
"display_name": plugin.humanName,
|
|
||||||
"value": plugin.key,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String selectedPlugin = await InvenTreeAPI().getUserSetting("LABEL_DEFAULT_PRINTER");
|
String selectedPlugin = await InvenTreeAPI().getUserSetting(
|
||||||
|
"LABEL_DEFAULT_PRINTER",
|
||||||
|
);
|
||||||
|
|
||||||
if (selectedPlugin.isNotEmpty) {
|
if (selectedPlugin.isNotEmpty) {
|
||||||
initial_plugin = selectedPlugin;
|
initial_plugin = selectedPlugin;
|
||||||
@ -85,7 +80,7 @@ Future<void> selectAndPrintLabel(
|
|||||||
"value": initial_plugin,
|
"value": initial_plugin,
|
||||||
"choices": plugin_options,
|
"choices": plugin_options,
|
||||||
"required": true,
|
"required": true,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
launchApiForm(
|
launchApiForm(
|
||||||
@ -99,18 +94,12 @@ Future<void> selectAndPrintLabel(
|
|||||||
final plugin = data["plugin"];
|
final plugin = data["plugin"];
|
||||||
|
|
||||||
if (template == null) {
|
if (template == null) {
|
||||||
showSnackIcon(
|
showSnackIcon(L10().labelSelectTemplate, success: false);
|
||||||
L10().labelSelectTemplate,
|
|
||||||
success: false,
|
|
||||||
);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
showSnackIcon(
|
showSnackIcon(L10().labelSelectPrinter, success: false);
|
||||||
L10().labelSelectPrinter,
|
|
||||||
success: false,
|
|
||||||
);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,22 +112,22 @@ Future<void> selectAndPrintLabel(
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (labelId != -1 && pluginKey != null) {
|
if (labelId != -1 && pluginKey != null) {
|
||||||
|
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
|
|
||||||
if (InvenTreeAPI().supportsModernLabelPrinting) {
|
if (InvenTreeAPI().supportsModernLabelPrinting) {
|
||||||
|
|
||||||
// Modern label printing API uses a POST request to a single API endpoint.
|
// Modern label printing API uses a POST request to a single API endpoint.
|
||||||
await InvenTreeAPI().post(
|
await InvenTreeAPI()
|
||||||
|
.post(
|
||||||
"/label/print/",
|
"/label/print/",
|
||||||
body: {
|
body: {
|
||||||
"plugin": pluginKey,
|
"plugin": pluginKey,
|
||||||
"template": labelId,
|
"template": labelId,
|
||||||
"items": [instanceId]
|
"items": [instanceId],
|
||||||
}
|
},
|
||||||
).then((APIResponse response) {
|
)
|
||||||
|
.then((APIResponse response) {
|
||||||
if (response.isValid() && response.statusCode >= 200 &&
|
if (response.isValid() &&
|
||||||
|
response.statusCode >= 200 &&
|
||||||
response.statusCode <= 201) {
|
response.statusCode <= 201) {
|
||||||
var data = response.asMap();
|
var data = response.asMap();
|
||||||
|
|
||||||
@ -154,11 +143,11 @@ Future<void> selectAndPrintLabel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Legacy label printing API
|
// Legacy label printing API
|
||||||
// Uses a GET request to a specially formed URL which depends on the parameters
|
// Uses a GET request to a specially formed URL which depends on the parameters
|
||||||
String url = "/label/${labelType}/${labelId}/print/?${labelQuery}&plugin=${pluginKey}";
|
String url =
|
||||||
|
"/label/${labelType}/${labelId}/print/?${labelQuery}&plugin=${pluginKey}";
|
||||||
await InvenTreeAPI().get(url).then((APIResponse response) {
|
await InvenTreeAPI().get(url).then((APIResponse response) {
|
||||||
if (response.isValid() && response.statusCode == 200) {
|
if (response.isValid() && response.statusCode == 200) {
|
||||||
var data = response.asMap();
|
var data = response.asMap();
|
||||||
@ -176,20 +165,14 @@ Future<void> selectAndPrintLabel(
|
|||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
showSnackIcon(
|
showSnackIcon(L10().printLabelSuccess, success: true);
|
||||||
L10().printLabelSuccess,
|
|
||||||
success: true
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
showSnackIcon(
|
showSnackIcon(L10().printLabelFailure, success: false);
|
||||||
L10().printLabelFailure,
|
}
|
||||||
success: false,
|
}
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Discover which label templates are available for a given item
|
* Discover which label templates are available for a given item
|
||||||
@ -198,8 +181,8 @@ Future<List<Map<String, dynamic>>> getLabelTemplates(
|
|||||||
String labelType,
|
String labelType,
|
||||||
Map<String, String> data,
|
Map<String, String> data,
|
||||||
) async {
|
) async {
|
||||||
|
if (!InvenTreeAPI().isConnected() ||
|
||||||
if (!InvenTreeAPI().isConnected() || !InvenTreeAPI().supportsMixin("labels")) {
|
!InvenTreeAPI().supportsMixin("labels")) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,10 +200,7 @@ Future<List<Map<String, dynamic>>> getLabelTemplates(
|
|||||||
|
|
||||||
List<Map<String, dynamic>> labels = [];
|
List<Map<String, dynamic>> labels = [];
|
||||||
|
|
||||||
await InvenTreeAPI().get(
|
await InvenTreeAPI().get(url, params: data).then((APIResponse response) {
|
||||||
url,
|
|
||||||
params: data,
|
|
||||||
).then((APIResponse response) {
|
|
||||||
if (response.isValid() && response.statusCode == 200) {
|
if (response.isValid() && response.statusCode == 200) {
|
||||||
for (var label in response.resultsList()) {
|
for (var label in response.resultsList()) {
|
||||||
if (label is Map<String, dynamic>) {
|
if (label is Map<String, dynamic>) {
|
||||||
|
@ -18,15 +18,13 @@ import "package:inventree/l10n/collected/app_localizations.dart";
|
|||||||
import "package:inventree/settings/release.dart";
|
import "package:inventree/settings/release.dart";
|
||||||
import "package:inventree/widget/home.dart";
|
import "package:inventree/widget/home.dart";
|
||||||
|
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
final savedThemeMode = await AdaptiveTheme.getThemeMode();
|
final savedThemeMode = await AdaptiveTheme.getThemeMode();
|
||||||
|
|
||||||
await runZonedGuarded<Future<void>>(() async {
|
await runZonedGuarded<Future<void>>(
|
||||||
|
() async {
|
||||||
PackageInfo info = await PackageInfo.fromPlatform();
|
PackageInfo info = await PackageInfo.fromPlatform();
|
||||||
String pkg = info.packageName;
|
String pkg = info.packageName;
|
||||||
String version = info.version;
|
String version = info.version;
|
||||||
@ -46,20 +44,25 @@ Future<void> main() async {
|
|||||||
|
|
||||||
// Pass any flutter errors off to the Sentry reporting context!
|
// Pass any flutter errors off to the Sentry reporting context!
|
||||||
FlutterError.onError = (FlutterErrorDetails details) async {
|
FlutterError.onError = (FlutterErrorDetails details) async {
|
||||||
|
|
||||||
// Ensure that the error gets reported to sentry!
|
// Ensure that the error gets reported to sentry!
|
||||||
await sentryReportError(
|
await sentryReportError(
|
||||||
"FlutterError.onError",
|
"FlutterError.onError",
|
||||||
details.exception, details.stack,
|
details.exception,
|
||||||
|
details.stack,
|
||||||
context: {
|
context: {
|
||||||
"context": details.context.toString(),
|
"context": details.context.toString(),
|
||||||
"summary": details.summary.toString(),
|
"summary": details.summary.toString(),
|
||||||
"library": details.library ?? "null",
|
"library": details.library ?? "null",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
final int orientation = await InvenTreeSettingsManager().getValue(INV_SCREEN_ORIENTATION, SCREEN_ORIENTATION_SYSTEM) as int;
|
final int orientation =
|
||||||
|
await InvenTreeSettingsManager().getValue(
|
||||||
|
INV_SCREEN_ORIENTATION,
|
||||||
|
SCREEN_ORIENTATION_SYSTEM,
|
||||||
|
)
|
||||||
|
as int;
|
||||||
|
|
||||||
List<DeviceOrientation> orientations = [];
|
List<DeviceOrientation> orientations = [];
|
||||||
|
|
||||||
@ -75,15 +78,13 @@ Future<void> main() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SystemChrome.setPreferredOrientations(orientations).then((_) {
|
SystemChrome.setPreferredOrientations(orientations).then((_) {
|
||||||
runApp(
|
runApp(InvenTreeApp(savedThemeMode));
|
||||||
InvenTreeApp(savedThemeMode)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
},
|
||||||
}, (Object error, StackTrace stackTrace) async {
|
(Object error, StackTrace stackTrace) async {
|
||||||
sentryReportError("main.runZonedGuarded", error, stackTrace);
|
sentryReportError("main.runZonedGuarded", error, stackTrace);
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class InvenTreeApp extends StatefulWidget {
|
class InvenTreeApp extends StatefulWidget {
|
||||||
@ -96,13 +97,11 @@ class InvenTreeApp extends StatefulWidget {
|
|||||||
@override
|
@override
|
||||||
InvenTreeAppState createState() => InvenTreeAppState(savedThemeMode);
|
InvenTreeAppState createState() => InvenTreeAppState(savedThemeMode);
|
||||||
|
|
||||||
static InvenTreeAppState? of(BuildContext context) => context.findAncestorStateOfType<InvenTreeAppState>();
|
static InvenTreeAppState? of(BuildContext context) =>
|
||||||
|
context.findAncestorStateOfType<InvenTreeAppState>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeAppState extends State<StatefulWidget> {
|
class InvenTreeAppState extends State<StatefulWidget> {
|
||||||
|
|
||||||
InvenTreeAppState(this.savedThemeMode) : super();
|
InvenTreeAppState(this.savedThemeMode) : super();
|
||||||
|
|
||||||
// Custom _locale (default = null; use system default)
|
// Custom _locale (default = null; use system default)
|
||||||
@ -120,13 +119,14 @@ class InvenTreeAppState extends State<StatefulWidget> {
|
|||||||
|
|
||||||
// Run app init routines in the background
|
// Run app init routines in the background
|
||||||
Future<void> runInitTasks() async {
|
Future<void> runInitTasks() async {
|
||||||
|
|
||||||
// Set the app locale (language)
|
// Set the app locale (language)
|
||||||
Locale? locale = await InvenTreeSettingsManager().getSelectedLocale();
|
Locale? locale = await InvenTreeSettingsManager().getSelectedLocale();
|
||||||
setLocale(locale);
|
setLocale(locale);
|
||||||
|
|
||||||
// Display release notes if this is a new version
|
// Display release notes if this is a new version
|
||||||
final String version = await InvenTreeSettingsManager().getValue("recentVersion", "") as String;
|
final String version =
|
||||||
|
await InvenTreeSettingsManager().getValue("recentVersion", "")
|
||||||
|
as String;
|
||||||
|
|
||||||
final PackageInfo info = await PackageInfo.fromPlatform();
|
final PackageInfo info = await PackageInfo.fromPlatform();
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ class InvenTreeAppState extends State<StatefulWidget> {
|
|||||||
|
|
||||||
// Show the release notes
|
// Show the release notes
|
||||||
OneContext().push(
|
OneContext().push(
|
||||||
MaterialPageRoute(builder: (context) => ReleaseNotesWidget(notes))
|
MaterialPageRoute(builder: (context) => ReleaseNotesWidget(notes)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,7 +155,6 @@ class InvenTreeAppState extends State<StatefulWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
return AdaptiveTheme(
|
return AdaptiveTheme(
|
||||||
light: ThemeData(
|
light: ThemeData(
|
||||||
brightness: Brightness.light,
|
brightness: Brightness.light,
|
||||||
@ -185,7 +184,7 @@ class InvenTreeAppState extends State<StatefulWidget> {
|
|||||||
],
|
],
|
||||||
supportedLocales: supported_locales,
|
supportedLocales: supported_locales,
|
||||||
locale: _locale,
|
locale: _locale,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import "package:path_provider/path_provider.dart";
|
|||||||
import "package:sembast/sembast_io.dart";
|
import "package:sembast/sembast_io.dart";
|
||||||
import "package:path/path.dart";
|
import "package:path/path.dart";
|
||||||
|
|
||||||
|
|
||||||
// Settings key values
|
// Settings key values
|
||||||
const String INV_HOME_SHOW_SUBSCRIBED = "homeShowSubscribed";
|
const String INV_HOME_SHOW_SUBSCRIBED = "homeShowSubscribed";
|
||||||
const String INV_HOME_SHOW_PO = "homeShowPo";
|
const String INV_HOME_SHOW_PO = "homeShowPo";
|
||||||
@ -62,7 +61,6 @@ const int BARCODE_CONTROLLER_WEDGE = 1;
|
|||||||
* Class for storing InvenTree preferences in a NoSql DB
|
* Class for storing InvenTree preferences in a NoSql DB
|
||||||
*/
|
*/
|
||||||
class InvenTreePreferencesDB {
|
class InvenTreePreferencesDB {
|
||||||
|
|
||||||
InvenTreePreferencesDB._();
|
InvenTreePreferencesDB._();
|
||||||
|
|
||||||
static final InvenTreePreferencesDB _singleton = InvenTreePreferencesDB._();
|
static final InvenTreePreferencesDB _singleton = InvenTreePreferencesDB._();
|
||||||
@ -74,7 +72,6 @@ class InvenTreePreferencesDB {
|
|||||||
bool isOpen = false;
|
bool isOpen = false;
|
||||||
|
|
||||||
Future<Database> get database async {
|
Future<Database> get database async {
|
||||||
|
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
// Calling _openDatabase will also complete the completer with database instance
|
// Calling _openDatabase will also complete the completer with database instance
|
||||||
_openDatabase();
|
_openDatabase();
|
||||||
@ -101,13 +98,11 @@ class InvenTreePreferencesDB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* InvenTree setings manager class.
|
* InvenTree setings manager class.
|
||||||
* Provides functions for loading and saving settings, with provision for default values
|
* Provides functions for loading and saving settings, with provision for default values
|
||||||
*/
|
*/
|
||||||
class InvenTreeSettingsManager {
|
class InvenTreeSettingsManager {
|
||||||
|
|
||||||
factory InvenTreeSettingsManager() {
|
factory InvenTreeSettingsManager() {
|
||||||
return _manager;
|
return _manager;
|
||||||
}
|
}
|
||||||
@ -144,7 +139,6 @@ class InvenTreeSettingsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<dynamic> getValue(String key, dynamic backup) async {
|
Future<dynamic> getValue(String key, dynamic backup) async {
|
||||||
|
|
||||||
dynamic value = await store.record(key).get(await _db);
|
dynamic value = await store.record(key).get(await _db);
|
||||||
|
|
||||||
// Retrieve value
|
// Retrieve value
|
||||||
@ -174,7 +168,6 @@ class InvenTreeSettingsManager {
|
|||||||
|
|
||||||
// Store a key:value pair in the database
|
// Store a key:value pair in the database
|
||||||
Future<void> setValue(String key, dynamic value) async {
|
Future<void> setValue(String key, dynamic value) async {
|
||||||
|
|
||||||
// Encode null values as strings
|
// Encode null values as strings
|
||||||
value ??= "__null__";
|
value ??= "__null__";
|
||||||
|
|
||||||
@ -182,5 +175,6 @@ class InvenTreeSettingsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we only ever create a single instance of this class
|
// Ensure we only ever create a single instance of this class
|
||||||
static final InvenTreeSettingsManager _manager = InvenTreeSettingsManager._internal();
|
static final InvenTreeSettingsManager _manager =
|
||||||
|
InvenTreeSettingsManager._internal();
|
||||||
}
|
}
|
||||||
|
@ -13,34 +13,30 @@ import "package:url_launcher/url_launcher.dart";
|
|||||||
const String DOCS_URL = "https://docs.inventree.org/app";
|
const String DOCS_URL = "https://docs.inventree.org/app";
|
||||||
|
|
||||||
class InvenTreeAboutWidget extends StatelessWidget {
|
class InvenTreeAboutWidget extends StatelessWidget {
|
||||||
|
|
||||||
const InvenTreeAboutWidget(this.info) : super();
|
const InvenTreeAboutWidget(this.info) : super();
|
||||||
|
|
||||||
final PackageInfo info;
|
final PackageInfo info;
|
||||||
|
|
||||||
Future<void> _releaseNotes(BuildContext context) async {
|
Future<void> _releaseNotes(BuildContext context) async {
|
||||||
|
|
||||||
// Load release notes from external file
|
// Load release notes from external file
|
||||||
String notes = await rootBundle.loadString("assets/release_notes.md");
|
String notes = await rootBundle.loadString("assets/release_notes.md");
|
||||||
|
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => ReleaseNotesWidget(notes))
|
MaterialPageRoute(builder: (context) => ReleaseNotesWidget(notes)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _credits(BuildContext context) async {
|
Future<void> _credits(BuildContext context) async {
|
||||||
|
|
||||||
String notes = await rootBundle.loadString("assets/credits.md");
|
String notes = await rootBundle.loadString("assets/credits.md");
|
||||||
|
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => CreditsWidget(notes))
|
MaterialPageRoute(builder: (context) => CreditsWidget(notes)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _openDocs() async {
|
Future<void> _openDocs() async {
|
||||||
|
|
||||||
var docsUrl = Uri.parse(DOCS_URL);
|
var docsUrl = Uri.parse(DOCS_URL);
|
||||||
|
|
||||||
if (await canLaunchUrl(docsUrl)) {
|
if (await canLaunchUrl(docsUrl)) {
|
||||||
@ -49,11 +45,11 @@ class InvenTreeAboutWidget extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _reportBug(BuildContext context) async {
|
Future<void> _reportBug(BuildContext context) async {
|
||||||
|
|
||||||
var url = Uri(
|
var url = Uri(
|
||||||
scheme: "https",
|
scheme: "https",
|
||||||
host: "github.com",
|
host: "github.com",
|
||||||
path: "inventree/inventree-app/issues/new?title=Enter+bug+description");
|
path: "inventree/inventree-app/issues/new?title=Enter+bug+description",
|
||||||
|
);
|
||||||
|
|
||||||
if (await canLaunchUrl(url)) {
|
if (await canLaunchUrl(url)) {
|
||||||
await launchUrl(url);
|
await launchUrl(url);
|
||||||
@ -64,7 +60,8 @@ class InvenTreeAboutWidget extends StatelessWidget {
|
|||||||
var url = Uri(
|
var url = Uri(
|
||||||
scheme: "https",
|
scheme: "https",
|
||||||
host: "crowdin.com",
|
host: "crowdin.com",
|
||||||
path: "/project/inventree");
|
path: "/project/inventree",
|
||||||
|
);
|
||||||
|
|
||||||
if (await canLaunchUrl(url)) {
|
if (await canLaunchUrl(url)) {
|
||||||
await launchUrl(url);
|
await launchUrl(url);
|
||||||
@ -73,7 +70,6 @@ class InvenTreeAboutWidget extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
List<Widget> tiles = [];
|
List<Widget> tiles = [];
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -82,41 +78,57 @@ class InvenTreeAboutWidget extends StatelessWidget {
|
|||||||
L10().serverDetails,
|
L10().serverDetails,
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (InvenTreeAPI().isConnected()) {
|
if (InvenTreeAPI().isConnected()) {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().address),
|
title: Text(L10().address),
|
||||||
subtitle: Text(InvenTreeAPI().baseUrl.isNotEmpty ? InvenTreeAPI().baseUrl : L10().notConnected),
|
subtitle: Text(
|
||||||
|
InvenTreeAPI().baseUrl.isNotEmpty
|
||||||
|
? InvenTreeAPI().baseUrl
|
||||||
|
: L10().notConnected,
|
||||||
|
),
|
||||||
leading: Icon(TablerIcons.globe),
|
leading: Icon(TablerIcons.globe),
|
||||||
trailing: InvenTreeAPI().isConnected() ? Icon(TablerIcons.circle_check, color: COLOR_SUCCESS) : Icon(TablerIcons.circle_x, color: COLOR_DANGER),
|
trailing: InvenTreeAPI().isConnected()
|
||||||
)
|
? Icon(TablerIcons.circle_check, color: COLOR_SUCCESS)
|
||||||
|
: Icon(TablerIcons.circle_x, color: COLOR_DANGER),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().username),
|
title: Text(L10().username),
|
||||||
subtitle: Text(InvenTreeAPI().username),
|
subtitle: Text(InvenTreeAPI().username),
|
||||||
leading: InvenTreeAPI().username.isNotEmpty ? Icon(TablerIcons.user) : Icon(TablerIcons.user_cancel, color: COLOR_DANGER),
|
leading: InvenTreeAPI().username.isNotEmpty
|
||||||
)
|
? Icon(TablerIcons.user)
|
||||||
|
: Icon(TablerIcons.user_cancel, color: COLOR_DANGER),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().version),
|
title: Text(L10().version),
|
||||||
subtitle: Text(InvenTreeAPI().serverVersion.isNotEmpty ? InvenTreeAPI().serverVersion : L10().notConnected),
|
subtitle: Text(
|
||||||
|
InvenTreeAPI().serverVersion.isNotEmpty
|
||||||
|
? InvenTreeAPI().serverVersion
|
||||||
|
: L10().notConnected,
|
||||||
|
),
|
||||||
leading: Icon(TablerIcons.info_circle),
|
leading: Icon(TablerIcons.info_circle),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().serverInstance),
|
title: Text(L10().serverInstance),
|
||||||
subtitle: Text(InvenTreeAPI().serverInstance.isNotEmpty ? InvenTreeAPI().serverInstance : L10().notConnected),
|
subtitle: Text(
|
||||||
|
InvenTreeAPI().serverInstance.isNotEmpty
|
||||||
|
? InvenTreeAPI().serverInstance
|
||||||
|
: L10().notConnected,
|
||||||
|
),
|
||||||
leading: Icon(TablerIcons.server),
|
leading: Icon(TablerIcons.server),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Display extra tile if the server supports plugins
|
// Display extra tile if the server supports plugins
|
||||||
@ -125,9 +137,8 @@ class InvenTreeAboutWidget extends StatelessWidget {
|
|||||||
title: Text(L10().pluginSupport),
|
title: Text(L10().pluginSupport),
|
||||||
subtitle: Text(L10().pluginSupportDetail),
|
subtitle: Text(L10().pluginSupportDetail),
|
||||||
leading: Icon(TablerIcons.plug),
|
leading: Icon(TablerIcons.plug),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
@ -136,8 +147,8 @@ class InvenTreeAboutWidget extends StatelessWidget {
|
|||||||
L10().serverNotConnected,
|
L10().serverNotConnected,
|
||||||
style: TextStyle(fontStyle: FontStyle.italic),
|
style: TextStyle(fontStyle: FontStyle.italic),
|
||||||
),
|
),
|
||||||
leading: Icon(TablerIcons.exclamation_circle)
|
leading: Icon(TablerIcons.exclamation_circle),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,23 +158,23 @@ class InvenTreeAboutWidget extends StatelessWidget {
|
|||||||
L10().appDetails,
|
L10().appDetails,
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().packageName),
|
title: Text(L10().packageName),
|
||||||
subtitle: Text("${info.packageName}"),
|
subtitle: Text("${info.packageName}"),
|
||||||
leading: Icon(TablerIcons.box)
|
leading: Icon(TablerIcons.box),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().version),
|
title: Text(L10().version),
|
||||||
subtitle: Text("${info.version} - Build ${info.buildNumber}"),
|
subtitle: Text("${info.version} - Build ${info.buildNumber}"),
|
||||||
leading: Icon(TablerIcons.info_circle)
|
leading: Icon(TablerIcons.info_circle),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -174,7 +185,7 @@ class InvenTreeAboutWidget extends StatelessWidget {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
_releaseNotes(context);
|
_releaseNotes(context);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -184,8 +195,8 @@ class InvenTreeAboutWidget extends StatelessWidget {
|
|||||||
leading: Icon(TablerIcons.balloon, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.balloon, color: COLOR_ACTION),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_credits(context);
|
_credits(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -196,7 +207,7 @@ class InvenTreeAboutWidget extends StatelessWidget {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
_openDocs();
|
_openDocs();
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -206,8 +217,8 @@ class InvenTreeAboutWidget extends StatelessWidget {
|
|||||||
leading: Icon(TablerIcons.language, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.language, color: COLOR_ACTION),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_translate();
|
_translate();
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -218,7 +229,7 @@ class InvenTreeAboutWidget extends StatelessWidget {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
_reportBug(context);
|
_reportBug(context);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -227,11 +238,8 @@ class InvenTreeAboutWidget extends StatelessWidget {
|
|||||||
backgroundColor: COLOR_APP_BAR,
|
backgroundColor: COLOR_APP_BAR,
|
||||||
),
|
),
|
||||||
body: ListView(
|
body: ListView(
|
||||||
children: ListTile.divideTiles(
|
children: ListTile.divideTiles(context: context, tiles: tiles).toList(),
|
||||||
context: context,
|
),
|
||||||
tiles: tiles,
|
|
||||||
).toList(),
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,17 +16,16 @@ import "package:inventree/preferences.dart";
|
|||||||
import "package:inventree/widget/dialogs.dart";
|
import "package:inventree/widget/dialogs.dart";
|
||||||
import "package:inventree/widget/progress.dart";
|
import "package:inventree/widget/progress.dart";
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeAppSettingsWidget extends StatefulWidget {
|
class InvenTreeAppSettingsWidget extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_InvenTreeAppSettingsState createState() => _InvenTreeAppSettingsState();
|
_InvenTreeAppSettingsState createState() => _InvenTreeAppSettingsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
||||||
|
|
||||||
_InvenTreeAppSettingsState();
|
_InvenTreeAppSettingsState();
|
||||||
|
|
||||||
final GlobalKey<_InvenTreeAppSettingsState> _settingsKey = GlobalKey<_InvenTreeAppSettingsState>();
|
final GlobalKey<_InvenTreeAppSettingsState> _settingsKey =
|
||||||
|
GlobalKey<_InvenTreeAppSettingsState>();
|
||||||
|
|
||||||
// Sound settings
|
// Sound settings
|
||||||
bool barcodeSounds = true;
|
bool barcodeSounds = true;
|
||||||
@ -49,15 +48,32 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> loadSettings(BuildContext context) async {
|
Future<void> loadSettings(BuildContext context) async {
|
||||||
|
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
|
|
||||||
barcodeSounds = await InvenTreeSettingsManager().getValue(INV_SOUNDS_BARCODE, true) as bool;
|
barcodeSounds =
|
||||||
serverSounds = await InvenTreeSettingsManager().getValue(INV_SOUNDS_SERVER, true) as bool;
|
await InvenTreeSettingsManager().getValue(INV_SOUNDS_BARCODE, true)
|
||||||
reportErrors = await InvenTreeSettingsManager().getValue(INV_REPORT_ERRORS, true) as bool;
|
as bool;
|
||||||
strictHttps = await InvenTreeSettingsManager().getValue(INV_STRICT_HTTPS, false) as bool;
|
serverSounds =
|
||||||
screenOrientation = await InvenTreeSettingsManager().getValue(INV_SCREEN_ORIENTATION, SCREEN_ORIENTATION_SYSTEM) as int;
|
await InvenTreeSettingsManager().getValue(INV_SOUNDS_SERVER, true)
|
||||||
enableLabelPrinting = await InvenTreeSettingsManager().getValue(INV_ENABLE_LABEL_PRINTING, true) as bool;
|
as bool;
|
||||||
|
reportErrors =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_REPORT_ERRORS, true)
|
||||||
|
as bool;
|
||||||
|
strictHttps =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_STRICT_HTTPS, false)
|
||||||
|
as bool;
|
||||||
|
screenOrientation =
|
||||||
|
await InvenTreeSettingsManager().getValue(
|
||||||
|
INV_SCREEN_ORIENTATION,
|
||||||
|
SCREEN_ORIENTATION_SYSTEM,
|
||||||
|
)
|
||||||
|
as int;
|
||||||
|
enableLabelPrinting =
|
||||||
|
await InvenTreeSettingsManager().getValue(
|
||||||
|
INV_ENABLE_LABEL_PRINTING,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
as bool;
|
||||||
|
|
||||||
darkMode = AdaptiveTheme.of(context).mode.isDark;
|
darkMode = AdaptiveTheme.of(context).mode.isDark;
|
||||||
|
|
||||||
@ -71,19 +87,15 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _selectLocale(BuildContext context) async {
|
Future<void> _selectLocale(BuildContext context) async {
|
||||||
|
|
||||||
List<Map<String, dynamic>> options = [
|
List<Map<String, dynamic>> options = [
|
||||||
{
|
{"display_name": L10().languageDefault, "value": null},
|
||||||
"display_name": L10().languageDefault,
|
|
||||||
"value": null,
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// Construct a list of available locales
|
// Construct a list of available locales
|
||||||
for (var locale in supported_locales) {
|
for (var locale in supported_locales) {
|
||||||
options.add({
|
options.add({
|
||||||
"display_name": LocaleNames.of(context)!.nameOf(locale.toString()),
|
"display_name": LocaleNames.of(context)!.nameOf(locale.toString()),
|
||||||
"value": locale.toString()
|
"value": locale.toString(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +105,7 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
|||||||
"type": "choice",
|
"type": "choice",
|
||||||
"choices": options,
|
"choices": options,
|
||||||
"value": locale?.toString(),
|
"value": locale?.toString(),
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
launchApiForm(
|
launchApiForm(
|
||||||
@ -103,7 +115,6 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
|||||||
fields,
|
fields,
|
||||||
icon: TablerIcons.circle_check,
|
icon: TablerIcons.circle_check,
|
||||||
onSuccess: (Map<String, dynamic> data) async {
|
onSuccess: (Map<String, dynamic> data) async {
|
||||||
|
|
||||||
String locale_name = (data["locale"] ?? "") as String;
|
String locale_name = (data["locale"] ?? "") as String;
|
||||||
Locale? selected_locale;
|
Locale? selected_locale;
|
||||||
|
|
||||||
@ -124,18 +135,18 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
|||||||
|
|
||||||
// Clear the cached status label information
|
// Clear the cached status label information
|
||||||
InvenTreeAPI().clearStatusCodeData();
|
InvenTreeAPI().clearStatusCodeData();
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
String languageName = L10().languageDefault;
|
String languageName = L10().languageDefault;
|
||||||
|
|
||||||
if (locale != null) {
|
if (locale != null) {
|
||||||
languageName = LocaleNames.of(context)!.nameOf(locale.toString()) ?? L10().languageDefault;
|
languageName =
|
||||||
|
LocaleNames.of(context)!.nameOf(locale.toString()) ??
|
||||||
|
L10().languageDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
IconData orientationIcon = Icons.screen_rotation;
|
IconData orientationIcon = Icons.screen_rotation;
|
||||||
@ -154,7 +165,7 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
|||||||
key: _settingsKey,
|
key: _settingsKey,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(L10().appSettings),
|
title: Text(L10().appSettings),
|
||||||
backgroundColor: COLOR_APP_BAR
|
backgroundColor: COLOR_APP_BAR,
|
||||||
),
|
),
|
||||||
body: Container(
|
body: Container(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
@ -183,8 +194,8 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
darkMode = value;
|
darkMode = value;
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
@ -198,26 +209,43 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
|||||||
L10().orientation,
|
L10().orientation,
|
||||||
[
|
[
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: Icon(Icons.screen_rotation, color: screenOrientation == SCREEN_ORIENTATION_SYSTEM ? COLOR_ACTION : null),
|
leading: Icon(
|
||||||
|
Icons.screen_rotation,
|
||||||
|
color: screenOrientation == SCREEN_ORIENTATION_SYSTEM
|
||||||
|
? COLOR_ACTION
|
||||||
|
: null,
|
||||||
|
),
|
||||||
title: Text(L10().orientationSystem),
|
title: Text(L10().orientationSystem),
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: Icon(Icons.screen_lock_portrait, color: screenOrientation == SCREEN_ORIENTATION_PORTRAIT ? COLOR_ACTION : null),
|
leading: Icon(
|
||||||
|
Icons.screen_lock_portrait,
|
||||||
|
color: screenOrientation == SCREEN_ORIENTATION_PORTRAIT
|
||||||
|
? COLOR_ACTION
|
||||||
|
: null,
|
||||||
|
),
|
||||||
title: Text(L10().orientationPortrait),
|
title: Text(L10().orientationPortrait),
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: Icon(Icons.screen_lock_landscape, color: screenOrientation == SCREEN_ORIENTATION_LANDSCAPE ? COLOR_ACTION : null),
|
leading: Icon(
|
||||||
|
Icons.screen_lock_landscape,
|
||||||
|
color: screenOrientation == SCREEN_ORIENTATION_LANDSCAPE
|
||||||
|
? COLOR_ACTION
|
||||||
|
: null,
|
||||||
|
),
|
||||||
title: Text(L10().orientationLandscape),
|
title: Text(L10().orientationLandscape),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
onSelected: (idx) async {
|
onSelected: (idx) async {
|
||||||
screenOrientation = idx as int;
|
screenOrientation = idx as int;
|
||||||
|
|
||||||
InvenTreeSettingsManager().setValue(INV_SCREEN_ORIENTATION, screenOrientation);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_SCREEN_ORIENTATION,
|
||||||
|
screenOrientation,
|
||||||
|
);
|
||||||
|
|
||||||
setState(() {
|
setState(() {});
|
||||||
});
|
},
|
||||||
}
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -228,11 +256,14 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
|||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: enableLabelPrinting,
|
value: enableLabelPrinting,
|
||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
InvenTreeSettingsManager().setValue(INV_ENABLE_LABEL_PRINTING, value);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_ENABLE_LABEL_PRINTING,
|
||||||
|
value,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
enableLabelPrinting = value;
|
enableLabelPrinting = value;
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
@ -300,7 +331,10 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
|||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: barcodeSounds,
|
value: barcodeSounds,
|
||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
InvenTreeSettingsManager().setValue(INV_SOUNDS_BARCODE, value);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_SOUNDS_BARCODE,
|
||||||
|
value,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
barcodeSounds = value;
|
barcodeSounds = value;
|
||||||
});
|
});
|
||||||
@ -308,9 +342,9 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Divider(height: 1),
|
Divider(height: 1),
|
||||||
]
|
],
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,22 +7,22 @@ import "package:inventree/app_colors.dart";
|
|||||||
|
|
||||||
import "package:inventree/widget/dialogs.dart";
|
import "package:inventree/widget/dialogs.dart";
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeBarcodeSettingsWidget extends StatefulWidget {
|
class InvenTreeBarcodeSettingsWidget extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_InvenTreeBarcodeSettingsState createState() => _InvenTreeBarcodeSettingsState();
|
_InvenTreeBarcodeSettingsState createState() =>
|
||||||
|
_InvenTreeBarcodeSettingsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _InvenTreeBarcodeSettingsState
|
||||||
class _InvenTreeBarcodeSettingsState extends State<InvenTreeBarcodeSettingsWidget> {
|
extends State<InvenTreeBarcodeSettingsWidget> {
|
||||||
|
|
||||||
_InvenTreeBarcodeSettingsState();
|
_InvenTreeBarcodeSettingsState();
|
||||||
|
|
||||||
int barcodeScanDelay = 500;
|
int barcodeScanDelay = 500;
|
||||||
int barcodeScanType = BARCODE_CONTROLLER_CAMERA;
|
int barcodeScanType = BARCODE_CONTROLLER_CAMERA;
|
||||||
bool barcodeScanSingle = false;
|
bool barcodeScanSingle = false;
|
||||||
|
|
||||||
final TextEditingController _barcodeScanDelayController = TextEditingController();
|
final TextEditingController _barcodeScanDelayController =
|
||||||
|
TextEditingController();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -31,20 +31,28 @@ class _InvenTreeBarcodeSettingsState extends State<InvenTreeBarcodeSettingsWidge
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> loadSettings() async {
|
Future<void> loadSettings() async {
|
||||||
barcodeScanDelay = await InvenTreeSettingsManager().getValue(INV_BARCODE_SCAN_DELAY, 500) as int;
|
barcodeScanDelay =
|
||||||
barcodeScanType = await InvenTreeSettingsManager().getValue(INV_BARCODE_SCAN_TYPE, BARCODE_CONTROLLER_CAMERA) as int;
|
await InvenTreeSettingsManager().getValue(INV_BARCODE_SCAN_DELAY, 500)
|
||||||
barcodeScanSingle = await InvenTreeSettingsManager().getBool(INV_BARCODE_SCAN_SINGLE, false);
|
as int;
|
||||||
|
barcodeScanType =
|
||||||
|
await InvenTreeSettingsManager().getValue(
|
||||||
|
INV_BARCODE_SCAN_TYPE,
|
||||||
|
BARCODE_CONTROLLER_CAMERA,
|
||||||
|
)
|
||||||
|
as int;
|
||||||
|
barcodeScanSingle = await InvenTreeSettingsManager().getBool(
|
||||||
|
INV_BARCODE_SCAN_SINGLE,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback function to edit the barcode scan delay value
|
// Callback function to edit the barcode scan delay value
|
||||||
// TODO: Next time any new settings are added, refactor this into a generic function
|
// TODO: Next time any new settings are added, refactor this into a generic function
|
||||||
Future<void> _editBarcodeScanDelay(BuildContext context) async {
|
Future<void> _editBarcodeScanDelay(BuildContext context) async {
|
||||||
|
|
||||||
_barcodeScanDelayController.text = barcodeScanDelay.toString();
|
_barcodeScanDelayController.text = barcodeScanDelay.toString();
|
||||||
|
|
||||||
return showDialog(
|
return showDialog(
|
||||||
@ -56,9 +64,7 @@ class _InvenTreeBarcodeSettingsState extends State<InvenTreeBarcodeSettingsWidge
|
|||||||
onChanged: (value) {},
|
onChanged: (value) {},
|
||||||
controller: _barcodeScanDelayController,
|
controller: _barcodeScanDelayController,
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(hintText: L10().barcodeScanDelayDetail),
|
||||||
hintText: L10().barcodeScanDelayDetail,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
MaterialButton(
|
MaterialButton(
|
||||||
@ -76,13 +82,18 @@ class _InvenTreeBarcodeSettingsState extends State<InvenTreeBarcodeSettingsWidge
|
|||||||
textColor: Colors.white,
|
textColor: Colors.white,
|
||||||
child: Text(L10().ok),
|
child: Text(L10().ok),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
int delay = int.tryParse(_barcodeScanDelayController.text) ?? barcodeScanDelay;
|
int delay =
|
||||||
|
int.tryParse(_barcodeScanDelayController.text) ??
|
||||||
|
barcodeScanDelay;
|
||||||
|
|
||||||
// Apply limits
|
// Apply limits
|
||||||
if (delay < 100) delay = 100;
|
if (delay < 100) delay = 100;
|
||||||
if (delay > 2500) delay = 2500;
|
if (delay > 2500) delay = 2500;
|
||||||
|
|
||||||
InvenTreeSettingsManager().setValue(INV_BARCODE_SCAN_DELAY, delay);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_BARCODE_SCAN_DELAY,
|
||||||
|
delay,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
barcodeScanDelay = delay;
|
barcodeScanDelay = delay;
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
@ -91,13 +102,12 @@ class _InvenTreeBarcodeSettingsState extends State<InvenTreeBarcodeSettingsWidge
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
// Construct an icon for the barcode scanner input
|
// Construct an icon for the barcode scanner input
|
||||||
Widget? barcodeInputIcon;
|
Widget? barcodeInputIcon;
|
||||||
|
|
||||||
@ -112,7 +122,7 @@ class _InvenTreeBarcodeSettingsState extends State<InvenTreeBarcodeSettingsWidge
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(L10().barcodeSettings),
|
title: Text(L10().barcodeSettings),
|
||||||
backgroundColor: COLOR_APP_BAR
|
backgroundColor: COLOR_APP_BAR,
|
||||||
),
|
),
|
||||||
body: Container(
|
body: Container(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
@ -135,17 +145,20 @@ class _InvenTreeBarcodeSettingsState extends State<InvenTreeBarcodeSettingsWidge
|
|||||||
title: Text(L10().scannerExternal),
|
title: Text(L10().scannerExternal),
|
||||||
subtitle: Text(L10().scannerExternalDetail),
|
subtitle: Text(L10().scannerExternalDetail),
|
||||||
leading: Icon(Icons.barcode_reader),
|
leading: Icon(Icons.barcode_reader),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
onSelected: (idx) async {
|
onSelected: (idx) async {
|
||||||
barcodeScanType = idx as int;
|
barcodeScanType = idx as int;
|
||||||
InvenTreeSettingsManager().setValue(INV_BARCODE_SCAN_TYPE, barcodeScanType);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_BARCODE_SCAN_TYPE,
|
||||||
|
barcodeScanType,
|
||||||
|
);
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().barcodeScanDelay),
|
title: Text(L10().barcodeScanDelay),
|
||||||
@ -165,17 +178,19 @@ class _InvenTreeBarcodeSettingsState extends State<InvenTreeBarcodeSettingsWidge
|
|||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: barcodeScanSingle,
|
value: barcodeScanSingle,
|
||||||
onChanged: (bool v) {
|
onChanged: (bool v) {
|
||||||
InvenTreeSettingsManager().setValue(INV_BARCODE_SCAN_SINGLE, v);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_BARCODE_SCAN_SINGLE,
|
||||||
|
v,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
barcodeScanSingle = v;
|
barcodeScanSingle = v;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||||
import "package:inventree/app_colors.dart";
|
import "package:inventree/app_colors.dart";
|
||||||
@ -12,10 +11,10 @@ class HomeScreenSettingsWidget extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _HomeScreenSettingsState extends State<HomeScreenSettingsWidget> {
|
class _HomeScreenSettingsState extends State<HomeScreenSettingsWidget> {
|
||||||
|
|
||||||
_HomeScreenSettingsState();
|
_HomeScreenSettingsState();
|
||||||
|
|
||||||
final GlobalKey<_HomeScreenSettingsState> _settingsKey = GlobalKey<_HomeScreenSettingsState>();
|
final GlobalKey<_HomeScreenSettingsState> _settingsKey =
|
||||||
|
GlobalKey<_HomeScreenSettingsState>();
|
||||||
|
|
||||||
// Home screen settings
|
// Home screen settings
|
||||||
bool homeShowSubscribed = true;
|
bool homeShowSubscribed = true;
|
||||||
@ -33,23 +32,38 @@ class _HomeScreenSettingsState extends State<HomeScreenSettingsWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> loadSettings() async {
|
Future<void> loadSettings() async {
|
||||||
|
|
||||||
// Load initial settings
|
// Load initial settings
|
||||||
|
|
||||||
homeShowSubscribed = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_SUBSCRIBED, true) as bool;
|
homeShowSubscribed =
|
||||||
homeShowPo = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_PO, true) as bool;
|
await InvenTreeSettingsManager().getValue(
|
||||||
homeShowSo = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_SO, true) as bool;
|
INV_HOME_SHOW_SUBSCRIBED,
|
||||||
homeShowManufacturers = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_MANUFACTURERS, true) as bool;
|
true,
|
||||||
homeShowCustomers = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_CUSTOMERS, true) as bool;
|
)
|
||||||
homeShowSuppliers = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_SUPPLIERS, true) as bool;
|
as bool;
|
||||||
|
homeShowPo =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_PO, true)
|
||||||
|
as bool;
|
||||||
|
homeShowSo =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_SO, true)
|
||||||
|
as bool;
|
||||||
|
homeShowManufacturers =
|
||||||
|
await InvenTreeSettingsManager().getValue(
|
||||||
|
INV_HOME_SHOW_MANUFACTURERS,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
as bool;
|
||||||
|
homeShowCustomers =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_CUSTOMERS, true)
|
||||||
|
as bool;
|
||||||
|
homeShowSuppliers =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_SUPPLIERS, true)
|
||||||
|
as bool;
|
||||||
|
|
||||||
setState(() {
|
setState(() {});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
key: _settingsKey,
|
key: _settingsKey,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
@ -66,12 +80,15 @@ class _HomeScreenSettingsState extends State<HomeScreenSettingsWidget> {
|
|||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: homeShowSubscribed,
|
value: homeShowSubscribed,
|
||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
InvenTreeSettingsManager().setValue(INV_HOME_SHOW_SUBSCRIBED, value);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_HOME_SHOW_SUBSCRIBED,
|
||||||
|
value,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
homeShowSubscribed = value;
|
homeShowSubscribed = value;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().homeShowPo),
|
title: Text(L10().homeShowPo),
|
||||||
@ -108,7 +125,10 @@ class _HomeScreenSettingsState extends State<HomeScreenSettingsWidget> {
|
|||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: homeShowSuppliers,
|
value: homeShowSuppliers,
|
||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
InvenTreeSettingsManager().setValue(INV_HOME_SHOW_SUPPLIERS, value);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_HOME_SHOW_SUPPLIERS,
|
||||||
|
value,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
homeShowSuppliers = value;
|
homeShowSuppliers = value;
|
||||||
});
|
});
|
||||||
@ -140,16 +160,19 @@ class _HomeScreenSettingsState extends State<HomeScreenSettingsWidget> {
|
|||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: homeShowCustomers,
|
value: homeShowCustomers,
|
||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
InvenTreeSettingsManager().setValue(INV_HOME_SHOW_CUSTOMERS, value);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_HOME_SHOW_CUSTOMERS,
|
||||||
|
value,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
homeShowCustomers = value;
|
homeShowCustomers = value;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
]
|
],
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||||
|
|
||||||
@ -9,21 +8,16 @@ import "package:inventree/api.dart";
|
|||||||
import "package:inventree/widget/dialogs.dart";
|
import "package:inventree/widget/dialogs.dart";
|
||||||
import "package:inventree/widget/progress.dart";
|
import "package:inventree/widget/progress.dart";
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeLoginWidget extends StatefulWidget {
|
class InvenTreeLoginWidget extends StatefulWidget {
|
||||||
|
|
||||||
const InvenTreeLoginWidget(this.profile) : super();
|
const InvenTreeLoginWidget(this.profile) : super();
|
||||||
|
|
||||||
final UserProfile profile;
|
final UserProfile profile;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_InvenTreeLoginState createState() => _InvenTreeLoginState();
|
_InvenTreeLoginState createState() => _InvenTreeLoginState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _InvenTreeLoginState extends State<InvenTreeLoginWidget> {
|
class _InvenTreeLoginState extends State<InvenTreeLoginWidget> {
|
||||||
|
|
||||||
final formKey = GlobalKey<FormState>();
|
final formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
String username = "";
|
String username = "";
|
||||||
@ -35,14 +29,12 @@ class _InvenTreeLoginState extends State<InvenTreeLoginWidget> {
|
|||||||
|
|
||||||
// Attempt login
|
// Attempt login
|
||||||
Future<void> _doLogin(BuildContext context) async {
|
Future<void> _doLogin(BuildContext context) async {
|
||||||
|
|
||||||
// Save form
|
// Save form
|
||||||
formKey.currentState?.save();
|
formKey.currentState?.save();
|
||||||
|
|
||||||
bool valid = formKey.currentState?.validate() ?? false;
|
bool valid = formKey.currentState?.validate() ?? false;
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
|
||||||
// Dismiss the keyboard
|
// Dismiss the keyboard
|
||||||
FocusScopeNode currentFocus = FocusScope.of(context);
|
FocusScopeNode currentFocus = FocusScope.of(context);
|
||||||
|
|
||||||
@ -53,7 +45,11 @@ class _InvenTreeLoginState extends State<InvenTreeLoginWidget> {
|
|||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
|
|
||||||
// Attempt login
|
// Attempt login
|
||||||
final response = await InvenTreeAPI().fetchToken(widget.profile, username, password);
|
final response = await InvenTreeAPI().fetchToken(
|
||||||
|
widget.profile,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
);
|
||||||
|
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
|
|
||||||
@ -75,12 +71,10 @@ class _InvenTreeLoginState extends State<InvenTreeLoginWidget> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
List<Widget> before = [
|
List<Widget> before = [
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().loginEnter),
|
title: Text(L10().loginEnter),
|
||||||
@ -99,11 +93,13 @@ class _InvenTreeLoginState extends State<InvenTreeLoginWidget> {
|
|||||||
|
|
||||||
if (error.isNotEmpty) {
|
if (error.isNotEmpty) {
|
||||||
after.add(Divider());
|
after.add(Divider());
|
||||||
after.add(ListTile(
|
after.add(
|
||||||
|
ListTile(
|
||||||
leading: Icon(TablerIcons.exclamation_circle, color: COLOR_DANGER),
|
leading: Icon(TablerIcons.exclamation_circle, color: COLOR_DANGER),
|
||||||
title: Text(L10().error, style: TextStyle(color: COLOR_DANGER)),
|
title: Text(L10().error, style: TextStyle(color: COLOR_DANGER)),
|
||||||
subtitle: Text(error, style: TextStyle(color: COLOR_DANGER)),
|
subtitle: Text(error, style: TextStyle(color: COLOR_DANGER)),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
@ -115,8 +111,8 @@ class _InvenTreeLoginState extends State<InvenTreeLoginWidget> {
|
|||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
_doLogin(context);
|
_doLogin(context);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
]
|
],
|
||||||
),
|
),
|
||||||
body: Form(
|
body: Form(
|
||||||
key: formKey,
|
key: formKey,
|
||||||
@ -131,7 +127,7 @@ class _InvenTreeLoginState extends State<InvenTreeLoginWidget> {
|
|||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: L10().username,
|
labelText: L10().username,
|
||||||
labelStyle: TextStyle(fontWeight: FontWeight.bold),
|
labelStyle: TextStyle(fontWeight: FontWeight.bold),
|
||||||
hintText: L10().enterUsername
|
hintText: L10().enterUsername,
|
||||||
),
|
),
|
||||||
initialValue: "",
|
initialValue: "",
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
@ -152,7 +148,9 @@ class _InvenTreeLoginState extends State<InvenTreeLoginWidget> {
|
|||||||
labelStyle: TextStyle(fontWeight: FontWeight.bold),
|
labelStyle: TextStyle(fontWeight: FontWeight.bold),
|
||||||
hintText: L10().enterPassword,
|
hintText: L10().enterPassword,
|
||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
icon: _obscured ? Icon(TablerIcons.eye) : Icon(TablerIcons.eye_off),
|
icon: _obscured
|
||||||
|
? Icon(TablerIcons.eye)
|
||||||
|
: Icon(TablerIcons.eye_off),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_obscured = !_obscured;
|
_obscured = !_obscured;
|
||||||
@ -172,16 +170,14 @@ class _InvenTreeLoginState extends State<InvenTreeLoginWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
},
|
||||||
),
|
),
|
||||||
...after,
|
...after,
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
padding: EdgeInsets.all(16),
|
padding: EdgeInsets.all(16),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||||
|
|
||||||
@ -6,15 +5,12 @@ import "package:inventree/l10.dart";
|
|||||||
import "package:inventree/app_colors.dart";
|
import "package:inventree/app_colors.dart";
|
||||||
import "package:inventree/preferences.dart";
|
import "package:inventree/preferences.dart";
|
||||||
|
|
||||||
|
|
||||||
class InvenTreePartSettingsWidget extends StatefulWidget {
|
class InvenTreePartSettingsWidget extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_InvenTreePartSettingsState createState() => _InvenTreePartSettingsState();
|
_InvenTreePartSettingsState createState() => _InvenTreePartSettingsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _InvenTreePartSettingsState extends State<InvenTreePartSettingsWidget> {
|
class _InvenTreePartSettingsState extends State<InvenTreePartSettingsWidget> {
|
||||||
|
|
||||||
_InvenTreePartSettingsState();
|
_InvenTreePartSettingsState();
|
||||||
|
|
||||||
bool partShowParameters = true;
|
bool partShowParameters = true;
|
||||||
@ -32,16 +28,33 @@ class _InvenTreePartSettingsState extends State<InvenTreePartSettingsWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> loadSettings() async {
|
Future<void> loadSettings() async {
|
||||||
partShowParameters = await InvenTreeSettingsManager().getBool(INV_PART_SHOW_PARAMETERS, true);
|
partShowParameters = await InvenTreeSettingsManager().getBool(
|
||||||
partShowBom = await InvenTreeSettingsManager().getBool(INV_PART_SHOW_BOM, true);
|
INV_PART_SHOW_PARAMETERS,
|
||||||
partShowPricing = await InvenTreeSettingsManager().getBool(INV_PART_SHOW_PRICING, true);
|
true,
|
||||||
stockShowHistory = await InvenTreeSettingsManager().getBool(INV_STOCK_SHOW_HISTORY, false);
|
);
|
||||||
stockShowTests = await InvenTreeSettingsManager().getBool(INV_STOCK_SHOW_TESTS, true);
|
partShowBom = await InvenTreeSettingsManager().getBool(
|
||||||
stockConfirmScan = await InvenTreeSettingsManager().getBool(INV_STOCK_CONFIRM_SCAN, false);
|
INV_PART_SHOW_BOM,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
partShowPricing = await InvenTreeSettingsManager().getBool(
|
||||||
|
INV_PART_SHOW_PRICING,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
stockShowHistory = await InvenTreeSettingsManager().getBool(
|
||||||
|
INV_STOCK_SHOW_HISTORY,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
stockShowTests = await InvenTreeSettingsManager().getBool(
|
||||||
|
INV_STOCK_SHOW_TESTS,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
stockConfirmScan = await InvenTreeSettingsManager().getBool(
|
||||||
|
INV_STOCK_CONFIRM_SCAN,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +63,7 @@ class _InvenTreePartSettingsState extends State<InvenTreePartSettingsWidget> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(L10().partSettings),
|
title: Text(L10().partSettings),
|
||||||
backgroundColor: COLOR_APP_BAR
|
backgroundColor: COLOR_APP_BAR,
|
||||||
),
|
),
|
||||||
body: Container(
|
body: Container(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
@ -62,7 +75,10 @@ class _InvenTreePartSettingsState extends State<InvenTreePartSettingsWidget> {
|
|||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: partShowParameters,
|
value: partShowParameters,
|
||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
InvenTreeSettingsManager().setValue(INV_PART_SHOW_PARAMETERS, value);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_PART_SHOW_PARAMETERS,
|
||||||
|
value,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
partShowParameters = value;
|
partShowParameters = value;
|
||||||
});
|
});
|
||||||
@ -90,7 +106,10 @@ class _InvenTreePartSettingsState extends State<InvenTreePartSettingsWidget> {
|
|||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: partShowPricing,
|
value: partShowPricing,
|
||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
InvenTreeSettingsManager().setValue(INV_PART_SHOW_PRICING, value);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_PART_SHOW_PRICING,
|
||||||
|
value,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
partShowPricing = value;
|
partShowPricing = value;
|
||||||
});
|
});
|
||||||
@ -105,7 +124,10 @@ class _InvenTreePartSettingsState extends State<InvenTreePartSettingsWidget> {
|
|||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: stockShowHistory,
|
value: stockShowHistory,
|
||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
InvenTreeSettingsManager().setValue(INV_STOCK_SHOW_HISTORY, value);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_STOCK_SHOW_HISTORY,
|
||||||
|
value,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
stockShowHistory = value;
|
stockShowHistory = value;
|
||||||
});
|
});
|
||||||
@ -119,7 +141,10 @@ class _InvenTreePartSettingsState extends State<InvenTreePartSettingsWidget> {
|
|||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: stockShowTests,
|
value: stockShowTests,
|
||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
InvenTreeSettingsManager().setValue(INV_STOCK_SHOW_TESTS, value);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_STOCK_SHOW_TESTS,
|
||||||
|
value,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
stockShowTests = value;
|
stockShowTests = value;
|
||||||
});
|
});
|
||||||
@ -133,16 +158,19 @@ class _InvenTreePartSettingsState extends State<InvenTreePartSettingsWidget> {
|
|||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: stockConfirmScan,
|
value: stockConfirmScan,
|
||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
InvenTreeSettingsManager().setValue(INV_STOCK_CONFIRM_SCAN, value);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_STOCK_CONFIRM_SCAN,
|
||||||
|
value,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
stockConfirmScan = value;
|
stockConfirmScan = value;
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||||
import "package:inventree/app_colors.dart";
|
import "package:inventree/app_colors.dart";
|
||||||
@ -6,15 +5,14 @@ import "package:inventree/app_colors.dart";
|
|||||||
import "package:inventree/l10.dart";
|
import "package:inventree/l10.dart";
|
||||||
import "package:inventree/preferences.dart";
|
import "package:inventree/preferences.dart";
|
||||||
|
|
||||||
|
|
||||||
class InvenTreePurchaseOrderSettingsWidget extends StatefulWidget {
|
class InvenTreePurchaseOrderSettingsWidget extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_InvenTreePurchaseOrderSettingsState createState() => _InvenTreePurchaseOrderSettingsState();
|
_InvenTreePurchaseOrderSettingsState createState() =>
|
||||||
|
_InvenTreePurchaseOrderSettingsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _InvenTreePurchaseOrderSettingsState
|
||||||
class _InvenTreePurchaseOrderSettingsState extends State<InvenTreePurchaseOrderSettingsWidget> {
|
extends State<InvenTreePurchaseOrderSettingsWidget> {
|
||||||
|
|
||||||
_InvenTreePurchaseOrderSettingsState();
|
_InvenTreePurchaseOrderSettingsState();
|
||||||
|
|
||||||
bool poEnable = true;
|
bool poEnable = true;
|
||||||
@ -30,12 +28,17 @@ class _InvenTreePurchaseOrderSettingsState extends State<InvenTreePurchaseOrderS
|
|||||||
|
|
||||||
Future<void> loadSettings() async {
|
Future<void> loadSettings() async {
|
||||||
poEnable = await InvenTreeSettingsManager().getBool(INV_PO_ENABLE, true);
|
poEnable = await InvenTreeSettingsManager().getBool(INV_PO_ENABLE, true);
|
||||||
poShowCamera = await InvenTreeSettingsManager().getBool(INV_PO_SHOW_CAMERA, true);
|
poShowCamera = await InvenTreeSettingsManager().getBool(
|
||||||
poConfirmScan = await InvenTreeSettingsManager().getBool(INV_PO_CONFIRM_SCAN, true);
|
INV_PO_SHOW_CAMERA,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
poConfirmScan = await InvenTreeSettingsManager().getBool(
|
||||||
|
INV_PO_CONFIRM_SCAN,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +73,10 @@ class _InvenTreePurchaseOrderSettingsState extends State<InvenTreePurchaseOrderS
|
|||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: poShowCamera,
|
value: poShowCamera,
|
||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
InvenTreeSettingsManager().setValue(INV_PO_SHOW_CAMERA, value);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_PO_SHOW_CAMERA,
|
||||||
|
value,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
poShowCamera = value;
|
poShowCamera = value;
|
||||||
});
|
});
|
||||||
@ -84,16 +90,19 @@ class _InvenTreePurchaseOrderSettingsState extends State<InvenTreePurchaseOrderS
|
|||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: poConfirmScan,
|
value: poConfirmScan,
|
||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
InvenTreeSettingsManager().setValue(INV_PO_CONFIRM_SCAN, value);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_PO_CONFIRM_SCAN,
|
||||||
|
value,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
poConfirmScan = value;
|
poConfirmScan = value;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
]
|
],
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,9 +6,7 @@ import "package:url_launcher/url_launcher.dart";
|
|||||||
import "package:inventree/l10.dart";
|
import "package:inventree/l10.dart";
|
||||||
import "package:inventree/helpers.dart";
|
import "package:inventree/helpers.dart";
|
||||||
|
|
||||||
|
|
||||||
class ReleaseNotesWidget extends StatelessWidget {
|
class ReleaseNotesWidget extends StatelessWidget {
|
||||||
|
|
||||||
const ReleaseNotesWidget(this.releaseNotes);
|
const ReleaseNotesWidget(this.releaseNotes);
|
||||||
|
|
||||||
final String releaseNotes;
|
final String releaseNotes;
|
||||||
@ -29,21 +27,18 @@ class ReleaseNotesWidget extends StatelessWidget {
|
|||||||
openLink(link);
|
openLink(link);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class CreditsWidget extends StatelessWidget {
|
class CreditsWidget extends StatelessWidget {
|
||||||
|
|
||||||
const CreditsWidget(this.credits);
|
const CreditsWidget(this.credits);
|
||||||
|
|
||||||
final String credits;
|
final String credits;
|
||||||
|
|
||||||
// Callback function when a link is clicked in the markdown
|
// Callback function when a link is clicked in the markdown
|
||||||
Future<void> openLink(String url) async {
|
Future<void> openLink(String url) async {
|
||||||
|
|
||||||
final link = Uri.parse(url);
|
final link = Uri.parse(url);
|
||||||
|
|
||||||
if (await canLaunchUrl(link)) {
|
if (await canLaunchUrl(link)) {
|
||||||
@ -67,7 +62,7 @@ class CreditsWidget extends StatelessWidget {
|
|||||||
openLink(link);
|
openLink(link);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||||
|
|
||||||
@ -6,15 +5,14 @@ import "package:inventree/l10.dart";
|
|||||||
import "package:inventree/app_colors.dart";
|
import "package:inventree/app_colors.dart";
|
||||||
import "package:inventree/preferences.dart";
|
import "package:inventree/preferences.dart";
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeSalesOrderSettingsWidget extends StatefulWidget {
|
class InvenTreeSalesOrderSettingsWidget extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_InvenTreeSalesOrderSettingsState createState() => _InvenTreeSalesOrderSettingsState();
|
_InvenTreeSalesOrderSettingsState createState() =>
|
||||||
|
_InvenTreeSalesOrderSettingsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _InvenTreeSalesOrderSettingsState
|
||||||
class _InvenTreeSalesOrderSettingsState extends State<InvenTreeSalesOrderSettingsWidget> {
|
extends State<InvenTreeSalesOrderSettingsWidget> {
|
||||||
|
|
||||||
_InvenTreeSalesOrderSettingsState();
|
_InvenTreeSalesOrderSettingsState();
|
||||||
|
|
||||||
bool soEnable = true;
|
bool soEnable = true;
|
||||||
@ -29,11 +27,13 @@ class _InvenTreeSalesOrderSettingsState extends State<InvenTreeSalesOrderSetting
|
|||||||
|
|
||||||
Future<void> loadSettings() async {
|
Future<void> loadSettings() async {
|
||||||
soEnable = await InvenTreeSettingsManager().getBool(INV_SO_ENABLE, true);
|
soEnable = await InvenTreeSettingsManager().getBool(INV_SO_ENABLE, true);
|
||||||
soShowCamera = await InvenTreeSettingsManager().getBool(INV_SO_SHOW_CAMERA, true);
|
soShowCamera = await InvenTreeSettingsManager().getBool(
|
||||||
|
INV_SO_SHOW_CAMERA,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,16 +68,19 @@ class _InvenTreeSalesOrderSettingsState extends State<InvenTreeSalesOrderSetting
|
|||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: soShowCamera,
|
value: soShowCamera,
|
||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
InvenTreeSettingsManager().setValue(INV_SO_SHOW_CAMERA, value);
|
InvenTreeSettingsManager().setValue(
|
||||||
|
INV_SO_SHOW_CAMERA,
|
||||||
|
value,
|
||||||
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
soShowCamera = value;
|
soShowCamera = value;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
]
|
],
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,39 +12,37 @@ import "package:inventree/api.dart";
|
|||||||
import "package:inventree/user_profile.dart";
|
import "package:inventree/user_profile.dart";
|
||||||
|
|
||||||
class InvenTreeSelectServerWidget extends StatefulWidget {
|
class InvenTreeSelectServerWidget extends StatefulWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_InvenTreeSelectServerState createState() => _InvenTreeSelectServerState();
|
_InvenTreeSelectServerState createState() => _InvenTreeSelectServerState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _InvenTreeSelectServerState extends State<InvenTreeSelectServerWidget> {
|
class _InvenTreeSelectServerState extends State<InvenTreeSelectServerWidget> {
|
||||||
|
|
||||||
_InvenTreeSelectServerState() {
|
_InvenTreeSelectServerState() {
|
||||||
_reload();
|
_reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
final GlobalKey<_InvenTreeSelectServerState> _loginKey = GlobalKey<_InvenTreeSelectServerState>();
|
final GlobalKey<_InvenTreeSelectServerState> _loginKey =
|
||||||
|
GlobalKey<_InvenTreeSelectServerState>();
|
||||||
|
|
||||||
List<UserProfile> profiles = [];
|
List<UserProfile> profiles = [];
|
||||||
|
|
||||||
Future<void> _reload() async {
|
Future<void> _reload() async {
|
||||||
|
|
||||||
profiles = await UserProfileDBManager().getAllProfiles();
|
profiles = await UserProfileDBManager().getAllProfiles();
|
||||||
|
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(() {
|
setState(() {});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Logout the selected profile (delete the stored token)
|
* Logout the selected profile (delete the stored token)
|
||||||
*/
|
*/
|
||||||
Future<void> _logoutProfile(BuildContext context, {UserProfile? userProfile}) async {
|
Future<void> _logoutProfile(
|
||||||
|
BuildContext context, {
|
||||||
|
UserProfile? userProfile,
|
||||||
|
}) async {
|
||||||
if (userProfile != null) {
|
if (userProfile != null) {
|
||||||
userProfile.token = "";
|
userProfile.token = "";
|
||||||
await UserProfileDBManager().updateProfile(userProfile);
|
await UserProfileDBManager().updateProfile(userProfile);
|
||||||
@ -54,26 +52,25 @@ class _InvenTreeSelectServerState extends State<InvenTreeSelectServerWidget> {
|
|||||||
|
|
||||||
InvenTreeAPI().disconnectFromServer();
|
InvenTreeAPI().disconnectFromServer();
|
||||||
_reload();
|
_reload();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Edit the selected profile
|
* Edit the selected profile
|
||||||
*/
|
*/
|
||||||
void _editProfile(BuildContext context, {UserProfile? userProfile, bool createNew = false}) {
|
void _editProfile(
|
||||||
|
BuildContext context, {
|
||||||
|
UserProfile? userProfile,
|
||||||
|
bool createNew = false,
|
||||||
|
}) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => ProfileEditWidget(userProfile)),
|
||||||
builder: (context) => ProfileEditWidget(userProfile)
|
|
||||||
)
|
|
||||||
).then((context) {
|
).then((context) {
|
||||||
_reload();
|
_reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _selectProfile(BuildContext context, UserProfile profile) async {
|
Future<void> _selectProfile(BuildContext context, UserProfile profile) async {
|
||||||
|
|
||||||
// Disconnect InvenTree
|
// Disconnect InvenTree
|
||||||
InvenTreeAPI().disconnectFromServer();
|
InvenTreeAPI().disconnectFromServer();
|
||||||
|
|
||||||
@ -94,8 +91,9 @@ class _InvenTreeSelectServerState extends State<InvenTreeSelectServerWidget> {
|
|||||||
// First check if the profile has an associate token
|
// First check if the profile has an associate token
|
||||||
if (!prf.hasToken) {
|
if (!prf.hasToken) {
|
||||||
// Redirect user to login screen
|
// Redirect user to login screen
|
||||||
Navigator.push(context,
|
Navigator.push(
|
||||||
MaterialPageRoute(builder: (context) => InvenTreeLoginWidget(profile))
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => InvenTreeLoginWidget(profile)),
|
||||||
).then((value) async {
|
).then((value) async {
|
||||||
_reload();
|
_reload();
|
||||||
// Reload profile
|
// Reload profile
|
||||||
@ -126,7 +124,6 @@ class _InvenTreeSelectServerState extends State<InvenTreeSelectServerWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _deleteProfile(UserProfile profile) async {
|
Future<void> _deleteProfile(UserProfile profile) async {
|
||||||
|
|
||||||
await UserProfileDBManager().deleteProfile(profile);
|
await UserProfileDBManager().deleteProfile(profile);
|
||||||
|
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
@ -135,13 +132,13 @@ class _InvenTreeSelectServerState extends State<InvenTreeSelectServerWidget> {
|
|||||||
|
|
||||||
_reload();
|
_reload();
|
||||||
|
|
||||||
if (InvenTreeAPI().isConnected() && profile.key == (InvenTreeAPI().profile?.key ?? "")) {
|
if (InvenTreeAPI().isConnected() &&
|
||||||
|
profile.key == (InvenTreeAPI().profile?.key ?? "")) {
|
||||||
InvenTreeAPI().disconnectFromServer();
|
InvenTreeAPI().disconnectFromServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget? _getProfileIcon(UserProfile profile) {
|
Widget? _getProfileIcon(UserProfile profile) {
|
||||||
|
|
||||||
// Not selected? No icon for you!
|
// Not selected? No icon for you!
|
||||||
if (!profile.selected) return null;
|
if (!profile.selected) return null;
|
||||||
|
|
||||||
@ -152,39 +149,32 @@ class _InvenTreeSelectServerState extends State<InvenTreeSelectServerWidget> {
|
|||||||
|
|
||||||
// Reflect the connection status of the server
|
// Reflect the connection status of the server
|
||||||
if (InvenTreeAPI().isConnected()) {
|
if (InvenTreeAPI().isConnected()) {
|
||||||
return Icon(
|
return Icon(TablerIcons.circle_check, color: COLOR_SUCCESS);
|
||||||
TablerIcons.circle_check,
|
|
||||||
color: COLOR_SUCCESS
|
|
||||||
);
|
|
||||||
} else if (InvenTreeAPI().isConnecting()) {
|
} else if (InvenTreeAPI().isConnecting()) {
|
||||||
return Spinner(
|
return Spinner(icon: TablerIcons.loader_2, color: COLOR_PROGRESS);
|
||||||
icon: TablerIcons.loader_2,
|
|
||||||
color: COLOR_PROGRESS,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return Icon(
|
return Icon(TablerIcons.circle_x, color: COLOR_DANGER);
|
||||||
TablerIcons.circle_x,
|
|
||||||
color: COLOR_DANGER,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
List<Widget> children = [];
|
List<Widget> children = [];
|
||||||
|
|
||||||
if (profiles.isNotEmpty) {
|
if (profiles.isNotEmpty) {
|
||||||
for (int idx = 0; idx < profiles.length; idx++) {
|
for (int idx = 0; idx < profiles.length; idx++) {
|
||||||
UserProfile profile = profiles[idx];
|
UserProfile profile = profiles[idx];
|
||||||
|
|
||||||
children.add(ListTile(
|
children.add(
|
||||||
title: Text(
|
ListTile(
|
||||||
profile.name,
|
title: Text(profile.name),
|
||||||
),
|
tileColor: profile.selected
|
||||||
tileColor: profile.selected ? Theme.of(context).secondaryHeaderColor : null,
|
? Theme.of(context).secondaryHeaderColor
|
||||||
|
: null,
|
||||||
subtitle: Text("${profile.server}"),
|
subtitle: Text("${profile.server}"),
|
||||||
leading: profile.hasToken ? Icon(TablerIcons.user_check, color: COLOR_SUCCESS) : Icon(TablerIcons.user_cancel, color: COLOR_WARNING),
|
leading: profile.hasToken
|
||||||
|
? Icon(TablerIcons.user_check, color: COLOR_SUCCESS)
|
||||||
|
: Icon(TablerIcons.user_cancel, color: COLOR_WARNING),
|
||||||
trailing: _getProfileIcon(profile),
|
trailing: _getProfileIcon(profile),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_selectProfile(context, profile);
|
_selectProfile(context, profile);
|
||||||
@ -204,7 +194,7 @@ class _InvenTreeSelectServerState extends State<InvenTreeSelectServerWidget> {
|
|||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text(L10().profileConnect),
|
title: Text(L10().profileConnect),
|
||||||
leading: Icon(TablerIcons.server),
|
leading: Icon(TablerIcons.server),
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
SimpleDialogOption(
|
SimpleDialogOption(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -213,8 +203,8 @@ class _InvenTreeSelectServerState extends State<InvenTreeSelectServerWidget> {
|
|||||||
},
|
},
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text(L10().profileEdit),
|
title: Text(L10().profileEdit),
|
||||||
leading: Icon(TablerIcons.edit)
|
leading: Icon(TablerIcons.edit),
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
SimpleDialogOption(
|
SimpleDialogOption(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -224,7 +214,7 @@ class _InvenTreeSelectServerState extends State<InvenTreeSelectServerWidget> {
|
|||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text(L10().profileLogout),
|
title: Text(L10().profileLogout),
|
||||||
leading: Icon(TablerIcons.logout),
|
leading: Icon(TablerIcons.logout),
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
Divider(),
|
Divider(),
|
||||||
SimpleDialogOption(
|
SimpleDialogOption(
|
||||||
@ -238,28 +228,28 @@ class _InvenTreeSelectServerState extends State<InvenTreeSelectServerWidget> {
|
|||||||
icon: TablerIcons.trash,
|
icon: TablerIcons.trash,
|
||||||
onAccept: () {
|
onAccept: () {
|
||||||
_deleteProfile(profile);
|
_deleteProfile(profile);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text(L10().profileDelete, style: TextStyle(color: Colors.red)),
|
title: Text(
|
||||||
|
L10().profileDelete,
|
||||||
|
style: TextStyle(color: Colors.red),
|
||||||
|
),
|
||||||
leading: Icon(TablerIcons.trash, color: Colors.red),
|
leading: Icon(TablerIcons.trash, color: Colors.red),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No profile available!
|
// No profile available!
|
||||||
children.add(
|
children.add(ListTile(title: Text(L10().profileNone)));
|
||||||
ListTile(
|
|
||||||
title: Text(L10().profileNone),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -273,27 +263,25 @@ class _InvenTreeSelectServerState extends State<InvenTreeSelectServerWidget> {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
_editProfile(context, createNew: true);
|
_editProfile(context, createNew: true);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: Container(
|
body: Container(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: ListTile.divideTiles(
|
children: ListTile.divideTiles(
|
||||||
context: context,
|
context: context,
|
||||||
tiles: children
|
tiles: children,
|
||||||
).toList(),
|
).toList(),
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Widget for editing server details
|
* Widget for editing server details
|
||||||
*/
|
*/
|
||||||
class ProfileEditWidget extends StatefulWidget {
|
class ProfileEditWidget extends StatefulWidget {
|
||||||
|
|
||||||
const ProfileEditWidget(this.profile) : super();
|
const ProfileEditWidget(this.profile) : super();
|
||||||
|
|
||||||
final UserProfile? profile;
|
final UserProfile? profile;
|
||||||
@ -303,7 +291,6 @@ class ProfileEditWidget extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ProfileEditState extends State<ProfileEditWidget> {
|
class _ProfileEditState extends State<ProfileEditWidget> {
|
||||||
|
|
||||||
_ProfileEditState() : super();
|
_ProfileEditState() : super();
|
||||||
|
|
||||||
final formKey = GlobalKey<FormState>();
|
final formKey = GlobalKey<FormState>();
|
||||||
@ -316,7 +303,9 @@ class _ProfileEditState extends State<ProfileEditWidget> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor: COLOR_APP_BAR,
|
backgroundColor: COLOR_APP_BAR,
|
||||||
title: Text(widget.profile == null ? L10().profileAdd : L10().profileEdit),
|
title: Text(
|
||||||
|
widget.profile == null ? L10().profileAdd : L10().profileEdit,
|
||||||
|
),
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(TablerIcons.circle_check),
|
icon: Icon(TablerIcons.circle_check),
|
||||||
@ -327,14 +316,10 @@ class _ProfileEditState extends State<ProfileEditWidget> {
|
|||||||
UserProfile? prf = widget.profile;
|
UserProfile? prf = widget.profile;
|
||||||
|
|
||||||
if (prf == null) {
|
if (prf == null) {
|
||||||
UserProfile profile = UserProfile(
|
UserProfile profile = UserProfile(name: name, server: server);
|
||||||
name: name,
|
|
||||||
server: server,
|
|
||||||
);
|
|
||||||
|
|
||||||
await UserProfileDBManager().addProfile(profile);
|
await UserProfileDBManager().addProfile(profile);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
prf.name = name;
|
prf.name = name;
|
||||||
prf.server = server;
|
prf.server = server;
|
||||||
|
|
||||||
@ -345,8 +330,8 @@ class _ProfileEditState extends State<ProfileEditWidget> {
|
|||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
]
|
],
|
||||||
),
|
),
|
||||||
body: Form(
|
body: Form(
|
||||||
key: formKey,
|
key: formKey,
|
||||||
@ -373,7 +358,7 @@ class _ProfileEditState extends State<ProfileEditWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
},
|
||||||
),
|
),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
@ -398,7 +383,8 @@ class _ProfileEditState extends State<ProfileEditWidget> {
|
|||||||
return L10().invalidHost;
|
return L10().invalidHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!value.startsWith("http:") && !value.startsWith("https:")) {
|
if (!value.startsWith("http:") &&
|
||||||
|
!value.startsWith("https:")) {
|
||||||
// return L10().serverStart;
|
// return L10().serverStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -410,7 +396,10 @@ class _ProfileEditState extends State<ProfileEditWidget> {
|
|||||||
Uri uri = Uri.parse(value);
|
Uri uri = Uri.parse(value);
|
||||||
|
|
||||||
if (uri.hasScheme) {
|
if (uri.hasScheme) {
|
||||||
if (!["http", "https"].contains(uri.scheme.toLowerCase())) {
|
if (![
|
||||||
|
"http",
|
||||||
|
"https",
|
||||||
|
].contains(uri.scheme.toLowerCase())) {
|
||||||
return L10().serverStart;
|
return L10().serverStart;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -422,12 +411,11 @@ class _ProfileEditState extends State<ProfileEditWidget> {
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
]
|
],
|
||||||
),
|
),
|
||||||
padding: EdgeInsets.all(16),
|
padding: EdgeInsets.all(16),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -16,15 +16,11 @@ import "package:inventree/settings/sales_order_settings.dart";
|
|||||||
|
|
||||||
// InvenTree settings view
|
// InvenTree settings view
|
||||||
class InvenTreeSettingsWidget extends StatefulWidget {
|
class InvenTreeSettingsWidget extends StatefulWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_InvenTreeSettingsState createState() => _InvenTreeSettingsState();
|
_InvenTreeSettingsState createState() => _InvenTreeSettingsState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _InvenTreeSettingsState extends State<InvenTreeSettingsWidget> {
|
class _InvenTreeSettingsState extends State<InvenTreeSettingsWidget> {
|
||||||
|
|
||||||
final _scaffoldKey = GlobalKey<ScaffoldState>();
|
final _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -32,8 +28,10 @@ class _InvenTreeSettingsState extends State<InvenTreeSettingsWidget> {
|
|||||||
*/
|
*/
|
||||||
Future<void> _about() async {
|
Future<void> _about() async {
|
||||||
PackageInfo.fromPlatform().then((PackageInfo info) {
|
PackageInfo.fromPlatform().then((PackageInfo info) {
|
||||||
Navigator.push(context,
|
Navigator.push(
|
||||||
MaterialPageRoute(builder: (context) => InvenTreeAboutWidget(info)));
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => InvenTreeAboutWidget(info)),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +51,12 @@ class _InvenTreeSettingsState extends State<InvenTreeSettingsWidget> {
|
|||||||
subtitle: Text(L10().configureServer),
|
subtitle: Text(L10().configureServer),
|
||||||
leading: Icon(TablerIcons.server, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.server, color: COLOR_ACTION),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeSelectServerWidget()));
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => InvenTreeSelectServerWidget(),
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Divider(),
|
Divider(),
|
||||||
@ -62,39 +65,65 @@ class _InvenTreeSettingsState extends State<InvenTreeSettingsWidget> {
|
|||||||
subtitle: Text(L10().appSettingsDetails),
|
subtitle: Text(L10().appSettingsDetails),
|
||||||
leading: Icon(TablerIcons.settings, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.settings, color: COLOR_ACTION),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeAppSettingsWidget()));
|
Navigator.push(
|
||||||
}
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => InvenTreeAppSettingsWidget(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().homeScreen),
|
title: Text(L10().homeScreen),
|
||||||
subtitle: Text(L10().homeScreenSettings),
|
subtitle: Text(L10().homeScreenSettings),
|
||||||
leading: Icon(TablerIcons.home, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.home, color: COLOR_ACTION),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => HomeScreenSettingsWidget()));
|
Navigator.push(
|
||||||
}
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => HomeScreenSettingsWidget(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().barcodes),
|
title: Text(L10().barcodes),
|
||||||
subtitle: Text(L10().barcodeSettings),
|
subtitle: Text(L10().barcodeSettings),
|
||||||
leading: Icon(TablerIcons.barcode, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.barcode, color: COLOR_ACTION),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeBarcodeSettingsWidget()));
|
Navigator.push(
|
||||||
}
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => InvenTreeBarcodeSettingsWidget(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().part),
|
title: Text(L10().part),
|
||||||
subtitle: Text(L10().partSettings),
|
subtitle: Text(L10().partSettings),
|
||||||
leading: Icon(TablerIcons.box, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.box, color: COLOR_ACTION),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreePartSettingsWidget()));
|
Navigator.push(
|
||||||
}
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => InvenTreePartSettingsWidget(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().purchaseOrder),
|
title: Text(L10().purchaseOrder),
|
||||||
subtitle: Text(L10().purchaseOrderSettings),
|
subtitle: Text(L10().purchaseOrderSettings),
|
||||||
leading: Icon(TablerIcons.shopping_cart, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.shopping_cart, color: COLOR_ACTION),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreePurchaseOrderSettingsWidget()));
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
InvenTreePurchaseOrderSettingsWidget(),
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
@ -102,7 +131,12 @@ class _InvenTreeSettingsState extends State<InvenTreeSettingsWidget> {
|
|||||||
subtitle: Text(L10().salesOrderSettings),
|
subtitle: Text(L10().salesOrderSettings),
|
||||||
leading: Icon(TablerIcons.truck, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.truck, color: COLOR_ACTION),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeSalesOrderSettingsWidget()));
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => InvenTreeSalesOrderSettingsWidget(),
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Divider(),
|
Divider(),
|
||||||
@ -110,10 +144,10 @@ class _InvenTreeSettingsState extends State<InvenTreeSettingsWidget> {
|
|||||||
title: Text(L10().about),
|
title: Text(L10().about),
|
||||||
leading: Icon(TablerIcons.info_circle, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.info_circle, color: COLOR_ACTION),
|
||||||
onTap: _about,
|
onTap: _about,
|
||||||
)
|
),
|
||||||
]
|
],
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,11 +1,9 @@
|
|||||||
|
|
||||||
import "package:sembast/sembast.dart";
|
import "package:sembast/sembast.dart";
|
||||||
|
|
||||||
import "package:inventree/helpers.dart";
|
import "package:inventree/helpers.dart";
|
||||||
import "package:inventree/preferences.dart";
|
import "package:inventree/preferences.dart";
|
||||||
|
|
||||||
class UserProfile {
|
class UserProfile {
|
||||||
|
|
||||||
UserProfile({
|
UserProfile({
|
||||||
this.key,
|
this.key,
|
||||||
this.name = "",
|
this.name = "",
|
||||||
@ -14,7 +12,11 @@ class UserProfile {
|
|||||||
this.selected = false,
|
this.selected = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory UserProfile.fromJson(int key, Map<String, dynamic> json, bool isSelected) => UserProfile(
|
factory UserProfile.fromJson(
|
||||||
|
int key,
|
||||||
|
Map<String, dynamic> json,
|
||||||
|
bool isSelected,
|
||||||
|
) => UserProfile(
|
||||||
key: key,
|
key: key,
|
||||||
name: (json["name"] ?? "") as String,
|
name: (json["name"] ?? "") as String,
|
||||||
server: (json["server"] ?? "") as String,
|
server: (json["server"] ?? "") as String,
|
||||||
@ -58,7 +60,6 @@ class UserProfile {
|
|||||||
* Class for storing and managing user (server) profiles
|
* Class for storing and managing user (server) profiles
|
||||||
*/
|
*/
|
||||||
class UserProfileDBManager {
|
class UserProfileDBManager {
|
||||||
|
|
||||||
final store = StoreRef("profiles");
|
final store = StoreRef("profiles");
|
||||||
|
|
||||||
Future<Database> get _db async => InvenTreePreferencesDB.instance.database;
|
Future<Database> get _db async => InvenTreePreferencesDB.instance.database;
|
||||||
@ -67,7 +68,6 @@ class UserProfileDBManager {
|
|||||||
* Check if a profile with the specified name exists in the database
|
* Check if a profile with the specified name exists in the database
|
||||||
*/
|
*/
|
||||||
Future<bool> profileNameExists(String name) async {
|
Future<bool> profileNameExists(String name) async {
|
||||||
|
|
||||||
final profiles = await getAllProfiles();
|
final profiles = await getAllProfiles();
|
||||||
|
|
||||||
for (var prf in profiles) {
|
for (var prf in profiles) {
|
||||||
@ -84,9 +84,10 @@ class UserProfileDBManager {
|
|||||||
* Add a new UserProfile to the profiles database.
|
* Add a new UserProfile to the profiles database.
|
||||||
*/
|
*/
|
||||||
Future<bool> addProfile(UserProfile profile) async {
|
Future<bool> addProfile(UserProfile profile) async {
|
||||||
|
|
||||||
if (profile.name.isEmpty) {
|
if (profile.name.isEmpty) {
|
||||||
debug("addProfile() : Profile missing required values - not adding to database");
|
debug(
|
||||||
|
"addProfile() : Profile missing required values - not adding to database",
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +114,6 @@ class UserProfileDBManager {
|
|||||||
* The unique integer <key> is used to determine if the profile already exists.
|
* The unique integer <key> is used to determine if the profile already exists.
|
||||||
*/
|
*/
|
||||||
Future<bool> updateProfile(UserProfile profile) async {
|
Future<bool> updateProfile(UserProfile profile) async {
|
||||||
|
|
||||||
// Prevent invalid profile data from being updated
|
// Prevent invalid profile data from being updated
|
||||||
if (profile.name.isEmpty) {
|
if (profile.name.isEmpty) {
|
||||||
debug("updateProfile() : Profile missing required values - not updating");
|
debug("updateProfile() : Profile missing required values - not updating");
|
||||||
@ -144,15 +144,15 @@ class UserProfileDBManager {
|
|||||||
* The key of the UserProfile should match the "selected" property
|
* The key of the UserProfile should match the "selected" property
|
||||||
*/
|
*/
|
||||||
Future<UserProfile?> getSelectedProfile() async {
|
Future<UserProfile?> getSelectedProfile() async {
|
||||||
|
|
||||||
final selected = await store.record("selected").get(await _db);
|
final selected = await store.record("selected").get(await _db);
|
||||||
|
|
||||||
final profiles = await store.find(await _db);
|
final profiles = await store.find(await _db);
|
||||||
|
|
||||||
debug("getSelectedProfile() : ${profiles.length} profiles available - selected = ${selected}");
|
debug(
|
||||||
|
"getSelectedProfile() : ${profiles.length} profiles available - selected = ${selected}",
|
||||||
|
);
|
||||||
|
|
||||||
for (int idx = 0; idx < profiles.length; idx++) {
|
for (int idx = 0; idx < profiles.length; idx++) {
|
||||||
|
|
||||||
if (profiles[idx].key is int && profiles[idx].key == selected) {
|
if (profiles[idx].key is int && profiles[idx].key == selected) {
|
||||||
return UserProfile.fromJson(
|
return UserProfile.fromJson(
|
||||||
profiles[idx].key! as int,
|
profiles[idx].key! as int,
|
||||||
@ -169,7 +169,6 @@ class UserProfileDBManager {
|
|||||||
* Return all user profile objects
|
* Return all user profile objects
|
||||||
*/
|
*/
|
||||||
Future<List<UserProfile>> getAllProfiles() async {
|
Future<List<UserProfile>> getAllProfiles() async {
|
||||||
|
|
||||||
final selected = await store.record("selected").get(await _db);
|
final selected = await store.record("selected").get(await _db);
|
||||||
|
|
||||||
final profiles = await store.find(await _db);
|
final profiles = await store.find(await _db);
|
||||||
@ -177,25 +176,26 @@ class UserProfileDBManager {
|
|||||||
List<UserProfile> profileList = [];
|
List<UserProfile> profileList = [];
|
||||||
|
|
||||||
for (int idx = 0; idx < profiles.length; idx++) {
|
for (int idx = 0; idx < profiles.length; idx++) {
|
||||||
|
|
||||||
if (profiles[idx].key is int) {
|
if (profiles[idx].key is int) {
|
||||||
profileList.add(
|
profileList.add(
|
||||||
UserProfile.fromJson(
|
UserProfile.fromJson(
|
||||||
profiles[idx].key! as int,
|
profiles[idx].key! as int,
|
||||||
profiles[idx].value! as Map<String, dynamic>,
|
profiles[idx].value! as Map<String, dynamic>,
|
||||||
profiles[idx].key == selected,
|
profiles[idx].key == selected,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are no available profiles, create a demo profile
|
// If there are no available profiles, create a demo profile
|
||||||
if (profileList.isEmpty) {
|
if (profileList.isEmpty) {
|
||||||
bool added = await InvenTreeSettingsManager().getBool("demo_profile_added", false);
|
bool added = await InvenTreeSettingsManager().getBool(
|
||||||
|
"demo_profile_added",
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
// Don't add a new profile if we have added it previously
|
// Don't add a new profile if we have added it previously
|
||||||
if (!added) {
|
if (!added) {
|
||||||
|
|
||||||
await InvenTreeSettingsManager().setValue("demo_profile_added", true);
|
await InvenTreeSettingsManager().setValue("demo_profile_added", true);
|
||||||
|
|
||||||
UserProfile demoProfile = UserProfile(
|
UserProfile demoProfile = UserProfile(
|
||||||
@ -212,7 +212,6 @@ class UserProfileDBManager {
|
|||||||
return profileList;
|
return profileList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Retrieve a profile by key (or null if no match exists)
|
* Retrieve a profile by key (or null if no match exists)
|
||||||
*/
|
*/
|
||||||
@ -231,7 +230,6 @@ class UserProfileDBManager {
|
|||||||
return prf;
|
return prf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Retrieve a profile by name (or null if no match exists)
|
* Retrieve a profile by name (or null if no match exists)
|
||||||
*/
|
*/
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "dart:io";
|
import "dart:io";
|
||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
@ -17,7 +16,6 @@ import "package:inventree/widget/progress.dart";
|
|||||||
import "package:inventree/widget/snacks.dart";
|
import "package:inventree/widget/snacks.dart";
|
||||||
import "package:inventree/widget/refreshable_state.dart";
|
import "package:inventree/widget/refreshable_state.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A generic widget for displaying a list of attachments.
|
* A generic widget for displaying a list of attachments.
|
||||||
*
|
*
|
||||||
@ -25,8 +23,12 @@ import "package:inventree/widget/refreshable_state.dart";
|
|||||||
* we pass a subclassed instance of the InvenTreeAttachment model.
|
* we pass a subclassed instance of the InvenTreeAttachment model.
|
||||||
*/
|
*/
|
||||||
class AttachmentWidget extends StatefulWidget {
|
class AttachmentWidget extends StatefulWidget {
|
||||||
|
const AttachmentWidget(
|
||||||
const AttachmentWidget(this.attachmentClass, this.modelId, this.imagePrefix, this.hasUploadPermission) : super();
|
this.attachmentClass,
|
||||||
|
this.modelId,
|
||||||
|
this.imagePrefix,
|
||||||
|
this.hasUploadPermission,
|
||||||
|
) : super();
|
||||||
|
|
||||||
final InvenTreeAttachment attachmentClass;
|
final InvenTreeAttachment attachmentClass;
|
||||||
final int modelId;
|
final int modelId;
|
||||||
@ -37,9 +39,7 @@ class AttachmentWidget extends StatefulWidget {
|
|||||||
_AttachmentWidgetState createState() => _AttachmentWidgetState();
|
_AttachmentWidgetState createState() => _AttachmentWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
|
class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
|
||||||
|
|
||||||
_AttachmentWidgetState();
|
_AttachmentWidgetState();
|
||||||
|
|
||||||
List<InvenTreeAttachment> attachments = [];
|
List<InvenTreeAttachment> attachments = [];
|
||||||
@ -64,7 +64,7 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
|
|||||||
refresh(context);
|
refresh(context);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(TablerIcons.file_upload),
|
icon: Icon(TablerIcons.file_upload),
|
||||||
@ -74,20 +74,19 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
|
|||||||
refresh(context);
|
refresh(context);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> upload(BuildContext context, File? file) async {
|
Future<void> upload(BuildContext context, File? file) async {
|
||||||
|
|
||||||
if (file == null) return;
|
if (file == null) return;
|
||||||
|
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
|
|
||||||
final bool result = await widget.attachmentClass.uploadAttachment(
|
final bool result = await widget.attachmentClass.uploadAttachment(
|
||||||
file,
|
file,
|
||||||
widget.modelId
|
widget.modelId,
|
||||||
);
|
);
|
||||||
|
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
@ -101,35 +100,39 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
|
|||||||
refresh(context);
|
refresh(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> editAttachment(
|
||||||
Future<void> editAttachment(BuildContext context, InvenTreeAttachment attachment) async
|
BuildContext context,
|
||||||
{
|
InvenTreeAttachment attachment,
|
||||||
attachment.editForm(context, L10().editAttachment).then((result) => {
|
) async {
|
||||||
refresh(context)
|
attachment
|
||||||
});
|
.editForm(context, L10().editAttachment)
|
||||||
|
.then((result) => {refresh(context)});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Delete the specified attachment
|
* Delete the specified attachment
|
||||||
*/
|
*/
|
||||||
Future<void> deleteAttachment(BuildContext context, InvenTreeAttachment attachment) async {
|
Future<void> deleteAttachment(
|
||||||
|
BuildContext context,
|
||||||
|
InvenTreeAttachment attachment,
|
||||||
|
) async {
|
||||||
final bool result = await attachment.delete();
|
final bool result = await attachment.delete();
|
||||||
|
|
||||||
showSnackIcon(
|
showSnackIcon(
|
||||||
result ? L10().deleteSuccess : L10().deleteFailed,
|
result ? L10().deleteSuccess : L10().deleteFailed,
|
||||||
success: result
|
success: result,
|
||||||
);
|
);
|
||||||
|
|
||||||
refresh(context);
|
refresh(context);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display an option context menu for the selected attachment
|
* Display an option context menu for the selected attachment
|
||||||
*/
|
*/
|
||||||
Future<void> showOptionsMenu(BuildContext context, InvenTreeAttachment attachment) async {
|
Future<void> showOptionsMenu(
|
||||||
|
BuildContext context,
|
||||||
|
InvenTreeAttachment attachment,
|
||||||
|
) async {
|
||||||
OneContext().showDialog(
|
OneContext().showDialog(
|
||||||
builder: (BuildContext ctx) {
|
builder: (BuildContext ctx) {
|
||||||
return SimpleDialog(
|
return SimpleDialog(
|
||||||
@ -144,7 +147,7 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
|
|||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text(L10().edit),
|
title: Text(L10().edit),
|
||||||
leading: Icon(TablerIcons.edit),
|
leading: Icon(TablerIcons.edit),
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
SimpleDialogOption(
|
SimpleDialogOption(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
@ -154,29 +157,27 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
|
|||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text(L10().delete),
|
title: Text(L10().delete),
|
||||||
leading: Icon(TablerIcons.trash, color: COLOR_DANGER),
|
leading: Icon(TablerIcons.trash, color: COLOR_DANGER),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
]
|
],
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> request(BuildContext context) async {
|
Future<void> request(BuildContext context) async {
|
||||||
|
|
||||||
Map<String, String> filters = {};
|
Map<String, String> filters = {};
|
||||||
|
|
||||||
if (InvenTreeAPI().supportsModernAttachments) {
|
if (InvenTreeAPI().supportsModernAttachments) {
|
||||||
filters["model_type"] = widget.attachmentClass.REF_MODEL_TYPE;
|
filters["model_type"] = widget.attachmentClass.REF_MODEL_TYPE;
|
||||||
filters["model_id"] = widget.modelId.toString();
|
filters["model_id"] = widget.modelId.toString();
|
||||||
} else {
|
} else {
|
||||||
filters[widget.attachmentClass.REFERENCE_FIELD] = widget.modelId.toString();
|
filters[widget.attachmentClass.REFERENCE_FIELD] = widget.modelId
|
||||||
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
await widget.attachmentClass.list(
|
await widget.attachmentClass.list(filters: filters).then((var results) {
|
||||||
filters: filters
|
|
||||||
).then((var results) {
|
|
||||||
attachments.clear();
|
attachments.clear();
|
||||||
|
|
||||||
for (var result in results) {
|
for (var result in results) {
|
||||||
@ -186,20 +187,18 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setState(() {
|
setState(() {});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Widget> getTiles(BuildContext context) {
|
List<Widget> getTiles(BuildContext context) {
|
||||||
|
|
||||||
List<Widget> tiles = [];
|
List<Widget> tiles = [];
|
||||||
|
|
||||||
// An "attachment" can either be a file, or a URL
|
// An "attachment" can either be a file, or a URL
|
||||||
for (var attachment in attachments) {
|
for (var attachment in attachments) {
|
||||||
|
|
||||||
if (attachment.filename.isNotEmpty) {
|
if (attachment.filename.isNotEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(attachment.filename),
|
title: Text(attachment.filename),
|
||||||
subtitle: Text(attachment.comment),
|
subtitle: Text(attachment.comment),
|
||||||
leading: Icon(attachment.icon, color: COLOR_ACTION),
|
leading: Icon(attachment.icon, color: COLOR_ACTION),
|
||||||
@ -211,11 +210,11 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
|
|||||||
onLongPress: () {
|
onLongPress: () {
|
||||||
showOptionsMenu(context, attachment);
|
showOptionsMenu(context, attachment);
|
||||||
},
|
},
|
||||||
));
|
),
|
||||||
}
|
);
|
||||||
|
} else if (attachment.link.isNotEmpty) {
|
||||||
else if (attachment.link.isNotEmpty) {
|
tiles.add(
|
||||||
tiles.add(ListTile(
|
ListTile(
|
||||||
title: Text(attachment.link),
|
title: Text(attachment.link),
|
||||||
subtitle: Text(attachment.comment),
|
subtitle: Text(attachment.comment),
|
||||||
leading: Icon(TablerIcons.link, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.link, color: COLOR_ACTION),
|
||||||
@ -228,15 +227,18 @@ class _AttachmentWidgetState extends RefreshableState<AttachmentWidget> {
|
|||||||
onLongPress: () {
|
onLongPress: () {
|
||||||
showOptionsMenu(context, attachment);
|
showOptionsMenu(context, attachment);
|
||||||
},
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tiles.isEmpty) {
|
if (tiles.isEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
leading: Icon(TablerIcons.file_x, color: COLOR_WARNING),
|
leading: Icon(TablerIcons.file_x, color: COLOR_WARNING),
|
||||||
title: Text(L10().attachmentNone),
|
title: Text(L10().attachmentNone),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
|
@ -6,7 +6,6 @@ import "package:flutter/material.dart";
|
|||||||
* Long-pressing on this will return the user to the home screen
|
* Long-pressing on this will return the user to the home screen
|
||||||
*/
|
*/
|
||||||
Widget backButton(BuildContext context, GlobalKey<ScaffoldState> key) {
|
Widget backButton(BuildContext context, GlobalKey<ScaffoldState> key) {
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onLongPress: () {
|
onLongPress: () {
|
||||||
// Display the menu
|
// Display the menu
|
||||||
|
@ -16,24 +16,19 @@ import "package:inventree/widget/refreshable_state.dart";
|
|||||||
import "package:inventree/widget/snacks.dart";
|
import "package:inventree/widget/snacks.dart";
|
||||||
import "package:inventree/widget/company/supplier_part_list.dart";
|
import "package:inventree/widget/company/supplier_part_list.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Widget for displaying detail view of a single Company instance
|
* Widget for displaying detail view of a single Company instance
|
||||||
*/
|
*/
|
||||||
class CompanyDetailWidget extends StatefulWidget {
|
class CompanyDetailWidget extends StatefulWidget {
|
||||||
|
|
||||||
const CompanyDetailWidget(this.company, {Key? key}) : super(key: key);
|
const CompanyDetailWidget(this.company, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
final InvenTreeCompany company;
|
final InvenTreeCompany company;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_CompanyDetailState createState() => _CompanyDetailState();
|
_CompanyDetailState createState() => _CompanyDetailState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
||||||
|
|
||||||
_CompanyDetailState();
|
_CompanyDetailState();
|
||||||
|
|
||||||
int supplierPartCount = 0;
|
int supplierPartCount = 0;
|
||||||
@ -65,8 +60,8 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
|||||||
tooltip: L10().companyEdit,
|
tooltip: L10().companyEdit,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
editCompany(context);
|
editCompany(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,23 +73,27 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
|||||||
List<SpeedDialChild> actions = [];
|
List<SpeedDialChild> actions = [];
|
||||||
|
|
||||||
if (widget.company.isCustomer && InvenTreeSalesOrder().canCreate) {
|
if (widget.company.isCustomer && InvenTreeSalesOrder().canCreate) {
|
||||||
actions.add(SpeedDialChild(
|
actions.add(
|
||||||
|
SpeedDialChild(
|
||||||
child: Icon(TablerIcons.truck),
|
child: Icon(TablerIcons.truck),
|
||||||
label: L10().salesOrderCreate,
|
label: L10().salesOrderCreate,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
_createSalesOrder(context);
|
_createSalesOrder(context);
|
||||||
}
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.company.isSupplier && InvenTreePurchaseOrder().canCreate) {
|
if (widget.company.isSupplier && InvenTreePurchaseOrder().canCreate) {
|
||||||
actions.add(SpeedDialChild(
|
actions.add(
|
||||||
|
SpeedDialChild(
|
||||||
child: Icon(TablerIcons.shopping_cart),
|
child: Icon(TablerIcons.shopping_cart),
|
||||||
label: L10().purchaseOrderCreate,
|
label: L10().purchaseOrderCreate,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
_createPurchaseOrder(context);
|
_createPurchaseOrder(context);
|
||||||
}
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return actions;
|
return actions;
|
||||||
@ -119,7 +118,7 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
|||||||
var order = InvenTreeSalesOrder.fromJson(data);
|
var order = InvenTreeSalesOrder.fromJson(data);
|
||||||
order.goToDetailPage(context);
|
order.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +141,7 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
|||||||
var order = InvenTreePurchaseOrder.fromJson(data);
|
var order = InvenTreePurchaseOrder.fromJson(data);
|
||||||
order.goToDetailPage(context);
|
order.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,23 +155,27 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
outstandingPurchaseOrders = widget.company.isSupplier ?
|
outstandingPurchaseOrders = widget.company.isSupplier
|
||||||
await InvenTreePurchaseOrder().count(filters: {
|
? await InvenTreePurchaseOrder().count(
|
||||||
"supplier": widget.company.pk.toString(),
|
|
||||||
"outstanding": "true"
|
|
||||||
}) : 0;
|
|
||||||
|
|
||||||
outstandingSalesOrders = widget.company.isCustomer ?
|
|
||||||
await InvenTreeSalesOrder().count(filters: {
|
|
||||||
"customer": widget.company.pk.toString(),
|
|
||||||
"outstanding": "true"
|
|
||||||
}) : 0;
|
|
||||||
|
|
||||||
InvenTreeSupplierPart().count(
|
|
||||||
filters: {
|
filters: {
|
||||||
"supplier": widget.company.pk.toString()
|
"supplier": widget.company.pk.toString(),
|
||||||
}
|
"outstanding": "true",
|
||||||
).then((value) {
|
},
|
||||||
|
)
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
outstandingSalesOrders = widget.company.isCustomer
|
||||||
|
? await InvenTreeSalesOrder().count(
|
||||||
|
filters: {
|
||||||
|
"customer": widget.company.pk.toString(),
|
||||||
|
"outstanding": "true",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
InvenTreeSupplierPart()
|
||||||
|
.count(filters: {"supplier": widget.company.pk.toString()})
|
||||||
|
.then((value) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
supplierPartCount = value;
|
supplierPartCount = value;
|
||||||
@ -180,8 +183,9 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
InvenTreeCompanyAttachment().countAttachments(widget.company.pk)
|
InvenTreeCompanyAttachment().countAttachments(widget.company.pk).then((
|
||||||
.then((value) {
|
value,
|
||||||
|
) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
attachmentCount = value;
|
attachmentCount = value;
|
||||||
@ -191,14 +195,13 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> editCompany(BuildContext context) async {
|
Future<void> editCompany(BuildContext context) async {
|
||||||
|
|
||||||
widget.company.editForm(
|
widget.company.editForm(
|
||||||
context,
|
context,
|
||||||
L10().companyEdit,
|
L10().companyEdit,
|
||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
showSnackIcon(L10().companyUpdated, success: true);
|
showSnackIcon(L10().companyUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,87 +210,86 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
|||||||
*/
|
*/
|
||||||
@override
|
@override
|
||||||
List<Widget> getTiles(BuildContext context) {
|
List<Widget> getTiles(BuildContext context) {
|
||||||
|
|
||||||
List<Widget> tiles = [];
|
List<Widget> tiles = [];
|
||||||
|
|
||||||
bool sep = false;
|
bool sep = false;
|
||||||
|
|
||||||
tiles.add(Card(
|
tiles.add(
|
||||||
|
Card(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text("${widget.company.name}"),
|
title: Text("${widget.company.name}"),
|
||||||
subtitle: Text("${widget.company.description}"),
|
subtitle: Text("${widget.company.description}"),
|
||||||
leading: InvenTreeAPI().getThumbnail(widget.company.image),
|
leading: InvenTreeAPI().getThumbnail(widget.company.image),
|
||||||
),
|
),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
|
|
||||||
if (!widget.company.active) {
|
if (!widget.company.active) {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(
|
title: Text(L10().inactive, style: TextStyle(color: COLOR_DANGER)),
|
||||||
L10().inactive,
|
|
||||||
style: TextStyle(
|
|
||||||
color: COLOR_DANGER
|
|
||||||
)
|
|
||||||
),
|
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
L10().inactiveCompany,
|
L10().inactiveCompany,
|
||||||
style: TextStyle(
|
style: TextStyle(color: COLOR_DANGER),
|
||||||
color: COLOR_DANGER
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
leading: Icon(
|
leading: Icon(TablerIcons.exclamation_circle, color: COLOR_DANGER),
|
||||||
TablerIcons.exclamation_circle,
|
|
||||||
color: COLOR_DANGER
|
|
||||||
),
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.company.website.isNotEmpty) {
|
if (widget.company.website.isNotEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text("${widget.company.website}"),
|
title: Text("${widget.company.website}"),
|
||||||
leading: Icon(TablerIcons.globe, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.globe, color: COLOR_ACTION),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
openLink(widget.company.website);
|
openLink(widget.company.website);
|
||||||
},
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
|
|
||||||
sep = true;
|
sep = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.company.email.isNotEmpty) {
|
if (widget.company.email.isNotEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text("${widget.company.email}"),
|
title: Text("${widget.company.email}"),
|
||||||
leading: Icon(TablerIcons.at, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.at, color: COLOR_ACTION),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
openLink("mailto:${widget.company.email}");
|
openLink("mailto:${widget.company.email}");
|
||||||
},
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
|
|
||||||
sep = true;
|
sep = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.company.phone.isNotEmpty) {
|
if (widget.company.phone.isNotEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text("${widget.company.phone}"),
|
title: Text("${widget.company.phone}"),
|
||||||
leading: Icon(TablerIcons.phone, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.phone, color: COLOR_ACTION),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
openLink("tel:${widget.company.phone}");
|
openLink("tel:${widget.company.phone}");
|
||||||
},
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
|
|
||||||
sep = true;
|
sep = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// External link
|
// External link
|
||||||
if (widget.company.link.isNotEmpty) {
|
if (widget.company.link.isNotEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text("${widget.company.link}"),
|
title: Text("${widget.company.link}"),
|
||||||
leading: Icon(TablerIcons.link, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.link, color: COLOR_ACTION),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
widget.company.openLink();
|
widget.company.openLink();
|
||||||
},
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
|
|
||||||
sep = true;
|
sep = true;
|
||||||
}
|
}
|
||||||
@ -297,7 +299,6 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (widget.company.isSupplier) {
|
if (widget.company.isSupplier) {
|
||||||
|
|
||||||
if (supplierPartCount > 0) {
|
if (supplierPartCount > 0) {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
@ -309,12 +310,12 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
|||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => SupplierPartList({
|
builder: (context) => SupplierPartList({
|
||||||
"supplier": widget.company.pk.toString()
|
"supplier": widget.company.pk.toString(),
|
||||||
})
|
}),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,14 +329,12 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
|||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => PurchaseOrderListWidget(
|
builder: (context) => PurchaseOrderListWidget(
|
||||||
filters: {
|
filters: {"supplier": "${widget.company.pk}"},
|
||||||
"supplier": "${widget.company.pk}"
|
),
|
||||||
}
|
),
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: Display "supplied parts" count (click through to list of supplier parts)
|
// TODO: Display "supplied parts" count (click through to list of supplier parts)
|
||||||
@ -365,27 +364,27 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
|||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => SalesOrderListWidget(
|
builder: (context) => SalesOrderListWidget(
|
||||||
filters: {
|
filters: {"customer": widget.company.pk.toString()},
|
||||||
"customer": widget.company.pk.toString()
|
),
|
||||||
}
|
),
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.company.notes.isNotEmpty) {
|
if (widget.company.notes.isNotEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().notes),
|
title: Text(L10().notes),
|
||||||
leading: Icon(TablerIcons.note),
|
leading: Icon(TablerIcons.note),
|
||||||
onTap: null,
|
onTap: null,
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tiles.add(
|
||||||
tiles.add(ListTile(
|
ListTile(
|
||||||
title: Text(L10().attachments),
|
title: Text(L10().attachments),
|
||||||
leading: Icon(TablerIcons.file, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.file, color: COLOR_ACTION),
|
||||||
trailing: attachmentCount > 0 ? Text(attachmentCount.toString()) : null,
|
trailing: attachmentCount > 0 ? Text(attachmentCount.toString()) : null,
|
||||||
@ -397,14 +396,14 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
|||||||
InvenTreeCompanyAttachment(),
|
InvenTreeCompanyAttachment(),
|
||||||
widget.company.pk,
|
widget.company.pk,
|
||||||
widget.company.name,
|
widget.company.name,
|
||||||
InvenTreeCompany().canEdit
|
InvenTreeCompany().canEdit,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter_speed_dial/flutter_speed_dial.dart";
|
import "package:flutter_speed_dial/flutter_speed_dial.dart";
|
||||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||||
@ -12,13 +11,12 @@ import "package:inventree/inventree/model.dart";
|
|||||||
import "package:inventree/widget/paginator.dart";
|
import "package:inventree/widget/paginator.dart";
|
||||||
import "package:inventree/widget/refreshable_state.dart";
|
import "package:inventree/widget/refreshable_state.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Widget for displaying a filterable list of Company instances
|
* Widget for displaying a filterable list of Company instances
|
||||||
*/
|
*/
|
||||||
class CompanyListWidget extends StatefulWidget {
|
class CompanyListWidget extends StatefulWidget {
|
||||||
|
const CompanyListWidget(this.title, this.filters, {Key? key})
|
||||||
const CompanyListWidget(this.title, this.filters, {Key? key}) : super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
|
|
||||||
@ -28,16 +26,13 @@ class CompanyListWidget extends StatefulWidget {
|
|||||||
_CompanyListWidgetState createState() => _CompanyListWidgetState();
|
_CompanyListWidgetState createState() => _CompanyListWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _CompanyListWidgetState extends RefreshableState<CompanyListWidget> {
|
class _CompanyListWidgetState extends RefreshableState<CompanyListWidget> {
|
||||||
|
|
||||||
_CompanyListWidgetState();
|
_CompanyListWidgetState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getAppBarTitle() => widget.title;
|
String getAppBarTitle() => widget.title;
|
||||||
|
|
||||||
Future<void> _addCompany(BuildContext context) async {
|
Future<void> _addCompany(BuildContext context) async {
|
||||||
|
|
||||||
InvenTreeCompany().createForm(
|
InvenTreeCompany().createForm(
|
||||||
context,
|
context,
|
||||||
L10().companyAdd,
|
L10().companyAdd,
|
||||||
@ -49,7 +44,7 @@ class _CompanyListWidgetState extends RefreshableState<CompanyListWidget> {
|
|||||||
var company = InvenTreeCompany.fromJson(data);
|
var company = InvenTreeCompany.fromJson(data);
|
||||||
company.goToDetailPage(context);
|
company.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,8 +59,8 @@ class _CompanyListWidgetState extends RefreshableState<CompanyListWidget> {
|
|||||||
label: L10().companyAdd,
|
label: L10().companyAdd,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_addCompany(context);
|
_addCompany(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,12 +71,11 @@ class _CompanyListWidgetState extends RefreshableState<CompanyListWidget> {
|
|||||||
Widget getBody(BuildContext context) {
|
Widget getBody(BuildContext context) {
|
||||||
return PaginatedCompanyList(widget.title, widget.filters);
|
return PaginatedCompanyList(widget.title, widget.filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class PaginatedCompanyList extends PaginatedSearchWidget {
|
class PaginatedCompanyList extends PaginatedSearchWidget {
|
||||||
|
const PaginatedCompanyList(this.companyTitle, Map<String, String> filters)
|
||||||
const PaginatedCompanyList(this.companyTitle, Map<String, String> filters) : super(filters: filters);
|
: super(filters: filters);
|
||||||
|
|
||||||
final String companyTitle;
|
final String companyTitle;
|
||||||
|
|
||||||
@ -93,12 +87,10 @@ class PaginatedCompanyList extends PaginatedSearchWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _CompanyListState extends PaginatedSearchState<PaginatedCompanyList> {
|
class _CompanyListState extends PaginatedSearchState<PaginatedCompanyList> {
|
||||||
|
|
||||||
_CompanyListState() : super();
|
_CompanyListState() : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, Map<String, dynamic>> get filterOptions {
|
Map<String, Map<String, dynamic>> get filterOptions {
|
||||||
|
|
||||||
Map<String, Map<String, dynamic>> filters = {};
|
Map<String, Map<String, dynamic>> filters = {};
|
||||||
|
|
||||||
if (InvenTreeAPI().supportsCompanyActiveStatus) {
|
if (InvenTreeAPI().supportsCompanyActiveStatus) {
|
||||||
@ -113,16 +105,22 @@ class _CompanyListState extends PaginatedSearchState<PaginatedCompanyList> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
|
int limit,
|
||||||
final page = await InvenTreeCompany().listPaginated(limit, offset, filters: params);
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
|
final page = await InvenTreeCompany().listPaginated(
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
filters: params,
|
||||||
|
);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||||
|
|
||||||
InvenTreeCompany company = model as InvenTreeCompany;
|
InvenTreeCompany company = model as InvenTreeCompany;
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter_speed_dial/flutter_speed_dial.dart";
|
import "package:flutter_speed_dial/flutter_speed_dial.dart";
|
||||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||||
@ -19,19 +18,18 @@ import "package:url_launcher/url_launcher.dart";
|
|||||||
* Detail widget for viewing a single ManufacturerPart instance
|
* Detail widget for viewing a single ManufacturerPart instance
|
||||||
*/
|
*/
|
||||||
class ManufacturerPartDetailWidget extends StatefulWidget {
|
class ManufacturerPartDetailWidget extends StatefulWidget {
|
||||||
|
|
||||||
const ManufacturerPartDetailWidget(this.manufacturerPart, {Key? key})
|
const ManufacturerPartDetailWidget(this.manufacturerPart, {Key? key})
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
final InvenTreeManufacturerPart manufacturerPart;
|
final InvenTreeManufacturerPart manufacturerPart;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_ManufacturerPartDisplayState createState() => _ManufacturerPartDisplayState();
|
_ManufacturerPartDisplayState createState() =>
|
||||||
|
_ManufacturerPartDisplayState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _ManufacturerPartDisplayState
|
||||||
class _ManufacturerPartDisplayState extends RefreshableState<ManufacturerPartDetailWidget> {
|
extends RefreshableState<ManufacturerPartDetailWidget> {
|
||||||
|
|
||||||
_ManufacturerPartDisplayState();
|
_ManufacturerPartDisplayState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -39,7 +37,8 @@ class _ManufacturerPartDisplayState extends RefreshableState<ManufacturerPartDet
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> request(BuildContext context) async {
|
Future<void> request(BuildContext context) async {
|
||||||
final bool result = widget.manufacturerPart.pk > 0 &&
|
final bool result =
|
||||||
|
widget.manufacturerPart.pk > 0 &&
|
||||||
await widget.manufacturerPart.reload();
|
await widget.manufacturerPart.reload();
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
@ -54,7 +53,7 @@ class _ManufacturerPartDisplayState extends RefreshableState<ManufacturerPartDet
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
showSnackIcon(L10().itemUpdated, success: true);
|
showSnackIcon(L10().itemUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,8 +77,8 @@ class _ManufacturerPartDisplayState extends RefreshableState<ManufacturerPartDet
|
|||||||
tooltip: L10().edit,
|
tooltip: L10().edit,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
editManufacturerPart(context);
|
editManufacturerPart(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,17 +103,21 @@ class _ManufacturerPartDisplayState extends RefreshableState<ManufacturerPartDet
|
|||||||
title: Text(L10().internalPart),
|
title: Text(L10().internalPart),
|
||||||
subtitle: Text(widget.manufacturerPart.partName),
|
subtitle: Text(widget.manufacturerPart.partName),
|
||||||
leading: Icon(TablerIcons.box, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.box, color: COLOR_ACTION),
|
||||||
trailing: InvenTreeAPI().getThumbnail(widget.manufacturerPart.partImage),
|
trailing: InvenTreeAPI().getThumbnail(
|
||||||
|
widget.manufacturerPart.partImage,
|
||||||
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
final part = await InvenTreePart().get(widget.manufacturerPart.partId);
|
final part = await InvenTreePart().get(
|
||||||
|
widget.manufacturerPart.partId,
|
||||||
|
);
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
|
|
||||||
if (part is InvenTreePart) {
|
if (part is InvenTreePart) {
|
||||||
part.goToDetailPage(context);
|
part.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Manufacturer details
|
// Manufacturer details
|
||||||
@ -123,17 +126,21 @@ class _ManufacturerPartDisplayState extends RefreshableState<ManufacturerPartDet
|
|||||||
title: Text(L10().manufacturer),
|
title: Text(L10().manufacturer),
|
||||||
subtitle: Text(widget.manufacturerPart.manufacturerName),
|
subtitle: Text(widget.manufacturerPart.manufacturerName),
|
||||||
leading: Icon(TablerIcons.building_factory_2, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.building_factory_2, color: COLOR_ACTION),
|
||||||
trailing: InvenTreeAPI().getThumbnail(widget.manufacturerPart.manufacturerImage),
|
trailing: InvenTreeAPI().getThumbnail(
|
||||||
|
widget.manufacturerPart.manufacturerImage,
|
||||||
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
var supplier = await InvenTreeCompany().get(widget.manufacturerPart.manufacturerId);
|
var supplier = await InvenTreeCompany().get(
|
||||||
|
widget.manufacturerPart.manufacturerId,
|
||||||
|
);
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
|
|
||||||
if (supplier is InvenTreeCompany) {
|
if (supplier is InvenTreeCompany) {
|
||||||
supplier.goToDetailPage(context);
|
supplier.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// MPN (part number)
|
// MPN (part number)
|
||||||
@ -142,7 +149,7 @@ class _ManufacturerPartDisplayState extends RefreshableState<ManufacturerPartDet
|
|||||||
title: Text(L10().manufacturerPartNumber),
|
title: Text(L10().manufacturerPartNumber),
|
||||||
subtitle: Text(widget.manufacturerPart.MPN),
|
subtitle: Text(widget.manufacturerPart.MPN),
|
||||||
leading: Icon(TablerIcons.hash),
|
leading: Icon(TablerIcons.hash),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Description
|
// Description
|
||||||
@ -152,7 +159,7 @@ class _ManufacturerPartDisplayState extends RefreshableState<ManufacturerPartDet
|
|||||||
title: Text(L10().description),
|
title: Text(L10().description),
|
||||||
subtitle: Text(widget.manufacturerPart.description),
|
subtitle: Text(widget.manufacturerPart.description),
|
||||||
leading: Icon(TablerIcons.info_circle),
|
leading: Icon(TablerIcons.info_circle),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,11 +174,10 @@ class _ManufacturerPartDisplayState extends RefreshableState<ManufacturerPartDet
|
|||||||
await launchUrl(uri);
|
await launchUrl(uri);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,12 @@ import "package:inventree/widget/refreshable_state.dart";
|
|||||||
import "package:inventree/widget/snacks.dart";
|
import "package:inventree/widget/snacks.dart";
|
||||||
import "package:inventree/widget/company/manufacturer_part_detail.dart";
|
import "package:inventree/widget/company/manufacturer_part_detail.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Detail widget for viewing a single SupplierPart instance
|
* Detail widget for viewing a single SupplierPart instance
|
||||||
*/
|
*/
|
||||||
class SupplierPartDetailWidget extends StatefulWidget {
|
class SupplierPartDetailWidget extends StatefulWidget {
|
||||||
|
const SupplierPartDetailWidget(this.supplierPart, {Key? key})
|
||||||
const SupplierPartDetailWidget(this.supplierPart, {Key? key}) : super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
final InvenTreeSupplierPart supplierPart;
|
final InvenTreeSupplierPart supplierPart;
|
||||||
|
|
||||||
@ -31,9 +30,8 @@ class SupplierPartDetailWidget extends StatefulWidget {
|
|||||||
_SupplierPartDisplayState createState() => _SupplierPartDisplayState();
|
_SupplierPartDisplayState createState() => _SupplierPartDisplayState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _SupplierPartDisplayState
|
||||||
class _SupplierPartDisplayState extends RefreshableState<SupplierPartDetailWidget> {
|
extends RefreshableState<SupplierPartDetailWidget> {
|
||||||
|
|
||||||
_SupplierPartDisplayState();
|
_SupplierPartDisplayState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -49,7 +47,7 @@ class _SupplierPartDisplayState extends RefreshableState<SupplierPartDetailWidge
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
showSnackIcon(L10().supplierPartUpdated, success: true);
|
showSnackIcon(L10().supplierPartUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,11 +58,12 @@ class _SupplierPartDisplayState extends RefreshableState<SupplierPartDetailWidge
|
|||||||
if (widget.supplierPart.canEdit) {
|
if (widget.supplierPart.canEdit) {
|
||||||
actions.add(
|
actions.add(
|
||||||
customBarcodeAction(
|
customBarcodeAction(
|
||||||
context, this,
|
context,
|
||||||
|
this,
|
||||||
widget.supplierPart.customBarcode,
|
widget.supplierPart.customBarcode,
|
||||||
"supplierpart",
|
"supplierpart",
|
||||||
widget.supplierPart.pk
|
widget.supplierPart.pk,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,8 +81,8 @@ class _SupplierPartDisplayState extends RefreshableState<SupplierPartDetailWidge
|
|||||||
tooltip: L10().edit,
|
tooltip: L10().edit,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
editSupplierPart(context);
|
editSupplierPart(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +91,8 @@ class _SupplierPartDisplayState extends RefreshableState<SupplierPartDetailWidge
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> request(BuildContext context) async {
|
Future<void> request(BuildContext context) async {
|
||||||
final bool result = widget.supplierPart.pk > 0 && await widget.supplierPart.reload();
|
final bool result =
|
||||||
|
widget.supplierPart.pk > 0 && await widget.supplierPart.reload();
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
@ -127,29 +127,19 @@ class _SupplierPartDisplayState extends RefreshableState<SupplierPartDetailWidge
|
|||||||
part.goToDetailPage(context);
|
part.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!widget.supplierPart.active) {
|
if (!widget.supplierPart.active) {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(
|
title: Text(L10().inactive, style: TextStyle(color: COLOR_DANGER)),
|
||||||
L10().inactive,
|
|
||||||
style: TextStyle(
|
|
||||||
color: COLOR_DANGER
|
|
||||||
)
|
|
||||||
),
|
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
L10().inactiveDetail,
|
L10().inactiveDetail,
|
||||||
style: TextStyle(
|
style: TextStyle(color: COLOR_DANGER),
|
||||||
color: COLOR_DANGER
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
leading: Icon(
|
leading: Icon(TablerIcons.exclamation_circle, color: COLOR_DANGER),
|
||||||
TablerIcons.exclamation_circle,
|
|
||||||
color: COLOR_DANGER
|
|
||||||
),
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,17 +149,21 @@ class _SupplierPartDisplayState extends RefreshableState<SupplierPartDetailWidge
|
|||||||
title: Text(L10().supplier),
|
title: Text(L10().supplier),
|
||||||
subtitle: Text(widget.supplierPart.supplierName),
|
subtitle: Text(widget.supplierPart.supplierName),
|
||||||
leading: Icon(TablerIcons.building, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.building, color: COLOR_ACTION),
|
||||||
trailing: InvenTreeAPI().getThumbnail(widget.supplierPart.supplierImage),
|
trailing: InvenTreeAPI().getThumbnail(
|
||||||
|
widget.supplierPart.supplierImage,
|
||||||
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
var supplier = await InvenTreeCompany().get(widget.supplierPart.supplierId);
|
var supplier = await InvenTreeCompany().get(
|
||||||
|
widget.supplierPart.supplierId,
|
||||||
|
);
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
|
|
||||||
if (supplier is InvenTreeCompany) {
|
if (supplier is InvenTreeCompany) {
|
||||||
supplier.goToDetailPage(context);
|
supplier.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// SKU (part number)
|
// SKU (part number)
|
||||||
@ -178,7 +172,7 @@ class _SupplierPartDisplayState extends RefreshableState<SupplierPartDetailWidge
|
|||||||
title: Text(L10().supplierPartNumber),
|
title: Text(L10().supplierPartNumber),
|
||||||
subtitle: Text(widget.supplierPart.SKU),
|
subtitle: Text(widget.supplierPart.SKU),
|
||||||
leading: Icon(TablerIcons.hash),
|
leading: Icon(TablerIcons.hash),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Manufacturer information
|
// Manufacturer information
|
||||||
@ -188,17 +182,21 @@ class _SupplierPartDisplayState extends RefreshableState<SupplierPartDetailWidge
|
|||||||
title: Text(L10().manufacturer),
|
title: Text(L10().manufacturer),
|
||||||
subtitle: Text(widget.supplierPart.manufacturerName),
|
subtitle: Text(widget.supplierPart.manufacturerName),
|
||||||
leading: Icon(TablerIcons.building_factory_2, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.building_factory_2, color: COLOR_ACTION),
|
||||||
trailing: InvenTreeAPI().getThumbnail(widget.supplierPart.manufacturerImage),
|
trailing: InvenTreeAPI().getThumbnail(
|
||||||
|
widget.supplierPart.manufacturerImage,
|
||||||
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
var supplier = await InvenTreeCompany().get(widget.supplierPart.manufacturerId);
|
var supplier = await InvenTreeCompany().get(
|
||||||
|
widget.supplierPart.manufacturerId,
|
||||||
|
);
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
|
|
||||||
if (supplier is InvenTreeCompany) {
|
if (supplier is InvenTreeCompany) {
|
||||||
supplier.goToDetailPage(context);
|
supplier.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -208,28 +206,39 @@ class _SupplierPartDisplayState extends RefreshableState<SupplierPartDetailWidge
|
|||||||
leading: Icon(TablerIcons.hash, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.hash, color: COLOR_ACTION),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
var manufacturerPart = await InvenTreeManufacturerPart().get(widget.supplierPart.manufacturerPartId);
|
var manufacturerPart = await InvenTreeManufacturerPart().get(
|
||||||
|
widget.supplierPart.manufacturerPartId,
|
||||||
|
);
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
|
|
||||||
if (manufacturerPart is InvenTreeManufacturerPart) {
|
if (manufacturerPart is InvenTreeManufacturerPart) {
|
||||||
Navigator.push(context, MaterialPageRoute(
|
Navigator.push(
|
||||||
builder: (context) => ManufacturerPartDetailWidget(manufacturerPart)
|
context,
|
||||||
));
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
ManufacturerPartDetailWidget(manufacturerPart),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Packaging
|
// Packaging
|
||||||
if (widget.supplierPart.packaging.isNotEmpty || widget.supplierPart.pack_quantity.isNotEmpty) {
|
if (widget.supplierPart.packaging.isNotEmpty ||
|
||||||
|
widget.supplierPart.pack_quantity.isNotEmpty) {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().packaging),
|
title: Text(L10().packaging),
|
||||||
subtitle: widget.supplierPart.packaging.isNotEmpty ? Text(widget.supplierPart.packaging) : null,
|
subtitle: widget.supplierPart.packaging.isNotEmpty
|
||||||
|
? Text(widget.supplierPart.packaging)
|
||||||
|
: null,
|
||||||
leading: Icon(TablerIcons.package),
|
leading: Icon(TablerIcons.package),
|
||||||
trailing: widget.supplierPart.pack_quantity.isNotEmpty ? Text(widget.supplierPart.pack_quantity) : null,
|
trailing: widget.supplierPart.pack_quantity.isNotEmpty
|
||||||
)
|
? Text(widget.supplierPart.pack_quantity)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +253,7 @@ class _SupplierPartDisplayState extends RefreshableState<SupplierPartDetailWidge
|
|||||||
await launchUrl(uri);
|
await launchUrl(uri);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,11 +262,10 @@ class _SupplierPartDisplayState extends RefreshableState<SupplierPartDetailWidge
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(widget.supplierPart.note),
|
title: Text(widget.supplierPart.note),
|
||||||
leading: Icon(TablerIcons.pencil),
|
leading: Icon(TablerIcons.pencil),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -10,12 +10,10 @@ import "package:inventree/widget/paginator.dart";
|
|||||||
import "package:inventree/widget/refreshable_state.dart";
|
import "package:inventree/widget/refreshable_state.dart";
|
||||||
import "package:inventree/widget/company/supplier_part_detail.dart";
|
import "package:inventree/widget/company/supplier_part_detail.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Widget for displaying a list of Supplier Part instances
|
* Widget for displaying a list of Supplier Part instances
|
||||||
*/
|
*/
|
||||||
class SupplierPartList extends StatefulWidget {
|
class SupplierPartList extends StatefulWidget {
|
||||||
|
|
||||||
const SupplierPartList(this.filters);
|
const SupplierPartList(this.filters);
|
||||||
|
|
||||||
final Map<String, String> filters;
|
final Map<String, String> filters;
|
||||||
@ -24,9 +22,7 @@ class SupplierPartList extends StatefulWidget {
|
|||||||
_SupplierPartListState createState() => _SupplierPartListState();
|
_SupplierPartListState createState() => _SupplierPartListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _SupplierPartListState extends RefreshableState<SupplierPartList> {
|
class _SupplierPartListState extends RefreshableState<SupplierPartList> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getAppBarTitle() => L10().supplierParts;
|
String getAppBarTitle() => L10().supplierParts;
|
||||||
|
|
||||||
@ -34,25 +30,22 @@ class _SupplierPartListState extends RefreshableState<SupplierPartList> {
|
|||||||
Widget getBody(BuildContext context) {
|
Widget getBody(BuildContext context) {
|
||||||
return PaginatedSupplierPartList(widget.filters);
|
return PaginatedSupplierPartList(widget.filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PaginatedSupplierPartList extends PaginatedSearchWidget {
|
class PaginatedSupplierPartList extends PaginatedSearchWidget {
|
||||||
|
const PaginatedSupplierPartList(Map<String, String> filters)
|
||||||
const PaginatedSupplierPartList(Map<String, String> filters) : super(filters: filters);
|
: super(filters: filters);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get searchTitle => L10().supplierParts;
|
String get searchTitle => L10().supplierParts;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PaginatedSupplierPartListState createState() => _PaginatedSupplierPartListState();
|
_PaginatedSupplierPartListState createState() =>
|
||||||
|
_PaginatedSupplierPartListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _PaginatedSupplierPartListState
|
||||||
class _PaginatedSupplierPartListState extends PaginatedSearchState<PaginatedSupplierPartList> {
|
extends PaginatedSearchState<PaginatedSupplierPartList> {
|
||||||
|
|
||||||
_PaginatedSupplierPartListState() : super();
|
_PaginatedSupplierPartListState() : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -63,7 +56,6 @@ class _PaginatedSupplierPartListState extends PaginatedSearchState<PaginatedSupp
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, Map<String, dynamic>> get filterOptions {
|
Map<String, Map<String, dynamic>> get filterOptions {
|
||||||
|
|
||||||
Map<String, Map<String, dynamic>> filters = {};
|
Map<String, Map<String, dynamic>> filters = {};
|
||||||
|
|
||||||
if (InvenTreeAPI().supportsCompanyActiveStatus) {
|
if (InvenTreeAPI().supportsCompanyActiveStatus) {
|
||||||
@ -78,8 +70,16 @@ class _PaginatedSupplierPartListState extends PaginatedSearchState<PaginatedSupp
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
final page = await InvenTreeSupplierPart().listPaginated(limit, offset, filters: params);
|
int limit,
|
||||||
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
|
final page = await InvenTreeSupplierPart().listPaginated(
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
filters: params,
|
||||||
|
);
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,8 +96,8 @@ class _PaginatedSupplierPartListState extends PaginatedSearchState<PaginatedSupp
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => SupplierPartDetailWidget(supplierPart)
|
builder: (context) => SupplierPartDetailWidget(supplierPart),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -9,12 +9,14 @@ import "package:inventree/l10.dart";
|
|||||||
import "package:inventree/preferences.dart";
|
import "package:inventree/preferences.dart";
|
||||||
import "package:inventree/widget/snacks.dart";
|
import "package:inventree/widget/snacks.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Launch a dialog allowing the user to select from a list of options
|
* Launch a dialog allowing the user to select from a list of options
|
||||||
*/
|
*/
|
||||||
Future<void> choiceDialog(String title, List<Widget> items, {Function? onSelected}) async {
|
Future<void> choiceDialog(
|
||||||
|
String title,
|
||||||
|
List<Widget> items, {
|
||||||
|
Function? onSelected,
|
||||||
|
}) async {
|
||||||
List<Widget> choices = [];
|
List<Widget> choices = [];
|
||||||
|
|
||||||
for (int idx = 0; idx < items.length; idx++) {
|
for (int idx = 0; idx < items.length; idx++) {
|
||||||
@ -27,7 +29,7 @@ Future<void> choiceDialog(String title, List<Widget> items, {Function? onSelecte
|
|||||||
onSelected(idx);
|
onSelected(idx);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,31 +41,33 @@ Future<void> choiceDialog(String title, List<Widget> items, {Function? onSelecte
|
|||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: Text(title),
|
title: Text(title),
|
||||||
content: SingleChildScrollView(
|
content: SingleChildScrollView(child: Column(children: choices)),
|
||||||
child: Column(
|
|
||||||
children: choices,
|
|
||||||
)
|
|
||||||
),
|
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
child: Text(L10().cancel),
|
child: Text(L10().cancel),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display a "confirmation" dialog allowing the user to accept or reject an action
|
* Display a "confirmation" dialog allowing the user to accept or reject an action
|
||||||
*/
|
*/
|
||||||
Future<void> confirmationDialog(String title, String text, {Color? color, IconData icon = TablerIcons.help_circle, String? acceptText, String? rejectText, Function? onAccept, Function? onReject}) async {
|
Future<void> confirmationDialog(
|
||||||
|
String title,
|
||||||
|
String text, {
|
||||||
|
Color? color,
|
||||||
|
IconData icon = TablerIcons.help_circle,
|
||||||
|
String? acceptText,
|
||||||
|
String? rejectText,
|
||||||
|
Function? onAccept,
|
||||||
|
Function? onReject,
|
||||||
|
}) async {
|
||||||
String _accept = acceptText ?? L10().ok;
|
String _accept = acceptText ?? L10().ok;
|
||||||
String _reject = rejectText ?? L10().cancel;
|
String _reject = rejectText ?? L10().cancel;
|
||||||
|
|
||||||
@ -90,7 +94,7 @@ Future<void> confirmationDialog(String title, String text, {Color? color, IconDa
|
|||||||
if (onReject != null) {
|
if (onReject != null) {
|
||||||
onReject();
|
onReject();
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
child: Text(_accept),
|
child: Text(_accept),
|
||||||
@ -102,13 +106,12 @@ Future<void> confirmationDialog(String title, String text, {Color? color, IconDa
|
|||||||
onAccept();
|
onAccept();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
]
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Construct an error dialog showing information to the user
|
* Construct an error dialog showing information to the user
|
||||||
@ -117,24 +120,23 @@ Future<void> confirmationDialog(String title, String text, {Color? color, IconDa
|
|||||||
* @description = Simple string description of error
|
* @description = Simple string description of error
|
||||||
* @data = Error response (e.g from server)
|
* @data = Error response (e.g from server)
|
||||||
*/
|
*/
|
||||||
Future<void> showErrorDialog(String title, {String description = "", APIResponse? response, IconData icon = TablerIcons.exclamation_circle, Function? onDismissed}) async {
|
Future<void> showErrorDialog(
|
||||||
|
String title, {
|
||||||
|
String description = "",
|
||||||
|
APIResponse? response,
|
||||||
|
IconData icon = TablerIcons.exclamation_circle,
|
||||||
|
Function? onDismissed,
|
||||||
|
}) async {
|
||||||
List<Widget> children = [];
|
List<Widget> children = [];
|
||||||
|
|
||||||
if (description.isNotEmpty) {
|
if (description.isNotEmpty) {
|
||||||
children.add(
|
children.add(ListTile(title: Text(description)));
|
||||||
ListTile(
|
|
||||||
title: Text(description),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else if (response != null) {
|
} else if (response != null) {
|
||||||
// Look for extra error information in the provided APIResponse object
|
// Look for extra error information in the provided APIResponse object
|
||||||
switch (response.statusCode) {
|
switch (response.statusCode) {
|
||||||
case 400: // Bad request (typically bad input)
|
case 400: // Bad request (typically bad input)
|
||||||
if (response.data is Map<String, dynamic>) {
|
if (response.data is Map<String, dynamic>) {
|
||||||
|
|
||||||
for (String field in response.asMap().keys) {
|
for (String field in response.asMap().keys) {
|
||||||
|
|
||||||
dynamic error = response.data[field];
|
dynamic error = response.data[field];
|
||||||
|
|
||||||
if (error is List) {
|
if (error is List) {
|
||||||
@ -143,7 +145,7 @@ Future<void> showErrorDialog(String title, {String description = "", APIResponse
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(field),
|
title: Text(field),
|
||||||
subtitle: Text(error[ii].toString()),
|
subtitle: Text(error[ii].toString()),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -151,7 +153,7 @@ Future<void> showErrorDialog(String title, {String description = "", APIResponse
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(field),
|
title: Text(field),
|
||||||
subtitle: Text(response.data[field].toString()),
|
subtitle: Text(response.data[field].toString()),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,8 +161,8 @@ Future<void> showErrorDialog(String title, {String description = "", APIResponse
|
|||||||
children.add(
|
children.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().responseInvalid),
|
title: Text(L10().responseInvalid),
|
||||||
subtitle: Text(response.data.toString())
|
subtitle: Text(response.data.toString()),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -169,16 +171,15 @@ Future<void> showErrorDialog(String title, {String description = "", APIResponse
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().statusCode),
|
title: Text(L10().statusCode),
|
||||||
subtitle: Text(response.statusCode.toString()),
|
subtitle: Text(response.statusCode.toString()),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
children.add(
|
children.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().responseData),
|
title: Text(L10().responseData),
|
||||||
subtitle: Text(response.data.toString()),
|
subtitle: Text(response.data.toString()),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,15 +187,14 @@ Future<void> showErrorDialog(String title, {String description = "", APIResponse
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
OneContext().showDialog(
|
OneContext()
|
||||||
|
.showDialog(
|
||||||
builder: (context) => SimpleDialog(
|
builder: (context) => SimpleDialog(
|
||||||
title: ListTile(
|
title: ListTile(title: Text(title), leading: Icon(icon)),
|
||||||
title: Text(title),
|
children: children,
|
||||||
leading: Icon(icon),
|
|
||||||
),
|
),
|
||||||
children: children
|
|
||||||
)
|
)
|
||||||
).then((value) {
|
.then((value) {
|
||||||
if (onDismissed != null) {
|
if (onDismissed != null) {
|
||||||
onDismissed();
|
onDismissed();
|
||||||
}
|
}
|
||||||
@ -204,8 +204,11 @@ Future<void> showErrorDialog(String title, {String description = "", APIResponse
|
|||||||
/*
|
/*
|
||||||
* Display a message indicating the nature of a server / API error
|
* Display a message indicating the nature of a server / API error
|
||||||
*/
|
*/
|
||||||
Future<void> showServerError(String url, String title, String description) async {
|
Future<void> showServerError(
|
||||||
|
String url,
|
||||||
|
String title,
|
||||||
|
String description,
|
||||||
|
) async {
|
||||||
if (!hasContext()) {
|
if (!hasContext()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -220,7 +223,9 @@ Future<void> showServerError(String url, String title, String description) async
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Play a sound
|
// Play a sound
|
||||||
final bool tones = await InvenTreeSettingsManager().getValue(INV_SOUNDS_SERVER, true) as bool;
|
final bool tones =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_SOUNDS_SERVER, true)
|
||||||
|
as bool;
|
||||||
|
|
||||||
if (tones) {
|
if (tones) {
|
||||||
playAudioFile("sounds/server_error.mp3");
|
playAudioFile("sounds/server_error.mp3");
|
||||||
@ -236,17 +241,20 @@ Future<void> showServerError(String url, String title, String description) async
|
|||||||
showErrorDialog(
|
showErrorDialog(
|
||||||
title,
|
title,
|
||||||
description: description,
|
description: description,
|
||||||
icon: TablerIcons.server
|
icon: TablerIcons.server,
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Displays an error indicating that the server returned an unexpected status code
|
* Displays an error indicating that the server returned an unexpected status code
|
||||||
*/
|
*/
|
||||||
Future<void> showStatusCodeError(String url, int status, {String details=""}) async {
|
Future<void> showStatusCodeError(
|
||||||
|
String url,
|
||||||
|
int status, {
|
||||||
|
String details = "",
|
||||||
|
}) async {
|
||||||
String msg = statusCodeToString(status);
|
String msg = statusCodeToString(status);
|
||||||
String extra = url + "\n" + "${L10().statusCode}: ${status}";
|
String extra = url + "\n" + "${L10().statusCode}: ${status}";
|
||||||
|
|
||||||
@ -255,14 +263,9 @@ Future<void> showStatusCodeError(String url, int status, {String details=""}) as
|
|||||||
extra += details;
|
extra += details;
|
||||||
}
|
}
|
||||||
|
|
||||||
showServerError(
|
showServerError(url, msg, extra);
|
||||||
url,
|
|
||||||
msg,
|
|
||||||
extra,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Provide a human-readable descriptor for a particular error code
|
* Provide a human-readable descriptor for a particular error code
|
||||||
*/
|
*/
|
||||||
@ -297,7 +300,6 @@ String statusCodeToString(int status) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Displays a message indicating that the server timed out on a certain request
|
* Displays a message indicating that the server timed out on a certain request
|
||||||
*/
|
*/
|
||||||
|
@ -16,12 +16,10 @@ import "package:inventree/widget/notifications.dart";
|
|||||||
import "package:inventree/widget/order/purchase_order_list.dart";
|
import "package:inventree/widget/order/purchase_order_list.dart";
|
||||||
import "package:inventree/widget/stock/location_display.dart";
|
import "package:inventree/widget/stock/location_display.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Custom "drawer" widget for the InvenTree app.
|
* Custom "drawer" widget for the InvenTree app.
|
||||||
*/
|
*/
|
||||||
class InvenTreeDrawer extends StatelessWidget {
|
class InvenTreeDrawer extends StatelessWidget {
|
||||||
|
|
||||||
const InvenTreeDrawer(this.context);
|
const InvenTreeDrawer(this.context);
|
||||||
|
|
||||||
final BuildContext context;
|
final BuildContext context;
|
||||||
@ -54,7 +52,7 @@ class InvenTreeDrawer extends StatelessWidget {
|
|||||||
if (_checkConnection()) {
|
if (_checkConnection()) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null))
|
MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,7 +64,7 @@ class InvenTreeDrawer extends StatelessWidget {
|
|||||||
if (_checkConnection()) {
|
if (_checkConnection()) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => LocationDisplayWidget(null))
|
MaterialPageRoute(builder: (context) => LocationDisplayWidget(null)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,8 +77,8 @@ class InvenTreeDrawer extends StatelessWidget {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => SalesOrderListWidget(filters: {})
|
builder: (context) => SalesOrderListWidget(filters: {}),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,8 +91,8 @@ class InvenTreeDrawer extends StatelessWidget {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => PurchaseOrderListWidget(filters: {})
|
builder: (context) => PurchaseOrderListWidget(filters: {}),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,15 +102,20 @@ class InvenTreeDrawer extends StatelessWidget {
|
|||||||
_closeDrawer();
|
_closeDrawer();
|
||||||
|
|
||||||
if (_checkConnection()) {
|
if (_checkConnection()) {
|
||||||
Navigator.push(context,
|
Navigator.push(
|
||||||
MaterialPageRoute(builder: (context) => NotificationWidget()));
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => NotificationWidget()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load settings widget
|
// Load settings widget
|
||||||
void _settings() {
|
void _settings() {
|
||||||
_closeDrawer();
|
_closeDrawer();
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeSettingsWidget()));
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => InvenTreeSettingsWidget()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct list of tiles to display in the "drawer" menu
|
// Construct list of tiles to display in the "drawer" menu
|
||||||
@ -120,14 +123,16 @@ class InvenTreeDrawer extends StatelessWidget {
|
|||||||
List<Widget> tiles = [];
|
List<Widget> tiles = [];
|
||||||
|
|
||||||
// "Home" access
|
// "Home" access
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
leading: Icon(TablerIcons.home, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.home, color: COLOR_ACTION),
|
||||||
title: Text(
|
title: Text(
|
||||||
L10().appTitle,
|
L10().appTitle,
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
onTap: _home,
|
onTap: _home,
|
||||||
));
|
),
|
||||||
|
);
|
||||||
|
|
||||||
tiles.add(Divider());
|
tiles.add(Divider());
|
||||||
|
|
||||||
@ -137,7 +142,7 @@ class InvenTreeDrawer extends StatelessWidget {
|
|||||||
title: Text(L10().parts),
|
title: Text(L10().parts),
|
||||||
leading: Icon(TablerIcons.box, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.box, color: COLOR_ACTION),
|
||||||
onTap: _parts,
|
onTap: _parts,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +152,7 @@ class InvenTreeDrawer extends StatelessWidget {
|
|||||||
title: Text(L10().stock),
|
title: Text(L10().stock),
|
||||||
leading: Icon(TablerIcons.package, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.package, color: COLOR_ACTION),
|
||||||
onTap: _stock,
|
onTap: _stock,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +162,7 @@ class InvenTreeDrawer extends StatelessWidget {
|
|||||||
title: Text(L10().purchaseOrders),
|
title: Text(L10().purchaseOrders),
|
||||||
leading: Icon(TablerIcons.shopping_cart, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.shopping_cart, color: COLOR_ACTION),
|
||||||
onTap: _purchaseOrders,
|
onTap: _purchaseOrders,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +172,7 @@ class InvenTreeDrawer extends StatelessWidget {
|
|||||||
title: Text(L10().salesOrders),
|
title: Text(L10().salesOrders),
|
||||||
leading: Icon(TablerIcons.truck_delivery, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.truck_delivery, color: COLOR_ACTION),
|
||||||
onTap: _salesOrders,
|
onTap: _salesOrders,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,10 +185,12 @@ class InvenTreeDrawer extends StatelessWidget {
|
|||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: Icon(TablerIcons.bell, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.bell, color: COLOR_ACTION),
|
||||||
trailing: notification_count > 0 ? Text(notification_count.toString()) : null,
|
trailing: notification_count > 0
|
||||||
|
? Text(notification_count.toString())
|
||||||
|
: null,
|
||||||
title: Text(L10().notifications),
|
title: Text(L10().notifications),
|
||||||
onTap: _notifications,
|
onTap: _notifications,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(Divider());
|
tiles.add(Divider());
|
||||||
@ -198,14 +205,9 @@ class InvenTreeDrawer extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
title: Text(L10().colorScheme),
|
title: Text(L10().colorScheme),
|
||||||
subtitle: Text(L10().colorSchemeDetail),
|
subtitle: Text(L10().colorSchemeDetail),
|
||||||
leading: Icon(
|
leading: Icon(TablerIcons.sun_moon, color: COLOR_ACTION),
|
||||||
TablerIcons.sun_moon,
|
trailing: Icon(darkMode ? TablerIcons.moon : TablerIcons.sun),
|
||||||
color: COLOR_ACTION
|
|
||||||
),
|
),
|
||||||
trailing: Icon(
|
|
||||||
darkMode ? TablerIcons.moon : TablerIcons.sun,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -213,7 +215,7 @@ class InvenTreeDrawer extends StatelessWidget {
|
|||||||
title: Text(L10().settings),
|
title: Text(L10().settings),
|
||||||
leading: Icon(Icons.settings, color: COLOR_ACTION),
|
leading: Icon(Icons.settings, color: COLOR_ACTION),
|
||||||
onTap: _settings,
|
onTap: _settings,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
@ -221,11 +223,6 @@ class InvenTreeDrawer extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
return Drawer(child: ListView(children: drawerTiles(context)));
|
||||||
return Drawer(
|
|
||||||
child: ListView(
|
|
||||||
children: drawerTiles(context),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,11 +9,8 @@ import "package:one_context/one_context.dart";
|
|||||||
|
|
||||||
import "package:inventree/l10.dart";
|
import "package:inventree/l10.dart";
|
||||||
|
|
||||||
|
|
||||||
class FilePickerDialog {
|
class FilePickerDialog {
|
||||||
|
|
||||||
static Future<File?> pickImageFromCamera() async {
|
static Future<File?> pickImageFromCamera() async {
|
||||||
|
|
||||||
final picker = ImagePicker();
|
final picker = ImagePicker();
|
||||||
|
|
||||||
final pickedImage = await picker.pickImage(source: ImageSource.camera);
|
final pickedImage = await picker.pickImage(source: ImageSource.camera);
|
||||||
@ -26,7 +23,6 @@ class FilePickerDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Future<File?> pickImageFromGallery() async {
|
static Future<File?> pickImageFromGallery() async {
|
||||||
|
|
||||||
final picker = ImagePicker();
|
final picker = ImagePicker();
|
||||||
|
|
||||||
final pickedImage = await picker.pickImage(source: ImageSource.gallery);
|
final pickedImage = await picker.pickImage(source: ImageSource.gallery);
|
||||||
@ -39,7 +35,6 @@ class FilePickerDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Future<File?> pickFileFromDevice() async {
|
static Future<File?> pickFileFromDevice() async {
|
||||||
|
|
||||||
final FilePickerResult? result = await FilePicker.platform.pickFiles();
|
final FilePickerResult? result = await FilePicker.platform.pickFiles();
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
@ -54,8 +49,12 @@ class FilePickerDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Present a dialog to pick a file, either from local file system or from camera
|
// Present a dialog to pick a file, either from local file system or from camera
|
||||||
static Future<void> pickFile({String message = "", bool allowImages = true, bool allowFiles = true, Function(File)? onPicked}) async {
|
static Future<void> pickFile({
|
||||||
|
String message = "",
|
||||||
|
bool allowImages = true,
|
||||||
|
bool allowFiles = true,
|
||||||
|
Function(File)? onPicked,
|
||||||
|
}) async {
|
||||||
String title = "";
|
String title = "";
|
||||||
|
|
||||||
if (allowImages && !allowFiles) {
|
if (allowImages && !allowFiles) {
|
||||||
@ -65,16 +64,10 @@ class FilePickerDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Construct actions
|
// Construct actions
|
||||||
List<Widget> actions = [
|
List<Widget> actions = [];
|
||||||
|
|
||||||
];
|
|
||||||
|
|
||||||
if (message.isNotEmpty) {
|
if (message.isNotEmpty) {
|
||||||
actions.add(
|
actions.add(ListTile(title: Text(message)));
|
||||||
ListTile(
|
|
||||||
title: Text(message)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.add(
|
actions.add(
|
||||||
@ -84,7 +77,6 @@ class FilePickerDialog {
|
|||||||
title: Text(allowFiles ? L10().selectFile : L10().selectImage),
|
title: Text(allowFiles ? L10().selectFile : L10().selectImage),
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
|
||||||
// Close the dialog
|
// Close the dialog
|
||||||
OneContext().popDialog();
|
OneContext().popDialog();
|
||||||
|
|
||||||
@ -101,7 +93,7 @@ class FilePickerDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (allowImages) {
|
if (allowImages) {
|
||||||
@ -122,24 +114,19 @@ class FilePickerDialog {
|
|||||||
onPicked(file);
|
onPicked(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
OneContext().showDialog(
|
OneContext().showDialog(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return SimpleDialog(
|
return SimpleDialog(title: Text(title), children: actions);
|
||||||
title: Text(title),
|
},
|
||||||
children: actions,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class CheckBoxField extends FormField<bool> {
|
class CheckBoxField extends FormField<bool> {
|
||||||
CheckBoxField({
|
CheckBoxField({
|
||||||
String? label,
|
String? label,
|
||||||
@ -149,31 +136,37 @@ class CheckBoxField extends FormField<bool> {
|
|||||||
TextStyle? labelStyle,
|
TextStyle? labelStyle,
|
||||||
String? helperText,
|
String? helperText,
|
||||||
TextStyle? helperStyle,
|
TextStyle? helperStyle,
|
||||||
}) :
|
}) : super(
|
||||||
super(
|
|
||||||
onSaved: onSaved,
|
onSaved: onSaved,
|
||||||
initialValue: initial,
|
initialValue: initial,
|
||||||
builder: (FormFieldState<bool> state) {
|
builder: (FormFieldState<bool> state) {
|
||||||
|
|
||||||
return CheckboxListTile(
|
return CheckboxListTile(
|
||||||
title: label != null ? Text(label, style: labelStyle) : null,
|
title: label != null ? Text(label, style: labelStyle) : null,
|
||||||
value: state.value,
|
value: state.value,
|
||||||
tristate: tristate,
|
tristate: tristate,
|
||||||
onChanged: state.didChange,
|
onChanged: state.didChange,
|
||||||
subtitle: helperText != null ? Text(helperText, style: helperStyle) : null,
|
subtitle: helperText != null
|
||||||
|
? Text(helperText, style: helperStyle)
|
||||||
|
: null,
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class StringField extends TextFormField {
|
class StringField extends TextFormField {
|
||||||
|
StringField({
|
||||||
StringField({String label = "", String? hint, String? initial, Function(String?)? onSaved, Function(String?)? validator, bool allowEmpty = false, bool isEnabled = true}) :
|
String label = "",
|
||||||
super(
|
String? hint,
|
||||||
|
String? initial,
|
||||||
|
Function(String?)? onSaved,
|
||||||
|
Function(String?)? validator,
|
||||||
|
bool allowEmpty = false,
|
||||||
|
bool isEnabled = true,
|
||||||
|
}) : super(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: allowEmpty ? label : label + "*",
|
labelText: allowEmpty ? label : label + "*",
|
||||||
hintText: hint
|
hintText: hint,
|
||||||
),
|
),
|
||||||
initialValue: initial,
|
initialValue: initial,
|
||||||
onSaved: onSaved,
|
onSaved: onSaved,
|
||||||
@ -188,32 +181,35 @@ class StringField extends TextFormField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper class for quantity values
|
* Helper class for quantity values
|
||||||
*/
|
*/
|
||||||
class QuantityField extends TextFormField {
|
class QuantityField extends TextFormField {
|
||||||
|
QuantityField({
|
||||||
QuantityField({String label = "", String hint = "", double? max, TextEditingController? controller}) :
|
String label = "",
|
||||||
super(
|
String hint = "",
|
||||||
decoration: InputDecoration(
|
double? max,
|
||||||
labelText: label,
|
TextEditingController? controller,
|
||||||
hintText: hint,
|
}) : super(
|
||||||
),
|
decoration: InputDecoration(labelText: label, hintText: hint),
|
||||||
controller: controller,
|
controller: controller,
|
||||||
keyboardType: TextInputType.numberWithOptions(signed: false, decimal: true),
|
keyboardType: TextInputType.numberWithOptions(
|
||||||
|
signed: false,
|
||||||
|
decimal: true,
|
||||||
|
),
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
|
|
||||||
if (value != null && value.isEmpty) return L10().quantityEmpty;
|
if (value != null && value.isEmpty) return L10().quantityEmpty;
|
||||||
|
|
||||||
double quantity = double.tryParse(value.toString()) ?? 0;
|
double quantity = double.tryParse(value.toString()) ?? 0;
|
||||||
|
|
||||||
if (quantity <= 0) return L10().quantityPositive;
|
if (quantity <= 0) return L10().quantityPositive;
|
||||||
if ((max != null) && (quantity > max)) return "Quantity must not exceed ${max}";
|
if ((max != null) && (quantity > max)) {
|
||||||
|
return "Quantity must not exceed ${max}";
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
@ -26,18 +26,15 @@ import "package:inventree/widget/snacks.dart";
|
|||||||
import "package:inventree/widget/spinner.dart";
|
import "package:inventree/widget/spinner.dart";
|
||||||
import "package:inventree/widget/company/company_list.dart";
|
import "package:inventree/widget/company/company_list.dart";
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeHomePage extends StatefulWidget {
|
class InvenTreeHomePage extends StatefulWidget {
|
||||||
|
|
||||||
const InvenTreeHomePage({Key? key}) : super(key: key);
|
const InvenTreeHomePage({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_InvenTreeHomePageState createState() => _InvenTreeHomePageState();
|
_InvenTreeHomePageState createState() => _InvenTreeHomePageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _InvenTreeHomePageState extends State<InvenTreeHomePage>
|
||||||
class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetProperties {
|
with BaseWidgetProperties {
|
||||||
|
|
||||||
_InvenTreeHomePageState() : super() {
|
_InvenTreeHomePageState() : super() {
|
||||||
// Load display settings
|
// Load display settings
|
||||||
_loadSettings();
|
_loadSettings();
|
||||||
@ -46,7 +43,6 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
_loadProfile();
|
_loadProfile();
|
||||||
|
|
||||||
InvenTreeAPI().registerCallback(() {
|
InvenTreeAPI().registerCallback(() {
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
// Reload the widget
|
// Reload the widget
|
||||||
@ -70,7 +66,10 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
void _showParts(BuildContext context) {
|
void _showParts(BuildContext context) {
|
||||||
if (!InvenTreeAPI().checkConnection()) return;
|
if (!InvenTreeAPI().checkConnection()) return;
|
||||||
|
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null)));
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showStarredParts(BuildContext context) {
|
void _showStarredParts(BuildContext context) {
|
||||||
@ -78,18 +77,17 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
|
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => PartList({"starred": "true"})),
|
||||||
builder: (context) => PartList({
|
|
||||||
"starred": "true"
|
|
||||||
})
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showStock(BuildContext context) {
|
void _showStock(BuildContext context) {
|
||||||
if (!InvenTreeAPI().checkConnection()) return;
|
if (!InvenTreeAPI().checkConnection()) return;
|
||||||
|
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(null)));
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => LocationDisplayWidget(null)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showPurchaseOrders(BuildContext context) {
|
void _showPurchaseOrders(BuildContext context) {
|
||||||
@ -98,8 +96,8 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => PurchaseOrderListWidget(filters: {})
|
builder: (context) => PurchaseOrderListWidget(filters: {}),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,15 +107,21 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => SalesOrderListWidget(filters: {})
|
builder: (context) => SalesOrderListWidget(filters: {}),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showSuppliers(BuildContext context) {
|
void _showSuppliers(BuildContext context) {
|
||||||
if (!InvenTreeAPI().checkConnection()) return;
|
if (!InvenTreeAPI().checkConnection()) return;
|
||||||
|
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => CompanyListWidget(L10().suppliers, {"is_supplier": "true"})));
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
CompanyListWidget(L10().suppliers, {"is_supplier": "true"}),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -131,12 +135,19 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
void _showCustomers(BuildContext context) {
|
void _showCustomers(BuildContext context) {
|
||||||
if (!InvenTreeAPI().checkConnection()) return;
|
if (!InvenTreeAPI().checkConnection()) return;
|
||||||
|
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => CompanyListWidget(L10().customers, {"is_customer": "true"})));
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
CompanyListWidget(L10().customers, {"is_customer": "true"}),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _selectProfile() {
|
void _selectProfile() {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context, MaterialPageRoute(builder: (context) => InvenTreeSelectServerWidget())
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => InvenTreeSelectServerWidget()),
|
||||||
).then((context) {
|
).then((context) {
|
||||||
// Once we return
|
// Once we return
|
||||||
_loadProfile();
|
_loadProfile();
|
||||||
@ -144,26 +155,40 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadSettings() async {
|
Future<void> _loadSettings() async {
|
||||||
|
homeShowSubscribed =
|
||||||
|
await InvenTreeSettingsManager().getValue(
|
||||||
|
INV_HOME_SHOW_SUBSCRIBED,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
as bool;
|
||||||
|
homeShowPo =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_PO, true)
|
||||||
|
as bool;
|
||||||
|
homeShowSo =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_SO, true)
|
||||||
|
as bool;
|
||||||
|
homeShowManufacturers =
|
||||||
|
await InvenTreeSettingsManager().getValue(
|
||||||
|
INV_HOME_SHOW_MANUFACTURERS,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
as bool;
|
||||||
|
homeShowCustomers =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_CUSTOMERS, true)
|
||||||
|
as bool;
|
||||||
|
homeShowSuppliers =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_SUPPLIERS, true)
|
||||||
|
as bool;
|
||||||
|
|
||||||
homeShowSubscribed = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_SUBSCRIBED, true) as bool;
|
setState(() {});
|
||||||
homeShowPo = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_PO, true) as bool;
|
|
||||||
homeShowSo = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_SO, true) as bool;
|
|
||||||
homeShowManufacturers = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_MANUFACTURERS, true) as bool;
|
|
||||||
homeShowCustomers = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_CUSTOMERS, true) as bool;
|
|
||||||
homeShowSuppliers = await InvenTreeSettingsManager().getValue(INV_HOME_SHOW_SUPPLIERS, true) as bool;
|
|
||||||
|
|
||||||
setState(() {
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _loadProfile() async {
|
Future<void> _loadProfile() async {
|
||||||
|
|
||||||
_profile = await UserProfileDBManager().getSelectedProfile();
|
_profile = await UserProfileDBManager().getSelectedProfile();
|
||||||
|
|
||||||
// A valid profile was loaded!
|
// A valid profile was loaded!
|
||||||
if (_profile != null) {
|
if (_profile != null) {
|
||||||
if (!InvenTreeAPI().isConnected() && !InvenTreeAPI().isConnecting()) {
|
if (!InvenTreeAPI().isConnected() && !InvenTreeAPI().isConnecting()) {
|
||||||
|
|
||||||
// Attempt server connection
|
// Attempt server connection
|
||||||
InvenTreeAPI().connectToServer(_profile!).then((result) {
|
InvenTreeAPI().connectToServer(_profile!).then((result) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
@ -176,8 +201,15 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _listTile(BuildContext context, String label, IconData icon, {Function()? callback, String role = "", String permission = "", Widget? trailing}) {
|
Widget _listTile(
|
||||||
|
BuildContext context,
|
||||||
|
String label,
|
||||||
|
IconData icon, {
|
||||||
|
Function()? callback,
|
||||||
|
String role = "",
|
||||||
|
String permission = "",
|
||||||
|
Widget? trailing,
|
||||||
|
}) {
|
||||||
bool connected = InvenTreeAPI().isConnected();
|
bool connected = InvenTreeAPI().isConnected();
|
||||||
|
|
||||||
bool allowed = true;
|
bool allowed = true;
|
||||||
@ -194,18 +226,13 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
leading: Icon(
|
leading: Icon(
|
||||||
icon,
|
icon,
|
||||||
size: 32,
|
size: 32,
|
||||||
color: connected && allowed ? COLOR_ACTION : Colors.grey
|
color: connected && allowed ? COLOR_ACTION : Colors.grey,
|
||||||
),
|
|
||||||
title: Text(
|
|
||||||
label,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 20
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
title: Text(label, style: TextStyle(fontSize: 20)),
|
||||||
trailing: trailing,
|
trailing: trailing,
|
||||||
),
|
),
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
@ -228,78 +255,89 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
* Constructs a list of tiles for the main screen
|
* Constructs a list of tiles for the main screen
|
||||||
*/
|
*/
|
||||||
List<Widget> getListTiles(BuildContext context) {
|
List<Widget> getListTiles(BuildContext context) {
|
||||||
|
|
||||||
List<Widget> tiles = [];
|
List<Widget> tiles = [];
|
||||||
|
|
||||||
// Parts
|
// Parts
|
||||||
if (InvenTreePart().canView) {
|
if (InvenTreePart().canView) {
|
||||||
tiles.add(_listTile(
|
tiles.add(
|
||||||
|
_listTile(
|
||||||
context,
|
context,
|
||||||
L10().parts,
|
L10().parts,
|
||||||
TablerIcons.box,
|
TablerIcons.box,
|
||||||
callback: () {
|
callback: () {
|
||||||
_showParts(context);
|
_showParts(context);
|
||||||
},
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Starred parts
|
// Starred parts
|
||||||
if (homeShowSubscribed && InvenTreePart().canView) {
|
if (homeShowSubscribed && InvenTreePart().canView) {
|
||||||
tiles.add(_listTile(
|
tiles.add(
|
||||||
|
_listTile(
|
||||||
context,
|
context,
|
||||||
L10().partsStarred,
|
L10().partsStarred,
|
||||||
TablerIcons.bell,
|
TablerIcons.bell,
|
||||||
callback: () {
|
callback: () {
|
||||||
_showStarredParts(context);
|
_showStarredParts(context);
|
||||||
}
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stock button
|
// Stock button
|
||||||
if (InvenTreeStockItem().canView) {
|
if (InvenTreeStockItem().canView) {
|
||||||
tiles.add(_listTile(
|
tiles.add(
|
||||||
|
_listTile(
|
||||||
context,
|
context,
|
||||||
L10().stock,
|
L10().stock,
|
||||||
TablerIcons.package,
|
TablerIcons.package,
|
||||||
callback: () {
|
callback: () {
|
||||||
_showStock(context);
|
_showStock(context);
|
||||||
}
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Purchase orders
|
// Purchase orders
|
||||||
if (homeShowPo && InvenTreePurchaseOrder().canView) {
|
if (homeShowPo && InvenTreePurchaseOrder().canView) {
|
||||||
tiles.add(_listTile(
|
tiles.add(
|
||||||
|
_listTile(
|
||||||
context,
|
context,
|
||||||
L10().purchaseOrders,
|
L10().purchaseOrders,
|
||||||
TablerIcons.shopping_cart,
|
TablerIcons.shopping_cart,
|
||||||
callback: () {
|
callback: () {
|
||||||
_showPurchaseOrders(context);
|
_showPurchaseOrders(context);
|
||||||
}
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (homeShowSo && InvenTreeSalesOrder().canView) {
|
if (homeShowSo && InvenTreeSalesOrder().canView) {
|
||||||
tiles.add(_listTile(
|
tiles.add(
|
||||||
|
_listTile(
|
||||||
context,
|
context,
|
||||||
L10().salesOrders,
|
L10().salesOrders,
|
||||||
TablerIcons.truck_delivery,
|
TablerIcons.truck_delivery,
|
||||||
callback: () {
|
callback: () {
|
||||||
_showSalesOrders(context);
|
_showSalesOrders(context);
|
||||||
}
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Suppliers
|
// Suppliers
|
||||||
if (homeShowSuppliers && InvenTreePurchaseOrder().canView) {
|
if (homeShowSuppliers && InvenTreePurchaseOrder().canView) {
|
||||||
tiles.add(_listTile(
|
tiles.add(
|
||||||
|
_listTile(
|
||||||
context,
|
context,
|
||||||
L10().suppliers,
|
L10().suppliers,
|
||||||
TablerIcons.building,
|
TablerIcons.building,
|
||||||
callback: () {
|
callback: () {
|
||||||
_showSuppliers(context);
|
_showSuppliers(context);
|
||||||
}
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add these tiles back in once the features are fleshed out
|
// TODO: Add these tiles back in once the features are fleshed out
|
||||||
@ -320,14 +358,16 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
*/
|
*/
|
||||||
// Customers
|
// Customers
|
||||||
if (homeShowCustomers) {
|
if (homeShowCustomers) {
|
||||||
tiles.add(_listTile(
|
tiles.add(
|
||||||
|
_listTile(
|
||||||
context,
|
context,
|
||||||
L10().customers,
|
L10().customers,
|
||||||
TablerIcons.building_store,
|
TablerIcons.building_store,
|
||||||
callback: () {
|
callback: () {
|
||||||
_showCustomers(context);
|
_showCustomers(context);
|
||||||
}
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
@ -338,10 +378,10 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
* display a connection status widget
|
* display a connection status widget
|
||||||
*/
|
*/
|
||||||
Widget _connectionStatusWidget(BuildContext context) {
|
Widget _connectionStatusWidget(BuildContext context) {
|
||||||
|
|
||||||
String? serverAddress = InvenTreeAPI().serverAddress;
|
String? serverAddress = InvenTreeAPI().serverAddress;
|
||||||
bool validAddress = serverAddress != null;
|
bool validAddress = serverAddress != null;
|
||||||
bool connecting = !InvenTreeAPI().isConnected() && InvenTreeAPI().isConnecting();
|
bool connecting =
|
||||||
|
!InvenTreeAPI().isConnected() && InvenTreeAPI().isConnecting();
|
||||||
|
|
||||||
Widget leading = Icon(TablerIcons.exclamation_circle, color: COLOR_DANGER);
|
Widget leading = Icon(TablerIcons.exclamation_circle, color: COLOR_DANGER);
|
||||||
Widget trailing = Icon(TablerIcons.server, color: COLOR_ACTION);
|
Widget trailing = Icon(TablerIcons.server, color: COLOR_ACTION);
|
||||||
@ -373,8 +413,8 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
trailing: trailing,
|
trailing: trailing,
|
||||||
leading: leading,
|
leading: leading,
|
||||||
onTap: _selectProfile,
|
onTap: _selectProfile,
|
||||||
)
|
),
|
||||||
]
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -384,7 +424,6 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
*/
|
*/
|
||||||
@override
|
@override
|
||||||
Widget getBody(BuildContext context) {
|
Widget getBody(BuildContext context) {
|
||||||
|
|
||||||
if (!InvenTreeAPI().isConnected()) {
|
if (!InvenTreeAPI().isConnected()) {
|
||||||
return _connectionStatusWidget(context);
|
return _connectionStatusWidget(context);
|
||||||
}
|
}
|
||||||
@ -408,12 +447,10 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
mainAxisSpacing: padding,
|
mainAxisSpacing: padding,
|
||||||
padding: EdgeInsets.all(padding),
|
padding: EdgeInsets.all(padding),
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
var connected = InvenTreeAPI().isConnected();
|
var connected = InvenTreeAPI().isConnected();
|
||||||
var connecting = !connected && InvenTreeAPI().isConnecting();
|
var connecting = !connected && InvenTreeAPI().isConnecting();
|
||||||
|
|
||||||
@ -426,15 +463,19 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
|
|||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
TablerIcons.server,
|
TablerIcons.server,
|
||||||
color: connected ? COLOR_SUCCESS : (connecting ? COLOR_PROGRESS: COLOR_DANGER),
|
color: connected
|
||||||
|
? COLOR_SUCCESS
|
||||||
|
: (connecting ? COLOR_PROGRESS : COLOR_DANGER),
|
||||||
),
|
),
|
||||||
onPressed: _selectProfile,
|
onPressed: _selectProfile,
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
drawer: InvenTreeDrawer(context),
|
drawer: InvenTreeDrawer(context),
|
||||||
body: getBody(context),
|
body: getBody(context),
|
||||||
bottomNavigationBar: InvenTreeAPI().isConnected() ? buildBottomAppBar(context, homeKey) : null,
|
bottomNavigationBar: InvenTreeAPI().isConnected()
|
||||||
|
? buildBottomAppBar(context, homeKey)
|
||||||
|
: null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import "package:inventree/widget/refreshable_state.dart";
|
|||||||
import "package:flutter_markdown/flutter_markdown.dart";
|
import "package:flutter_markdown/flutter_markdown.dart";
|
||||||
import "package:inventree/l10.dart";
|
import "package:inventree/l10.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A widget for displaying the notes associated with a given model.
|
* A widget for displaying the notes associated with a given model.
|
||||||
* We need to pass in the following parameters:
|
* We need to pass in the following parameters:
|
||||||
@ -14,7 +13,6 @@ import "package:inventree/l10.dart";
|
|||||||
* - Title for the app bar
|
* - Title for the app bar
|
||||||
*/
|
*/
|
||||||
class NotesWidget extends StatefulWidget {
|
class NotesWidget extends StatefulWidget {
|
||||||
|
|
||||||
const NotesWidget(this.model, {Key? key}) : super(key: key);
|
const NotesWidget(this.model, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
final InvenTreeModel model;
|
final InvenTreeModel model;
|
||||||
@ -23,12 +21,10 @@ class NotesWidget extends StatefulWidget {
|
|||||||
_NotesState createState() => _NotesState();
|
_NotesState createState() => _NotesState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class representing the state of the NotesWidget
|
* Class representing the state of the NotesWidget
|
||||||
*/
|
*/
|
||||||
class _NotesState extends RefreshableState<NotesWidget> {
|
class _NotesState extends RefreshableState<NotesWidget> {
|
||||||
|
|
||||||
_NotesState();
|
_NotesState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -41,7 +37,6 @@ class _NotesState extends RefreshableState<NotesWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
List<Widget> appBarActions(BuildContext context) {
|
List<Widget> appBarActions(BuildContext context) {
|
||||||
|
|
||||||
List<Widget> actions = [];
|
List<Widget> actions = [];
|
||||||
|
|
||||||
if (widget.model.canEdit) {
|
if (widget.model.canEdit) {
|
||||||
@ -54,16 +49,14 @@ class _NotesState extends RefreshableState<NotesWidget> {
|
|||||||
context,
|
context,
|
||||||
L10().editNotes,
|
L10().editNotes,
|
||||||
fields: {
|
fields: {
|
||||||
"notes": {
|
"notes": {"multiline": true},
|
||||||
"multiline": true,
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,10 +65,6 @@ class _NotesState extends RefreshableState<NotesWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget getBody(BuildContext context) {
|
Widget getBody(BuildContext context) {
|
||||||
return Markdown(
|
return Markdown(selectable: false, data: widget.model.notes);
|
||||||
selectable: false,
|
|
||||||
data: widget.model.notes,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
|
|
||||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||||
@ -8,17 +7,12 @@ import "package:inventree/inventree/model.dart";
|
|||||||
import "package:inventree/inventree/notification.dart";
|
import "package:inventree/inventree/notification.dart";
|
||||||
import "package:inventree/widget/refreshable_state.dart";
|
import "package:inventree/widget/refreshable_state.dart";
|
||||||
|
|
||||||
|
|
||||||
class NotificationWidget extends StatefulWidget {
|
class NotificationWidget extends StatefulWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_NotificationState createState() => _NotificationState();
|
_NotificationState createState() => _NotificationState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _NotificationState extends RefreshableState<NotificationWidget> {
|
class _NotificationState extends RefreshableState<NotificationWidget> {
|
||||||
|
|
||||||
_NotificationState() : super();
|
_NotificationState() : super();
|
||||||
|
|
||||||
List<InvenTreeNotification> notifications = [];
|
List<InvenTreeNotification> notifications = [];
|
||||||
@ -30,7 +24,6 @@ class _NotificationState extends RefreshableState<NotificationWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> request(BuildContext context) async {
|
Future<void> request(BuildContext context) async {
|
||||||
|
|
||||||
final results = await InvenTreeNotification().list();
|
final results = await InvenTreeNotification().list();
|
||||||
|
|
||||||
notifications.clear();
|
notifications.clear();
|
||||||
@ -45,8 +38,10 @@ class _NotificationState extends RefreshableState<NotificationWidget> {
|
|||||||
/*
|
/*
|
||||||
* Dismiss an individual notification entry (mark it as "read")
|
* Dismiss an individual notification entry (mark it as "read")
|
||||||
*/
|
*/
|
||||||
Future<void> dismissNotification(BuildContext context, InvenTreeNotification notification) async {
|
Future<void> dismissNotification(
|
||||||
|
BuildContext context,
|
||||||
|
InvenTreeNotification notification,
|
||||||
|
) async {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
isDismissing = true;
|
isDismissing = true;
|
||||||
@ -71,18 +66,17 @@ class _NotificationState extends RefreshableState<NotificationWidget> {
|
|||||||
*/
|
*/
|
||||||
@override
|
@override
|
||||||
List<Widget> getTiles(BuildContext context) {
|
List<Widget> getTiles(BuildContext context) {
|
||||||
|
|
||||||
List<Widget> tiles = [];
|
List<Widget> tiles = [];
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(
|
title: Text(L10().notifications),
|
||||||
L10().notifications,
|
|
||||||
),
|
|
||||||
subtitle: notifications.isEmpty ? Text(L10().notificationsEmpty) : null,
|
subtitle: notifications.isEmpty ? Text(L10().notificationsEmpty) : null,
|
||||||
leading: notifications.isEmpty ? Icon(TablerIcons.bell_exclamation) : Icon(TablerIcons.bell),
|
leading: notifications.isEmpty
|
||||||
|
? Icon(TablerIcons.bell_exclamation)
|
||||||
|
: Icon(TablerIcons.bell),
|
||||||
trailing: Text("${notifications.length}"),
|
trailing: Text("${notifications.length}"),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
for (var notification in notifications) {
|
for (var notification in notifications) {
|
||||||
@ -92,15 +86,16 @@ class _NotificationState extends RefreshableState<NotificationWidget> {
|
|||||||
subtitle: Text(notification.message),
|
subtitle: Text(notification.message),
|
||||||
trailing: IconButton(
|
trailing: IconButton(
|
||||||
icon: Icon(TablerIcons.bookmark),
|
icon: Icon(TablerIcons.bookmark),
|
||||||
onPressed: isDismissing ? null : () async {
|
onPressed: isDismissing
|
||||||
|
? null
|
||||||
|
: () async {
|
||||||
dismissNotification(context, notification);
|
dismissNotification(context, notification);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import "package:inventree/widget/snacks.dart";
|
|||||||
|
|
||||||
import "package:inventree/inventree/orders.dart";
|
import "package:inventree/inventree/orders.dart";
|
||||||
|
|
||||||
|
|
||||||
class ExtraLineDetailWidget extends StatefulWidget {
|
class ExtraLineDetailWidget extends StatefulWidget {
|
||||||
const ExtraLineDetailWidget(this.item, {Key? key}) : super(key: key);
|
const ExtraLineDetailWidget(this.item, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
@ -18,8 +17,8 @@ class ExtraLineDetailWidget extends StatefulWidget {
|
|||||||
_ExtraLineDetailWidgetState createState() => _ExtraLineDetailWidgetState();
|
_ExtraLineDetailWidgetState createState() => _ExtraLineDetailWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ExtraLineDetailWidgetState extends RefreshableState<ExtraLineDetailWidget> {
|
class _ExtraLineDetailWidgetState
|
||||||
|
extends RefreshableState<ExtraLineDetailWidget> {
|
||||||
_ExtraLineDetailWidgetState();
|
_ExtraLineDetailWidgetState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -35,8 +34,8 @@ class _ExtraLineDetailWidgetState extends RefreshableState<ExtraLineDetailWidget
|
|||||||
icon: Icon(TablerIcons.edit),
|
icon: Icon(TablerIcons.edit),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_editLineItem(context);
|
_editLineItem(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +59,7 @@ class _ExtraLineDetailWidgetState extends RefreshableState<ExtraLineDetailWidget
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
showSnackIcon(L10().lineItemUpdated, success: true);
|
showSnackIcon(L10().lineItemUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,38 +71,35 @@ class _ExtraLineDetailWidgetState extends RefreshableState<ExtraLineDetailWidget
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().reference),
|
title: Text(L10().reference),
|
||||||
trailing: Text(widget.item.reference),
|
trailing: Text(widget.item.reference),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().description),
|
title: Text(L10().description),
|
||||||
trailing: Text(widget.item.description),
|
trailing: Text(widget.item.description),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().quantity),
|
title: Text(L10().quantity),
|
||||||
trailing: Text(widget.item.quantity.toString()),
|
trailing: Text(widget.item.quantity.toString()),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().unitPrice),
|
title: Text(L10().unitPrice),
|
||||||
trailing: Text(
|
trailing: Text(
|
||||||
renderCurrency(widget.item.price, widget.item.priceCurrency)
|
renderCurrency(widget.item.price, widget.item.priceCurrency),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (widget.item.notes.isNotEmpty) {
|
if (widget.item.notes.isNotEmpty) {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(title: Text(L10().notes), subtitle: Text(widget.item.notes)),
|
||||||
title: Text(L10().notes),
|
|
||||||
subtitle: Text(widget.item.notes),
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,28 +9,27 @@ import "package:inventree/widget/paginator.dart";
|
|||||||
import "package:inventree/widget/refreshable_state.dart";
|
import "package:inventree/widget/refreshable_state.dart";
|
||||||
import "package:inventree/widget/snacks.dart";
|
import "package:inventree/widget/snacks.dart";
|
||||||
|
|
||||||
|
|
||||||
class POExtraLineListWidget extends StatefulWidget {
|
class POExtraLineListWidget extends StatefulWidget {
|
||||||
|
const POExtraLineListWidget(this.order, {this.filters = const {}, Key? key})
|
||||||
const POExtraLineListWidget(this.order, {this.filters = const {}, Key? key}) : super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
final InvenTreePurchaseOrder order;
|
final InvenTreePurchaseOrder order;
|
||||||
|
|
||||||
final Map<String, String> filters;
|
final Map<String, String> filters;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PurchaseOrderExtraLineListWidgetState createState() => _PurchaseOrderExtraLineListWidgetState();
|
_PurchaseOrderExtraLineListWidgetState createState() =>
|
||||||
|
_PurchaseOrderExtraLineListWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PurchaseOrderExtraLineListWidgetState extends RefreshableState<POExtraLineListWidget> {
|
class _PurchaseOrderExtraLineListWidgetState
|
||||||
|
extends RefreshableState<POExtraLineListWidget> {
|
||||||
_PurchaseOrderExtraLineListWidgetState();
|
_PurchaseOrderExtraLineListWidgetState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getAppBarTitle() => L10().extraLineItems;
|
String getAppBarTitle() => L10().extraLineItems;
|
||||||
|
|
||||||
Future<void> _addLineItem(BuildContext context) async {
|
Future<void> _addLineItem(BuildContext context) async {
|
||||||
|
|
||||||
var fields = InvenTreePOExtraLineItem().formFields();
|
var fields = InvenTreePOExtraLineItem().formFields();
|
||||||
|
|
||||||
fields["order"]?["value"] = widget.order.pk;
|
fields["order"]?["value"] = widget.order.pk;
|
||||||
@ -42,7 +41,7 @@ class _PurchaseOrderExtraLineListWidgetState extends RefreshableState<POExtraLin
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
showSnackIcon(L10().lineItemUpdated, success: true);
|
showSnackIcon(L10().lineItemUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,8 +56,8 @@ class _PurchaseOrderExtraLineListWidgetState extends RefreshableState<POExtraLin
|
|||||||
label: L10().lineItemAdd,
|
label: L10().lineItemAdd,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_addLineItem(context);
|
_addLineItem(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,35 +70,41 @@ class _PurchaseOrderExtraLineListWidgetState extends RefreshableState<POExtraLin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PaginatedPOExtraLineList extends PaginatedSearchWidget {
|
class PaginatedPOExtraLineList extends PaginatedSearchWidget {
|
||||||
|
const PaginatedPOExtraLineList(Map<String, String> filters)
|
||||||
const PaginatedPOExtraLineList(Map<String, String> filters) : super(filters: filters);
|
: super(filters: filters);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get searchTitle => L10().extraLineItems;
|
String get searchTitle => L10().extraLineItems;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PaginatedPOExtraLineListState createState() => _PaginatedPOExtraLineListState();
|
_PaginatedPOExtraLineListState createState() =>
|
||||||
|
_PaginatedPOExtraLineListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PaginatedPOExtraLineListState extends PaginatedSearchState<PaginatedPOExtraLineList> {
|
class _PaginatedPOExtraLineListState
|
||||||
|
extends PaginatedSearchState<PaginatedPOExtraLineList> {
|
||||||
_PaginatedPOExtraLineListState() : super();
|
_PaginatedPOExtraLineListState() : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get prefix => "po_extra_line_";
|
String get prefix => "po_extra_line_";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
final page = await InvenTreePOExtraLineItem().listPaginated(limit, offset, filters: params);
|
int limit,
|
||||||
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
|
final page = await InvenTreePOExtraLineItem().listPaginated(
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
filters: params,
|
||||||
|
);
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||||
|
|
||||||
InvenTreePOExtraLineItem line = model as InvenTreePOExtraLineItem;
|
InvenTreePOExtraLineItem line = model as InvenTreePOExtraLineItem;
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
|
@ -21,22 +21,18 @@ import "package:inventree/widget/company/supplier_part_detail.dart";
|
|||||||
* Widget for displaying detail view of a single PurchaseOrderLineItem
|
* Widget for displaying detail view of a single PurchaseOrderLineItem
|
||||||
*/
|
*/
|
||||||
class POLineDetailWidget extends StatefulWidget {
|
class POLineDetailWidget extends StatefulWidget {
|
||||||
|
|
||||||
const POLineDetailWidget(this.item, {Key? key}) : super(key: key);
|
const POLineDetailWidget(this.item, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
final InvenTreePOLineItem item;
|
final InvenTreePOLineItem item;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_POLineDetailWidgetState createState() => _POLineDetailWidgetState();
|
_POLineDetailWidgetState createState() => _POLineDetailWidgetState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* State for the POLineDetailWidget
|
* State for the POLineDetailWidget
|
||||||
*/
|
*/
|
||||||
class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
||||||
|
|
||||||
_POLineDetailWidgetState();
|
_POLineDetailWidgetState();
|
||||||
|
|
||||||
InvenTreeStockLocation? destination;
|
InvenTreeStockLocation? destination;
|
||||||
@ -55,7 +51,7 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
_editLineItem(context);
|
_editLineItem(context);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,8 +71,8 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
|||||||
label: L10().receiveItem,
|
label: L10().receiveItem,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
receiveLineItem(context);
|
receiveLineItem(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,7 +85,9 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
|||||||
await widget.item.reload();
|
await widget.item.reload();
|
||||||
|
|
||||||
if (widget.item.destinationId > 0) {
|
if (widget.item.destinationId > 0) {
|
||||||
InvenTreeStockLocation().get(widget.item.destinationId).then((InvenTreeModel? loc) {
|
InvenTreeStockLocation().get(widget.item.destinationId).then((
|
||||||
|
InvenTreeModel? loc,
|
||||||
|
) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
if (loc != null && loc is InvenTreeStockLocation) {
|
if (loc != null && loc is InvenTreeStockLocation) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -109,7 +107,6 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback to edit this line item
|
// Callback to edit this line item
|
||||||
@ -123,7 +120,7 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
showSnackIcon(L10().lineItemUpdated, success: true);
|
showSnackIcon(L10().lineItemUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,8 +130,8 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
|||||||
context,
|
context,
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
showSnackIcon(L10().receivedItem, success: true),
|
showSnackIcon(L10().receivedItem, success: true),
|
||||||
refresh(context)
|
refresh(context),
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +155,7 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
|||||||
part.goToDetailPage(context);
|
part.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Reference to the supplier part
|
// Reference to the supplier part
|
||||||
@ -169,26 +166,33 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
|||||||
leading: Icon(TablerIcons.building, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.building, color: COLOR_ACTION),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
var part = await InvenTreeSupplierPart().get(widget.item.supplierPartId);
|
var part = await InvenTreeSupplierPart().get(
|
||||||
|
widget.item.supplierPartId,
|
||||||
|
);
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
|
|
||||||
if (part is InvenTreeSupplierPart) {
|
if (part is InvenTreeSupplierPart) {
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => SupplierPartDetailWidget(part)));
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => SupplierPartDetailWidget(part),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Destination
|
// Destination
|
||||||
if (destination != null) {
|
if (destination != null) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().destination),
|
title: Text(L10().destination),
|
||||||
subtitle: Text(destination!.name),
|
subtitle: Text(destination!.name),
|
||||||
leading: Icon(TablerIcons.map_pin, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.map_pin, color: COLOR_ACTION),
|
||||||
onTap: () => {
|
onTap: () => {destination!.goToDetailPage(context)},
|
||||||
destination!.goToDetailPage(context)
|
),
|
||||||
}
|
);
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Received quantity
|
// Received quantity
|
||||||
@ -199,11 +203,11 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
|||||||
trailing: Text(
|
trailing: Text(
|
||||||
widget.item.progressString,
|
widget.item.progressString,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: widget.item.isComplete ? COLOR_SUCCESS: COLOR_WARNING
|
color: widget.item.isComplete ? COLOR_SUCCESS : COLOR_WARNING,
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
leading: Icon(TablerIcons.progress),
|
leading: Icon(TablerIcons.progress),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Reference
|
// Reference
|
||||||
@ -213,7 +217,7 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
|||||||
title: Text(L10().reference),
|
title: Text(L10().reference),
|
||||||
subtitle: Text(widget.item.reference),
|
subtitle: Text(widget.item.reference),
|
||||||
leading: Icon(TablerIcons.hash),
|
leading: Icon(TablerIcons.hash),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,9 +227,12 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
|||||||
title: Text(L10().unitPrice),
|
title: Text(L10().unitPrice),
|
||||||
leading: Icon(TablerIcons.currency_dollar),
|
leading: Icon(TablerIcons.currency_dollar),
|
||||||
trailing: Text(
|
trailing: Text(
|
||||||
renderCurrency(widget.item.purchasePrice, widget.item.purchasePriceCurrency)
|
renderCurrency(
|
||||||
|
widget.item.purchasePrice,
|
||||||
|
widget.item.purchasePriceCurrency,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Note
|
// Note
|
||||||
@ -235,7 +242,7 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
|||||||
title: Text(L10().notes),
|
title: Text(L10().notes),
|
||||||
subtitle: Text(widget.item.notes),
|
subtitle: Text(widget.item.notes),
|
||||||
leading: Icon(TablerIcons.note),
|
leading: Icon(TablerIcons.note),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,11 +256,10 @@ class _POLineDetailWidgetState extends RefreshableState<POLineDetailWidget> {
|
|||||||
onTap: () async {
|
onTap: () async {
|
||||||
await openLink(widget.item.link);
|
await openLink(widget.item.link);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -16,22 +16,21 @@ import "package:inventree/widget/progress.dart";
|
|||||||
* Paginated widget class for displaying a list of purchase order line items
|
* Paginated widget class for displaying a list of purchase order line items
|
||||||
*/
|
*/
|
||||||
class PaginatedPOLineList extends PaginatedSearchWidget {
|
class PaginatedPOLineList extends PaginatedSearchWidget {
|
||||||
|
const PaginatedPOLineList(Map<String, String> filters)
|
||||||
const PaginatedPOLineList(Map<String, String> filters) : super(filters: filters);
|
: super(filters: filters);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get searchTitle => L10().lineItems;
|
String get searchTitle => L10().lineItems;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PaginatedPOLineListState createState() => _PaginatedPOLineListState();
|
_PaginatedPOLineListState createState() => _PaginatedPOLineListState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* State class for PaginatedPOLineList
|
* State class for PaginatedPOLineList
|
||||||
*/
|
*/
|
||||||
class _PaginatedPOLineListState extends PaginatedSearchState<PaginatedPOLineList> {
|
class _PaginatedPOLineListState
|
||||||
|
extends PaginatedSearchState<PaginatedPOLineList> {
|
||||||
_PaginatedPOLineListState() : super();
|
_PaginatedPOLineListState() : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -55,13 +54,20 @@ class _PaginatedPOLineListState extends PaginatedSearchState<PaginatedPOLineList
|
|||||||
"label": L10().received,
|
"label": L10().received,
|
||||||
"help_text": L10().receivedFilterDetail,
|
"help_text": L10().receivedFilterDetail,
|
||||||
"tristate": true,
|
"tristate": true,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
|
int limit,
|
||||||
final page = await InvenTreePOLineItem().listPaginated(limit, offset, filters: params);
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
|
final page = await InvenTreePOLineItem().listPaginated(
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
filters: params,
|
||||||
|
);
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,24 +77,34 @@ class _PaginatedPOLineListState extends PaginatedSearchState<PaginatedPOLineList
|
|||||||
InvenTreeSupplierPart? supplierPart = item.supplierPart;
|
InvenTreeSupplierPart? supplierPart = item.supplierPart;
|
||||||
|
|
||||||
if (supplierPart != null) {
|
if (supplierPart != null) {
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(supplierPart.SKU),
|
title: Text(supplierPart.SKU),
|
||||||
subtitle: Text(item.partName),
|
subtitle: Text(item.partName),
|
||||||
trailing: Text(item.progressString, style: TextStyle(color: item.isComplete ? COLOR_SUCCESS : COLOR_WARNING)),
|
trailing: Text(
|
||||||
|
item.progressString,
|
||||||
|
style: TextStyle(
|
||||||
|
color: item.isComplete ? COLOR_SUCCESS : COLOR_WARNING,
|
||||||
|
),
|
||||||
|
),
|
||||||
leading: InvenTreeAPI().getThumbnail(supplierPart.partImage),
|
leading: InvenTreeAPI().getThumbnail(supplierPart.partImage),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
await item.reload();
|
await item.reload();
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => POLineDetailWidget(item)));
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => POLineDetailWidget(item)),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Return an error tile
|
// Return an error tile
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(L10().error),
|
title: Text(L10().error),
|
||||||
subtitle: Text("supplier part not defined", style: TextStyle(color: COLOR_DANGER)),
|
subtitle: Text(
|
||||||
|
"supplier part not defined",
|
||||||
|
style: TextStyle(color: COLOR_DANGER),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import "package:inventree/widget/order/po_extra_line_list.dart";
|
|||||||
import "package:inventree/widget/stock/location_display.dart";
|
import "package:inventree/widget/stock/location_display.dart";
|
||||||
import "package:inventree/widget/order/po_line_list.dart";
|
import "package:inventree/widget/order/po_line_list.dart";
|
||||||
|
|
||||||
|
|
||||||
import "package:inventree/widget/attachment_widget.dart";
|
import "package:inventree/widget/attachment_widget.dart";
|
||||||
import "package:inventree/widget/notes_widget.dart";
|
import "package:inventree/widget/notes_widget.dart";
|
||||||
import "package:inventree/widget/progress.dart";
|
import "package:inventree/widget/progress.dart";
|
||||||
@ -27,12 +26,10 @@ import "package:inventree/widget/snacks.dart";
|
|||||||
import "package:inventree/widget/stock/stock_list.dart";
|
import "package:inventree/widget/stock/stock_list.dart";
|
||||||
import "package:inventree/preferences.dart";
|
import "package:inventree/preferences.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Widget for viewing a single PurchaseOrder instance
|
* Widget for viewing a single PurchaseOrder instance
|
||||||
*/
|
*/
|
||||||
class PurchaseOrderDetailWidget extends StatefulWidget {
|
class PurchaseOrderDetailWidget extends StatefulWidget {
|
||||||
|
|
||||||
const PurchaseOrderDetailWidget(this.order, {Key? key}) : super(key: key);
|
const PurchaseOrderDetailWidget(this.order, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
final InvenTreePurchaseOrder order;
|
final InvenTreePurchaseOrder order;
|
||||||
@ -41,9 +38,8 @@ class PurchaseOrderDetailWidget extends StatefulWidget {
|
|||||||
_PurchaseOrderDetailState createState() => _PurchaseOrderDetailState();
|
_PurchaseOrderDetailState createState() => _PurchaseOrderDetailState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _PurchaseOrderDetailState
|
||||||
class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidget> {
|
extends RefreshableState<PurchaseOrderDetailWidget> {
|
||||||
|
|
||||||
_PurchaseOrderDetailState();
|
_PurchaseOrderDetailState();
|
||||||
|
|
||||||
List<InvenTreePOLineItem> lines = [];
|
List<InvenTreePOLineItem> lines = [];
|
||||||
@ -79,8 +75,8 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
tooltip: L10().purchaseOrderEdit,
|
tooltip: L10().purchaseOrderEdit,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
editOrder(context);
|
editOrder(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,22 +94,21 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
label: L10().takePicture,
|
label: L10().takePicture,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
_uploadImage(context);
|
_uploadImage(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.order.canCreate) {
|
if (widget.order.canCreate) {
|
||||||
if (widget.order.isPending) {
|
if (widget.order.isPending) {
|
||||||
|
|
||||||
actions.add(
|
actions.add(
|
||||||
SpeedDialChild(
|
SpeedDialChild(
|
||||||
child: Icon(TablerIcons.circle_plus, color: Colors.green),
|
child: Icon(TablerIcons.circle_plus, color: Colors.green),
|
||||||
label: L10().lineItemAdd,
|
label: L10().lineItemAdd,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
_addLineItem(context);
|
_addLineItem(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
actions.add(
|
actions.add(
|
||||||
@ -122,8 +117,8 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
label: L10().issueOrder,
|
label: L10().issueOrder,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
_issueOrder(context);
|
_issueOrder(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,8 +129,8 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
label: L10().cancelOrder,
|
label: L10().cancelOrder,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
_cancelOrder(context);
|
_cancelOrder(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,14 +140,11 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
|
|
||||||
/// Add a new line item to this order
|
/// Add a new line item to this order
|
||||||
Future<void> _addLineItem(BuildContext context) async {
|
Future<void> _addLineItem(BuildContext context) async {
|
||||||
|
|
||||||
var fields = InvenTreePOLineItem().formFields();
|
var fields = InvenTreePOLineItem().formFields();
|
||||||
|
|
||||||
// Update part field definition
|
// Update part field definition
|
||||||
fields["part"]?["hidden"] = false;
|
fields["part"]?["hidden"] = false;
|
||||||
fields["part"]?["filters"] = {
|
fields["part"]?["filters"] = {"supplier": widget.order.supplierId};
|
||||||
"supplier": widget.order.supplierId
|
|
||||||
};
|
|
||||||
|
|
||||||
fields["order"]?["value"] = widget.order.pk;
|
fields["order"]?["value"] = widget.order.pk;
|
||||||
|
|
||||||
@ -163,24 +155,22 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
showSnackIcon(L10().lineItemUpdated, success: true);
|
showSnackIcon(L10().lineItemUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Upload an image against the current PurchaseOrder
|
/// Upload an image against the current PurchaseOrder
|
||||||
Future<void> _uploadImage(BuildContext context) async {
|
Future<void> _uploadImage(BuildContext context) async {
|
||||||
|
InvenTreePurchaseOrderAttachment()
|
||||||
InvenTreePurchaseOrderAttachment().uploadImage(
|
.uploadImage(widget.order.pk, prefix: widget.order.reference)
|
||||||
widget.order.pk,
|
.then((result) => refresh(context));
|
||||||
prefix: widget.order.reference,
|
|
||||||
).then((result) => refresh(context));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Issue this order
|
/// Issue this order
|
||||||
Future<void> _issueOrder(BuildContext context) async {
|
Future<void> _issueOrder(BuildContext context) async {
|
||||||
|
|
||||||
confirmationDialog(
|
confirmationDialog(
|
||||||
L10().issueOrder, "",
|
L10().issueOrder,
|
||||||
|
"",
|
||||||
icon: TablerIcons.send,
|
icon: TablerIcons.send,
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
acceptText: L10().issue,
|
acceptText: L10().issue,
|
||||||
@ -188,15 +178,15 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
widget.order.issueOrder().then((dynamic) {
|
widget.order.issueOrder().then((dynamic) {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Cancel this order
|
/// Cancel this order
|
||||||
Future<void> _cancelOrder(BuildContext context) async {
|
Future<void> _cancelOrder(BuildContext context) async {
|
||||||
|
|
||||||
confirmationDialog(
|
confirmationDialog(
|
||||||
L10().cancelOrder, "",
|
L10().cancelOrder,
|
||||||
|
"",
|
||||||
icon: TablerIcons.circle_x,
|
icon: TablerIcons.circle_x,
|
||||||
color: Colors.red,
|
color: Colors.red,
|
||||||
acceptText: L10().cancel,
|
acceptText: L10().cancel,
|
||||||
@ -204,7 +194,7 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
widget.order.cancelOrder().then((dynamic) {
|
widget.order.cancelOrder().then((dynamic) {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +215,7 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
refresh(context);
|
refresh(context);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,15 +229,14 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
context,
|
context,
|
||||||
handler: POAllocateBarcodeHandler(purchaseOrder: widget.order),
|
handler: POAllocateBarcodeHandler(purchaseOrder: widget.order),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> request(BuildContext context) async {
|
Future<void> request(BuildContext context) async {
|
||||||
await widget.order.reload();
|
await widget.order.reload();
|
||||||
@ -256,8 +245,16 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
|
|
||||||
lines = await widget.order.getLineItems();
|
lines = await widget.order.getLineItems();
|
||||||
|
|
||||||
showCameraShortcut = await InvenTreeSettingsManager().getBool(INV_PO_SHOW_CAMERA, true);
|
showCameraShortcut = await InvenTreeSettingsManager().getBool(
|
||||||
supportProjectCodes = api.supportsProjectCodes && await api.getGlobalBooleanSetting("PROJECT_CODES_ENABLED", backup: true);
|
INV_PO_SHOW_CAMERA,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
supportProjectCodes =
|
||||||
|
api.supportsProjectCodes &&
|
||||||
|
await api.getGlobalBooleanSetting(
|
||||||
|
"PROJECT_CODES_ENABLED",
|
||||||
|
backup: true,
|
||||||
|
);
|
||||||
|
|
||||||
completedLines = 0;
|
completedLines = 0;
|
||||||
|
|
||||||
@ -267,7 +264,9 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InvenTreePurchaseOrderAttachment().countAttachments(widget.order.pk).then((int value) {
|
InvenTreePurchaseOrderAttachment().countAttachments(widget.order.pk).then((
|
||||||
|
int value,
|
||||||
|
) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
attachmentCount = value;
|
attachmentCount = value;
|
||||||
@ -275,8 +274,11 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (api.supportsPurchaseOrderDestination && widget.order.destinationId > 0) {
|
if (api.supportsPurchaseOrderDestination &&
|
||||||
InvenTreeStockLocation().get(widget.order.destinationId).then((InvenTreeModel? loc) {
|
widget.order.destinationId > 0) {
|
||||||
|
InvenTreeStockLocation().get(widget.order.destinationId).then((
|
||||||
|
InvenTreeModel? loc,
|
||||||
|
) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
if (loc != null && loc is InvenTreeStockLocation) {
|
if (loc != null && loc is InvenTreeStockLocation) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -298,7 +300,9 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Count number of "extra line items" against this order
|
// Count number of "extra line items" against this order
|
||||||
InvenTreePOExtraLineItem().count(filters: {"order": widget.order.pk.toString() }).then((int value) {
|
InvenTreePOExtraLineItem()
|
||||||
|
.count(filters: {"order": widget.order.pk.toString()})
|
||||||
|
.then((int value) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
extraLineCount = value;
|
extraLineCount = value;
|
||||||
@ -331,12 +335,11 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
showSnackIcon(L10().purchaseOrderUpdated, success: true);
|
showSnackIcon(L10().purchaseOrderUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget headerTile(BuildContext context) {
|
Widget headerTile(BuildContext context) {
|
||||||
|
|
||||||
InvenTreeCompany? supplier = widget.order.supplier;
|
InvenTreeCompany? supplier = widget.order.supplier;
|
||||||
|
|
||||||
return Card(
|
return Card(
|
||||||
@ -347,16 +350,14 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
trailing: Text(
|
trailing: Text(
|
||||||
api.PurchaseOrderStatus.label(widget.order.status),
|
api.PurchaseOrderStatus.label(widget.order.status),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: api.PurchaseOrderStatus.color(widget.order.status)
|
color: api.PurchaseOrderStatus.color(widget.order.status),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> orderTiles(BuildContext context) {
|
List<Widget> orderTiles(BuildContext context) {
|
||||||
|
|
||||||
List<Widget> tiles = [];
|
List<Widget> tiles = [];
|
||||||
|
|
||||||
InvenTreeCompany? supplier = widget.order.supplier;
|
InvenTreeCompany? supplier = widget.order.supplier;
|
||||||
@ -364,35 +365,44 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
tiles.add(headerTile(context));
|
tiles.add(headerTile(context));
|
||||||
|
|
||||||
if (supportProjectCodes && widget.order.hasProjectCode) {
|
if (supportProjectCodes && widget.order.hasProjectCode) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().projectCode),
|
title: Text(L10().projectCode),
|
||||||
subtitle: Text("${widget.order.projectCode} - ${widget.order.projectCodeDescription}"),
|
subtitle: Text(
|
||||||
|
"${widget.order.projectCode} - ${widget.order.projectCodeDescription}",
|
||||||
|
),
|
||||||
leading: Icon(TablerIcons.list),
|
leading: Icon(TablerIcons.list),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (supplier != null) {
|
if (supplier != null) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().supplier),
|
title: Text(L10().supplier),
|
||||||
subtitle: Text(supplier.name),
|
subtitle: Text(supplier.name),
|
||||||
leading: Icon(TablerIcons.building, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.building, color: COLOR_ACTION),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
supplier.goToDetailPage(context);
|
supplier.goToDetailPage(context);
|
||||||
},
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.order.supplierReference.isNotEmpty) {
|
if (widget.order.supplierReference.isNotEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().supplierReference),
|
title: Text(L10().supplierReference),
|
||||||
subtitle: Text(widget.order.supplierReference),
|
subtitle: Text(widget.order.supplierReference),
|
||||||
leading: Icon(TablerIcons.hash),
|
leading: Icon(TablerIcons.hash),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Order destination
|
// Order destination
|
||||||
if (destination != null) {
|
if (destination != null) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().destination),
|
title: Text(L10().destination),
|
||||||
subtitle: Text(destination!.name),
|
subtitle: Text(destination!.name),
|
||||||
leading: Icon(TablerIcons.map_pin, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.map_pin, color: COLOR_ACTION),
|
||||||
@ -400,27 +410,36 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => LocationDisplayWidget(destination)
|
builder: (context) => LocationDisplayWidget(destination),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
}
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Color lineColor = completedLines < widget.order.lineItemCount ? COLOR_WARNING : COLOR_SUCCESS;
|
Color lineColor = completedLines < widget.order.lineItemCount
|
||||||
|
? COLOR_WARNING
|
||||||
|
: COLOR_SUCCESS;
|
||||||
|
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().lineItems),
|
title: Text(L10().lineItems),
|
||||||
subtitle: ProgressBar(
|
subtitle: ProgressBar(
|
||||||
completedLines.toDouble(),
|
completedLines.toDouble(),
|
||||||
maximum: widget.order.lineItemCount.toDouble(),
|
maximum: widget.order.lineItemCount.toDouble(),
|
||||||
),
|
),
|
||||||
leading: Icon(TablerIcons.clipboard_check),
|
leading: Icon(TablerIcons.clipboard_check),
|
||||||
trailing: Text("${completedLines} / ${widget.order.lineItemCount}", style: TextStyle(color: lineColor)),
|
trailing: Text(
|
||||||
));
|
"${completedLines} / ${widget.order.lineItemCount}",
|
||||||
|
style: TextStyle(color: lineColor),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
// Extra line items
|
// Extra line items
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().extraLineItems),
|
title: Text(L10().extraLineItems),
|
||||||
leading: Icon(TablerIcons.clipboard_list, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.clipboard_list, color: COLOR_ACTION),
|
||||||
trailing: Text(extraLineCount.toString()),
|
trailing: Text(extraLineCount.toString()),
|
||||||
@ -428,59 +447,83 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => POExtraLineListWidget(widget.order, filters: {"order": widget.order.pk.toString()})
|
builder: (context) => POExtraLineListWidget(
|
||||||
)
|
widget.order,
|
||||||
)
|
filters: {"order": widget.order.pk.toString()},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
},
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
|
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().totalPrice),
|
title: Text(L10().totalPrice),
|
||||||
leading: Icon(TablerIcons.currency_dollar),
|
leading: Icon(TablerIcons.currency_dollar),
|
||||||
trailing: Text(
|
trailing: Text(
|
||||||
renderCurrency(widget.order.totalPrice, widget.order.totalPriceCurrency)
|
renderCurrency(
|
||||||
|
widget.order.totalPrice,
|
||||||
|
widget.order.totalPriceCurrency,
|
||||||
),
|
),
|
||||||
));
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
if (widget.order.issueDate.isNotEmpty) {
|
if (widget.order.issueDate.isNotEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().issueDate),
|
title: Text(L10().issueDate),
|
||||||
trailing: Text(widget.order.issueDate),
|
trailing: Text(widget.order.issueDate),
|
||||||
leading: Icon(TablerIcons.calendar),
|
leading: Icon(TablerIcons.calendar),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.order.startDate.isNotEmpty) {
|
if (widget.order.startDate.isNotEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().startDate),
|
title: Text(L10().startDate),
|
||||||
trailing: Text(widget.order.startDate),
|
trailing: Text(widget.order.startDate),
|
||||||
leading: Icon(TablerIcons.calendar),
|
leading: Icon(TablerIcons.calendar),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.order.targetDate.isNotEmpty) {
|
if (widget.order.targetDate.isNotEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().targetDate),
|
title: Text(L10().targetDate),
|
||||||
trailing: Text(widget.order.targetDate),
|
trailing: Text(widget.order.targetDate),
|
||||||
leading: Icon(TablerIcons.calendar),
|
leading: Icon(TablerIcons.calendar),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.order.completionDate.isNotEmpty) {
|
if (widget.order.completionDate.isNotEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().completionDate),
|
title: Text(L10().completionDate),
|
||||||
trailing: Text(widget.order.completionDate),
|
trailing: Text(widget.order.completionDate),
|
||||||
leading: Icon(TablerIcons.calendar),
|
leading: Icon(TablerIcons.calendar),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Responsible "owner"
|
// Responsible "owner"
|
||||||
if (widget.order.responsibleName.isNotEmpty && widget.order.responsibleLabel.isNotEmpty) {
|
if (widget.order.responsibleName.isNotEmpty &&
|
||||||
tiles.add(ListTile(
|
widget.order.responsibleLabel.isNotEmpty) {
|
||||||
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().responsible),
|
title: Text(L10().responsible),
|
||||||
leading: Icon(widget.order.responsibleLabel == "group" ? TablerIcons.users : TablerIcons.user),
|
leading: Icon(
|
||||||
trailing: Text(widget.order.responsibleName)
|
widget.order.responsibleLabel == "group"
|
||||||
));
|
? TablerIcons.users
|
||||||
|
: TablerIcons.user,
|
||||||
|
),
|
||||||
|
trailing: Text(widget.order.responsibleName),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notes tile
|
// Notes tile
|
||||||
@ -491,12 +534,10 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => NotesWidget(widget.order)),
|
||||||
builder: (context) => NotesWidget(widget.order)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Attachments
|
// Attachments
|
||||||
@ -513,16 +554,15 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
InvenTreePurchaseOrderAttachment(),
|
InvenTreePurchaseOrderAttachment(),
|
||||||
widget.order.pk,
|
widget.order.pk,
|
||||||
widget.order.reference,
|
widget.order.reference,
|
||||||
widget.order.canEdit
|
widget.order.canEdit,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -530,7 +570,7 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
return [
|
return [
|
||||||
Tab(text: L10().details),
|
Tab(text: L10().details),
|
||||||
Tab(text: L10().lineItems),
|
Tab(text: L10().lineItems),
|
||||||
Tab(text: L10().received)
|
Tab(text: L10().received),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,18 +16,18 @@ import "package:inventree/inventree/purchase_order.dart";
|
|||||||
* Widget class for displaying a list of Purchase Orders
|
* Widget class for displaying a list of Purchase Orders
|
||||||
*/
|
*/
|
||||||
class PurchaseOrderListWidget extends StatefulWidget {
|
class PurchaseOrderListWidget extends StatefulWidget {
|
||||||
|
const PurchaseOrderListWidget({this.filters = const {}, Key? key})
|
||||||
const PurchaseOrderListWidget({this.filters = const {}, Key? key}) : super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
final Map<String, String> filters;
|
final Map<String, String> filters;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PurchaseOrderListWidgetState createState() => _PurchaseOrderListWidgetState();
|
_PurchaseOrderListWidgetState createState() =>
|
||||||
|
_PurchaseOrderListWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _PurchaseOrderListWidgetState
|
||||||
class _PurchaseOrderListWidgetState extends RefreshableState<PurchaseOrderListWidget> {
|
extends RefreshableState<PurchaseOrderListWidget> {
|
||||||
|
|
||||||
_PurchaseOrderListWidgetState();
|
_PurchaseOrderListWidgetState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -44,8 +44,8 @@ class _PurchaseOrderListWidgetState extends RefreshableState<PurchaseOrderListWi
|
|||||||
label: L10().purchaseOrderCreate,
|
label: L10().purchaseOrderCreate,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_createPurchaseOrder(context);
|
_createPurchaseOrder(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ class _PurchaseOrderListWidgetState extends RefreshableState<PurchaseOrderListWi
|
|||||||
var order = InvenTreePurchaseOrder.fromJson(data);
|
var order = InvenTreePurchaseOrder.fromJson(data);
|
||||||
order.goToDetailPage(context);
|
order.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,12 +84,9 @@ class _PurchaseOrderListWidgetState extends RefreshableState<PurchaseOrderListWi
|
|||||||
child: Icon(Icons.barcode_reader),
|
child: Icon(Icons.barcode_reader),
|
||||||
label: L10().scanReceivedParts,
|
label: L10().scanReceivedParts,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
scanBarcode(
|
scanBarcode(context, handler: POReceiveBarcodeHandler());
|
||||||
context,
|
|
||||||
handler: POReceiveBarcodeHandler(),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,22 +99,20 @@ class _PurchaseOrderListWidgetState extends RefreshableState<PurchaseOrderListWi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PaginatedPurchaseOrderList extends PaginatedSearchWidget {
|
class PaginatedPurchaseOrderList extends PaginatedSearchWidget {
|
||||||
|
const PaginatedPurchaseOrderList(Map<String, String> filters)
|
||||||
const PaginatedPurchaseOrderList(Map<String, String> filters) : super(filters: filters);
|
: super(filters: filters);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get searchTitle => L10().purchaseOrders;
|
String get searchTitle => L10().purchaseOrders;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PaginatedPurchaseOrderListState createState() => _PaginatedPurchaseOrderListState();
|
_PaginatedPurchaseOrderListState createState() =>
|
||||||
|
_PaginatedPurchaseOrderListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _PaginatedPurchaseOrderListState
|
||||||
class _PaginatedPurchaseOrderListState extends PaginatedSearchState<PaginatedPurchaseOrderList> {
|
extends PaginatedSearchState<PaginatedPurchaseOrderList> {
|
||||||
|
|
||||||
_PaginatedPurchaseOrderListState() : super();
|
_PaginatedPurchaseOrderListState() : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -147,21 +142,27 @@ class _PaginatedPurchaseOrderListState extends PaginatedSearchState<PaginatedPur
|
|||||||
"label": L10().assignedToMe,
|
"label": L10().assignedToMe,
|
||||||
"help_text": L10().assignedToMeDetail,
|
"help_text": L10().assignedToMeDetail,
|
||||||
"tristate": true,
|
"tristate": true,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
|
int limit,
|
||||||
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
await InvenTreeAPI().PurchaseOrderStatus.load();
|
await InvenTreeAPI().PurchaseOrderStatus.load();
|
||||||
final page = await InvenTreePurchaseOrder().listPaginated(limit, offset, filters: params);
|
final page = await InvenTreePurchaseOrder().listPaginated(
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
filters: params,
|
||||||
|
);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||||
|
|
||||||
InvenTreePurchaseOrder order = model as InvenTreePurchaseOrder;
|
InvenTreePurchaseOrder order = model as InvenTreePurchaseOrder;
|
||||||
|
|
||||||
InvenTreeCompany? supplier = order.supplier;
|
InvenTreeCompany? supplier = order.supplier;
|
||||||
@ -169,7 +170,9 @@ class _PaginatedPurchaseOrderListState extends PaginatedSearchState<PaginatedPur
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(order.reference),
|
title: Text(order.reference),
|
||||||
subtitle: Text(order.description),
|
subtitle: Text(order.description),
|
||||||
leading: supplier == null ? null : InvenTreeAPI().getThumbnail(supplier.thumbnail),
|
leading: supplier == null
|
||||||
|
? null
|
||||||
|
: InvenTreeAPI().getThumbnail(supplier.thumbnail),
|
||||||
trailing: Text(
|
trailing: Text(
|
||||||
InvenTreeAPI().PurchaseOrderStatus.label(order.status),
|
InvenTreeAPI().PurchaseOrderStatus.label(order.status),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter_speed_dial/flutter_speed_dial.dart";
|
import "package:flutter_speed_dial/flutter_speed_dial.dart";
|
||||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||||
@ -25,7 +24,6 @@ import "package:inventree/widget/progress.dart";
|
|||||||
* Widget for viewing a single SalesOrder instance
|
* Widget for viewing a single SalesOrder instance
|
||||||
*/
|
*/
|
||||||
class SalesOrderDetailWidget extends StatefulWidget {
|
class SalesOrderDetailWidget extends StatefulWidget {
|
||||||
|
|
||||||
const SalesOrderDetailWidget(this.order, {Key? key}) : super(key: key);
|
const SalesOrderDetailWidget(this.order, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
final InvenTreeSalesOrder order;
|
final InvenTreeSalesOrder order;
|
||||||
@ -34,9 +32,7 @@ class SalesOrderDetailWidget extends StatefulWidget {
|
|||||||
_SalesOrderDetailState createState() => _SalesOrderDetailState();
|
_SalesOrderDetailState createState() => _SalesOrderDetailState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
||||||
|
|
||||||
_SalesOrderDetailState();
|
_SalesOrderDetailState();
|
||||||
|
|
||||||
List<InvenTreeSOLineItem> lines = [];
|
List<InvenTreeSOLineItem> lines = [];
|
||||||
@ -68,7 +64,7 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
editOrder(context);
|
editOrder(context);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +73,6 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
|
|
||||||
// Add a new shipment against this sales order
|
// Add a new shipment against this sales order
|
||||||
Future<void> _addShipment(BuildContext context) async {
|
Future<void> _addShipment(BuildContext context) async {
|
||||||
|
|
||||||
var fields = InvenTreeSalesOrderShipment().formFields();
|
var fields = InvenTreeSalesOrderShipment().formFields();
|
||||||
|
|
||||||
fields["order"]?["value"] = widget.order.pk;
|
fields["order"]?["value"] = widget.order.pk;
|
||||||
@ -89,9 +84,8 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
fields: fields,
|
fields: fields,
|
||||||
onSuccess: (result) async {
|
onSuccess: (result) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a new line item to this sales order
|
// Add a new line item to this sales order
|
||||||
@ -107,23 +101,22 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
fields: fields,
|
fields: fields,
|
||||||
onSuccess: (result) async {
|
onSuccess: (result) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Upload an image for this order
|
/// Upload an image for this order
|
||||||
Future<void> _uploadImage(BuildContext context) async {
|
Future<void> _uploadImage(BuildContext context) async {
|
||||||
InvenTreeSalesOrderAttachment().uploadImage(
|
InvenTreeSalesOrderAttachment()
|
||||||
widget.order.pk,
|
.uploadImage(widget.order.pk, prefix: widget.order.reference)
|
||||||
prefix: widget.order.reference,
|
.then((result) => refresh(context));
|
||||||
).then((result) => refresh(context));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Issue this order
|
/// Issue this order
|
||||||
Future<void> _issueOrder(BuildContext context) async {
|
Future<void> _issueOrder(BuildContext context) async {
|
||||||
|
|
||||||
confirmationDialog(
|
confirmationDialog(
|
||||||
L10().issueOrder, "",
|
L10().issueOrder,
|
||||||
|
"",
|
||||||
icon: TablerIcons.send,
|
icon: TablerIcons.send,
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
acceptText: L10().issue,
|
acceptText: L10().issue,
|
||||||
@ -131,15 +124,15 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
widget.order.issueOrder().then((dynamic) {
|
widget.order.issueOrder().then((dynamic) {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Cancel this order
|
/// Cancel this order
|
||||||
Future<void> _cancelOrder(BuildContext context) async {
|
Future<void> _cancelOrder(BuildContext context) async {
|
||||||
|
|
||||||
confirmationDialog(
|
confirmationDialog(
|
||||||
L10().cancelOrder, "",
|
L10().cancelOrder,
|
||||||
|
"",
|
||||||
icon: TablerIcons.circle_x,
|
icon: TablerIcons.circle_x,
|
||||||
color: Colors.red,
|
color: Colors.red,
|
||||||
acceptText: L10().cancel,
|
acceptText: L10().cancel,
|
||||||
@ -147,7 +140,7 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
await widget.order.cancelOrder().then((dynamic) {
|
await widget.order.cancelOrder().then((dynamic) {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,8 +155,8 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
label: L10().takePicture,
|
label: L10().takePicture,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
_uploadImage(context);
|
_uploadImage(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,8 +167,8 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
label: L10().issueOrder,
|
label: L10().issueOrder,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
_issueOrder(context);
|
_issueOrder(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,21 +179,22 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
label: L10().cancelOrder,
|
label: L10().cancelOrder,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
_cancelOrder(context);
|
_cancelOrder(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add line item
|
// Add line item
|
||||||
if ((widget.order.isPending || widget.order.isInProgress) && InvenTreeSOLineItem().canCreate) {
|
if ((widget.order.isPending || widget.order.isInProgress) &&
|
||||||
|
InvenTreeSOLineItem().canCreate) {
|
||||||
actions.add(
|
actions.add(
|
||||||
SpeedDialChild(
|
SpeedDialChild(
|
||||||
child: Icon(TablerIcons.circle_plus, color: Colors.green),
|
child: Icon(TablerIcons.circle_plus, color: Colors.green),
|
||||||
label: L10().lineItemAdd,
|
label: L10().lineItemAdd,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
_addLineItem(context);
|
_addLineItem(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
actions.add(
|
actions.add(
|
||||||
@ -209,8 +203,8 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
label: L10().shipmentAdd,
|
label: L10().shipmentAdd,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
_addShipment(context);
|
_addShipment(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +215,8 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
List<SpeedDialChild> barcodeButtons(BuildContext context) {
|
List<SpeedDialChild> barcodeButtons(BuildContext context) {
|
||||||
List<SpeedDialChild> actions = [];
|
List<SpeedDialChild> actions = [];
|
||||||
|
|
||||||
if ((widget.order.isInProgress || widget.order.isPending) && InvenTreeSOLineItem().canCreate) {
|
if ((widget.order.isInProgress || widget.order.isPending) &&
|
||||||
|
InvenTreeSOLineItem().canCreate) {
|
||||||
actions.add(
|
actions.add(
|
||||||
SpeedDialChild(
|
SpeedDialChild(
|
||||||
child: Icon(Icons.barcode_reader),
|
child: Icon(Icons.barcode_reader),
|
||||||
@ -231,8 +226,8 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
context,
|
context,
|
||||||
handler: SOAddItemBarcodeHandler(salesOrder: widget.order),
|
handler: SOAddItemBarcodeHandler(salesOrder: widget.order),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (api.supportsBarcodeSOAllocateEndpoint) {
|
if (api.supportsBarcodeSOAllocateEndpoint) {
|
||||||
@ -243,12 +238,10 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
onTap: () async {
|
onTap: () async {
|
||||||
scanBarcode(
|
scanBarcode(
|
||||||
context,
|
context,
|
||||||
handler: SOAllocateStockHandler(
|
handler: SOAllocateStockHandler(salesOrder: widget.order),
|
||||||
salesOrder: widget.order,
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,10 +254,20 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
await widget.order.reload();
|
await widget.order.reload();
|
||||||
await api.SalesOrderStatus.load();
|
await api.SalesOrderStatus.load();
|
||||||
|
|
||||||
supportsProjectCodes = api.supportsProjectCodes && await api.getGlobalBooleanSetting("PROJECT_CODES_ENABLED", backup: true);
|
supportsProjectCodes =
|
||||||
showCameraShortcut = await InvenTreeSettingsManager().getBool(INV_SO_SHOW_CAMERA, true);
|
api.supportsProjectCodes &&
|
||||||
|
await api.getGlobalBooleanSetting(
|
||||||
|
"PROJECT_CODES_ENABLED",
|
||||||
|
backup: true,
|
||||||
|
);
|
||||||
|
showCameraShortcut = await InvenTreeSettingsManager().getBool(
|
||||||
|
INV_SO_SHOW_CAMERA,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
InvenTreeSalesOrderAttachment().countAttachments(widget.order.pk).then((int value) {
|
InvenTreeSalesOrderAttachment().countAttachments(widget.order.pk).then((
|
||||||
|
int value,
|
||||||
|
) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
attachmentCount = value;
|
attachmentCount = value;
|
||||||
@ -273,7 +276,9 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Count number of "extra line items" against this order
|
// Count number of "extra line items" against this order
|
||||||
InvenTreeSOExtraLineItem().count(filters: {"order": widget.order.pk.toString() }).then((int value) {
|
InvenTreeSOExtraLineItem()
|
||||||
|
.count(filters: {"order": widget.order.pk.toString()})
|
||||||
|
.then((int value) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
extraLineCount = value;
|
extraLineCount = value;
|
||||||
@ -305,7 +310,7 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
showSnackIcon(L10().salesOrderUpdated, success: true);
|
showSnackIcon(L10().salesOrderUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,62 +326,73 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
trailing: Text(
|
trailing: Text(
|
||||||
api.SalesOrderStatus.label(widget.order.status),
|
api.SalesOrderStatus.label(widget.order.status),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: api.SalesOrderStatus.color(widget.order.status)
|
color: api.SalesOrderStatus.color(widget.order.status),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> orderTiles(BuildContext context) {
|
List<Widget> orderTiles(BuildContext context) {
|
||||||
|
List<Widget> tiles = [headerTile(context)];
|
||||||
List<Widget> tiles = [
|
|
||||||
headerTile(context)
|
|
||||||
];
|
|
||||||
|
|
||||||
InvenTreeCompany? customer = widget.order.customer;
|
InvenTreeCompany? customer = widget.order.customer;
|
||||||
|
|
||||||
if (supportsProjectCodes && widget.order.hasProjectCode) {
|
if (supportsProjectCodes && widget.order.hasProjectCode) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().projectCode),
|
title: Text(L10().projectCode),
|
||||||
subtitle: Text("${widget.order.projectCode} - ${widget.order.projectCodeDescription}"),
|
subtitle: Text(
|
||||||
|
"${widget.order.projectCode} - ${widget.order.projectCodeDescription}",
|
||||||
|
),
|
||||||
leading: Icon(TablerIcons.list),
|
leading: Icon(TablerIcons.list),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customer != null) {
|
if (customer != null) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().customer),
|
title: Text(L10().customer),
|
||||||
subtitle: Text(customer.name),
|
subtitle: Text(customer.name),
|
||||||
leading: Icon(TablerIcons.user, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.user, color: COLOR_ACTION),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
customer.goToDetailPage(context);
|
customer.goToDetailPage(context);
|
||||||
}
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.order.customerReference.isNotEmpty) {
|
if (widget.order.customerReference.isNotEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().customerReference),
|
title: Text(L10().customerReference),
|
||||||
trailing: Text(widget.order.customerReference),
|
trailing: Text(widget.order.customerReference),
|
||||||
leading: Icon(TablerIcons.hash),
|
leading: Icon(TablerIcons.hash),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Color lineColor = widget.order.complete ? COLOR_SUCCESS : COLOR_WARNING;
|
Color lineColor = widget.order.complete ? COLOR_SUCCESS : COLOR_WARNING;
|
||||||
|
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().lineItems),
|
title: Text(L10().lineItems),
|
||||||
subtitle: ProgressBar(
|
subtitle: ProgressBar(
|
||||||
widget.order.completedLineItemCount.toDouble(),
|
widget.order.completedLineItemCount.toDouble(),
|
||||||
maximum: widget.order.lineItemCount.toDouble()
|
maximum: widget.order.lineItemCount.toDouble(),
|
||||||
),
|
),
|
||||||
leading: Icon(TablerIcons.clipboard_check),
|
leading: Icon(TablerIcons.clipboard_check),
|
||||||
trailing: Text("${widget.order.completedLineItemCount} / ${widget.order.lineItemCount}", style: TextStyle(color: lineColor)),
|
trailing: Text(
|
||||||
));
|
"${widget.order.completedLineItemCount} / ${widget.order.lineItemCount}",
|
||||||
|
style: TextStyle(color: lineColor),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
// Extra line items
|
// Extra line items
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().extraLineItems),
|
title: Text(L10().extraLineItems),
|
||||||
leading: Icon(TablerIcons.clipboard_list, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.clipboard_list, color: COLOR_ACTION),
|
||||||
trailing: Text(extraLineCount.toString()),
|
trailing: Text(extraLineCount.toString()),
|
||||||
@ -384,58 +400,80 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => SOExtraLineListWidget(widget.order, filters: {"order": widget.order.pk.toString()})
|
builder: (context) => SOExtraLineListWidget(
|
||||||
)
|
widget.order,
|
||||||
)
|
filters: {"order": widget.order.pk.toString()},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
},
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
|
|
||||||
// Shipment progress
|
// Shipment progress
|
||||||
if (widget.order.shipmentCount > 0) {
|
if (widget.order.shipmentCount > 0) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().shipments),
|
title: Text(L10().shipments),
|
||||||
subtitle: ProgressBar(
|
subtitle: ProgressBar(
|
||||||
widget.order.completedShipmentCount.toDouble(),
|
widget.order.completedShipmentCount.toDouble(),
|
||||||
maximum: widget.order.shipmentCount.toDouble()
|
maximum: widget.order.shipmentCount.toDouble(),
|
||||||
),
|
),
|
||||||
leading: Icon(TablerIcons.truck_delivery),
|
leading: Icon(TablerIcons.truck_delivery),
|
||||||
trailing: Text("${widget.order.completedShipmentCount} / ${widget.order.shipmentCount}", style: TextStyle(color: lineColor)),
|
trailing: Text(
|
||||||
));
|
"${widget.order.completedShipmentCount} / ${widget.order.shipmentCount}",
|
||||||
|
style: TextStyle(color: lineColor),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: total price
|
// TODO: total price
|
||||||
|
|
||||||
if (widget.order.startDate.isNotEmpty) {
|
if (widget.order.startDate.isNotEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().startDate),
|
title: Text(L10().startDate),
|
||||||
trailing: Text(widget.order.startDate),
|
trailing: Text(widget.order.startDate),
|
||||||
leading: Icon(TablerIcons.calendar),
|
leading: Icon(TablerIcons.calendar),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.order.targetDate.isNotEmpty) {
|
if (widget.order.targetDate.isNotEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().targetDate),
|
title: Text(L10().targetDate),
|
||||||
trailing: Text(widget.order.targetDate),
|
trailing: Text(widget.order.targetDate),
|
||||||
leading: Icon(TablerIcons.calendar),
|
leading: Icon(TablerIcons.calendar),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.order.shipmentDate.isNotEmpty) {
|
if (widget.order.shipmentDate.isNotEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().completionDate),
|
title: Text(L10().completionDate),
|
||||||
trailing: Text(widget.order.shipmentDate),
|
trailing: Text(widget.order.shipmentDate),
|
||||||
leading: Icon(TablerIcons.calendar),
|
leading: Icon(TablerIcons.calendar),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Responsible "owner"
|
// Responsible "owner"
|
||||||
if (widget.order.responsibleName.isNotEmpty && widget.order.responsibleLabel.isNotEmpty) {
|
if (widget.order.responsibleName.isNotEmpty &&
|
||||||
tiles.add(ListTile(
|
widget.order.responsibleLabel.isNotEmpty) {
|
||||||
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().responsible),
|
title: Text(L10().responsible),
|
||||||
leading: Icon(widget.order.responsibleLabel == "group" ? TablerIcons.users : TablerIcons.user),
|
leading: Icon(
|
||||||
trailing: Text(widget.order.responsibleName)
|
widget.order.responsibleLabel == "group"
|
||||||
));
|
? TablerIcons.users
|
||||||
|
: TablerIcons.user,
|
||||||
|
),
|
||||||
|
trailing: Text(widget.order.responsibleName),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notes tile
|
// Notes tile
|
||||||
@ -446,12 +484,10 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => NotesWidget(widget.order)),
|
||||||
builder: (context) => NotesWidget(widget.order)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Attachments
|
// Attachments
|
||||||
@ -468,12 +504,12 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
InvenTreeSalesOrderAttachment(),
|
InvenTreeSalesOrderAttachment(),
|
||||||
widget.order.pk,
|
widget.order.pk,
|
||||||
widget.order.reference,
|
widget.order.reference,
|
||||||
widget.order.canEdit
|
widget.order.canEdit,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
@ -496,5 +532,4 @@ class _SalesOrderDetailState extends RefreshableState<SalesOrderDetailWidget> {
|
|||||||
PaginatedSOShipmentList({"order": widget.order.pk.toString()}),
|
PaginatedSOShipmentList({"order": widget.order.pk.toString()}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter_speed_dial/flutter_speed_dial.dart";
|
import "package:flutter_speed_dial/flutter_speed_dial.dart";
|
||||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||||
@ -12,20 +11,18 @@ import "package:inventree/api.dart";
|
|||||||
import "package:inventree/inventree/company.dart";
|
import "package:inventree/inventree/company.dart";
|
||||||
import "package:inventree/inventree/model.dart";
|
import "package:inventree/inventree/model.dart";
|
||||||
|
|
||||||
|
|
||||||
class SalesOrderListWidget extends StatefulWidget {
|
class SalesOrderListWidget extends StatefulWidget {
|
||||||
|
const SalesOrderListWidget({this.filters = const {}, Key? key})
|
||||||
const SalesOrderListWidget({this.filters = const {}, Key? key}) : super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
final Map<String, String> filters;
|
final Map<String, String> filters;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_SalesOrderListWidgetState createState() => _SalesOrderListWidgetState();
|
_SalesOrderListWidgetState createState() => _SalesOrderListWidgetState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SalesOrderListWidgetState extends RefreshableState<SalesOrderListWidget> {
|
class _SalesOrderListWidgetState
|
||||||
|
extends RefreshableState<SalesOrderListWidget> {
|
||||||
_SalesOrderListWidgetState();
|
_SalesOrderListWidgetState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -42,8 +39,8 @@ class _SalesOrderListWidgetState extends RefreshableState<SalesOrderListWidget>
|
|||||||
label: L10().salesOrderCreate,
|
label: L10().salesOrderCreate,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_createSalesOrder(context);
|
_createSalesOrder(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +65,7 @@ class _SalesOrderListWidgetState extends RefreshableState<SalesOrderListWidget>
|
|||||||
var order = InvenTreeSalesOrder.fromJson(data);
|
var order = InvenTreeSalesOrder.fromJson(data);
|
||||||
order.goToDetailPage(context);
|
order.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,25 +79,22 @@ class _SalesOrderListWidgetState extends RefreshableState<SalesOrderListWidget>
|
|||||||
Widget getBody(BuildContext context) {
|
Widget getBody(BuildContext context) {
|
||||||
return PaginatedSalesOrderList(widget.filters);
|
return PaginatedSalesOrderList(widget.filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PaginatedSalesOrderList extends PaginatedSearchWidget {
|
class PaginatedSalesOrderList extends PaginatedSearchWidget {
|
||||||
|
const PaginatedSalesOrderList(Map<String, String> filters)
|
||||||
const PaginatedSalesOrderList(Map<String, String> filters) : super(filters: filters);
|
: super(filters: filters);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get searchTitle => L10().salesOrders;
|
String get searchTitle => L10().salesOrders;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PaginatedSalesOrderListState createState() => _PaginatedSalesOrderListState();
|
_PaginatedSalesOrderListState createState() =>
|
||||||
|
_PaginatedSalesOrderListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _PaginatedSalesOrderListState
|
||||||
class _PaginatedSalesOrderListState extends PaginatedSearchState<PaginatedSalesOrderList> {
|
extends PaginatedSearchState<PaginatedSalesOrderList> {
|
||||||
|
|
||||||
_PaginatedSalesOrderListState() : super();
|
_PaginatedSalesOrderListState() : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -130,21 +124,27 @@ class _PaginatedSalesOrderListState extends PaginatedSearchState<PaginatedSalesO
|
|||||||
"label": L10().assignedToMe,
|
"label": L10().assignedToMe,
|
||||||
"help_text": L10().assignedToMeDetail,
|
"help_text": L10().assignedToMeDetail,
|
||||||
"tristate": true,
|
"tristate": true,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
|
int limit,
|
||||||
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
await InvenTreeAPI().SalesOrderStatus.load();
|
await InvenTreeAPI().SalesOrderStatus.load();
|
||||||
final page = await InvenTreeSalesOrder().listPaginated(limit, offset, filters: params);
|
final page = await InvenTreeSalesOrder().listPaginated(
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
filters: params,
|
||||||
|
);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||||
|
|
||||||
InvenTreeSalesOrder order = model as InvenTreeSalesOrder;
|
InvenTreeSalesOrder order = model as InvenTreeSalesOrder;
|
||||||
|
|
||||||
InvenTreeCompany? customer = order.customer;
|
InvenTreeCompany? customer = order.customer;
|
||||||
@ -152,18 +152,18 @@ class _PaginatedSalesOrderListState extends PaginatedSearchState<PaginatedSalesO
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(order.reference),
|
title: Text(order.reference),
|
||||||
subtitle: Text(order.description),
|
subtitle: Text(order.description),
|
||||||
leading: customer == null ? null : InvenTreeAPI().getThumbnail(customer.thumbnail),
|
leading: customer == null
|
||||||
|
? null
|
||||||
|
: InvenTreeAPI().getThumbnail(customer.thumbnail),
|
||||||
trailing: Text(
|
trailing: Text(
|
||||||
InvenTreeAPI().SalesOrderStatus.label(order.status),
|
InvenTreeAPI().SalesOrderStatus.label(order.status),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: InvenTreeAPI().SalesOrderStatus.color(order.status),
|
color: InvenTreeAPI().SalesOrderStatus.color(order.status),
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
order.goToDetailPage(context);
|
order.goToDetailPage(context);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -11,28 +11,27 @@ import "package:inventree/widget/paginator.dart";
|
|||||||
import "package:inventree/widget/refreshable_state.dart";
|
import "package:inventree/widget/refreshable_state.dart";
|
||||||
import "package:inventree/widget/snacks.dart";
|
import "package:inventree/widget/snacks.dart";
|
||||||
|
|
||||||
|
|
||||||
class SOExtraLineListWidget extends StatefulWidget {
|
class SOExtraLineListWidget extends StatefulWidget {
|
||||||
|
const SOExtraLineListWidget(this.order, {this.filters = const {}, Key? key})
|
||||||
const SOExtraLineListWidget(this.order, {this.filters = const {}, Key? key}) : super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
final InvenTreeSalesOrder order;
|
final InvenTreeSalesOrder order;
|
||||||
|
|
||||||
final Map<String, String> filters;
|
final Map<String, String> filters;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_SalesOrderExtraLineListWidgetState createState() => _SalesOrderExtraLineListWidgetState();
|
_SalesOrderExtraLineListWidgetState createState() =>
|
||||||
|
_SalesOrderExtraLineListWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SalesOrderExtraLineListWidgetState extends RefreshableState<SOExtraLineListWidget> {
|
class _SalesOrderExtraLineListWidgetState
|
||||||
|
extends RefreshableState<SOExtraLineListWidget> {
|
||||||
_SalesOrderExtraLineListWidgetState();
|
_SalesOrderExtraLineListWidgetState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getAppBarTitle() => L10().extraLineItems;
|
String getAppBarTitle() => L10().extraLineItems;
|
||||||
|
|
||||||
Future<void> _addLineItem(BuildContext context) async {
|
Future<void> _addLineItem(BuildContext context) async {
|
||||||
|
|
||||||
var fields = InvenTreeSOExtraLineItem().formFields();
|
var fields = InvenTreeSOExtraLineItem().formFields();
|
||||||
|
|
||||||
fields["order"]?["value"] = widget.order.pk;
|
fields["order"]?["value"] = widget.order.pk;
|
||||||
@ -44,7 +43,7 @@ class _SalesOrderExtraLineListWidgetState extends RefreshableState<SOExtraLineLi
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
showSnackIcon(L10().lineItemUpdated, success: true);
|
showSnackIcon(L10().lineItemUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,8 +58,8 @@ class _SalesOrderExtraLineListWidgetState extends RefreshableState<SOExtraLineLi
|
|||||||
label: L10().lineItemAdd,
|
label: L10().lineItemAdd,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_addLineItem(context);
|
_addLineItem(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,35 +72,41 @@ class _SalesOrderExtraLineListWidgetState extends RefreshableState<SOExtraLineLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PaginatedSOExtraLineList extends PaginatedSearchWidget {
|
class PaginatedSOExtraLineList extends PaginatedSearchWidget {
|
||||||
|
const PaginatedSOExtraLineList(Map<String, String> filters)
|
||||||
const PaginatedSOExtraLineList(Map<String, String> filters) : super(filters: filters);
|
: super(filters: filters);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get searchTitle => L10().extraLineItems;
|
String get searchTitle => L10().extraLineItems;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PaginatedSOExtraLineListState createState() => _PaginatedSOExtraLineListState();
|
_PaginatedSOExtraLineListState createState() =>
|
||||||
|
_PaginatedSOExtraLineListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PaginatedSOExtraLineListState extends PaginatedSearchState<PaginatedSOExtraLineList> {
|
class _PaginatedSOExtraLineListState
|
||||||
|
extends PaginatedSearchState<PaginatedSOExtraLineList> {
|
||||||
_PaginatedSOExtraLineListState() : super();
|
_PaginatedSOExtraLineListState() : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get prefix => "so_extra_line_";
|
String get prefix => "so_extra_line_";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
final page = await InvenTreeSOExtraLineItem().listPaginated(limit, offset, filters: params);
|
int limit,
|
||||||
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
|
final page = await InvenTreeSOExtraLineItem().listPaginated(
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
filters: params,
|
||||||
|
);
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||||
|
|
||||||
InvenTreeSOExtraLineItem line = model as InvenTreeSOExtraLineItem;
|
InvenTreeSOExtraLineItem line = model as InvenTreeSOExtraLineItem;
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Widget for displaying detail view of a single SalesOrderLineItem
|
* Widget for displaying detail view of a single SalesOrderLineItem
|
||||||
*/
|
*/
|
||||||
@ -22,21 +20,16 @@ import "package:inventree/l10.dart";
|
|||||||
import "package:inventree/helpers.dart";
|
import "package:inventree/helpers.dart";
|
||||||
import "package:inventree/api_form.dart";
|
import "package:inventree/api_form.dart";
|
||||||
|
|
||||||
|
|
||||||
class SoLineDetailWidget extends StatefulWidget {
|
class SoLineDetailWidget extends StatefulWidget {
|
||||||
|
|
||||||
const SoLineDetailWidget(this.item, {Key? key}) : super(key: key);
|
const SoLineDetailWidget(this.item, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
final InvenTreeSOLineItem item;
|
final InvenTreeSOLineItem item;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_SOLineDetailWidgetState createState() => _SOLineDetailWidgetState();
|
_SOLineDetailWidgetState createState() => _SOLineDetailWidgetState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
||||||
|
|
||||||
_SOLineDetailWidgetState();
|
_SOLineDetailWidgetState();
|
||||||
|
|
||||||
InvenTreeSalesOrder? order;
|
InvenTreeSalesOrder? order;
|
||||||
@ -54,7 +47,8 @@ class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
|||||||
icon: Icon(TablerIcons.edit),
|
icon: Icon(TablerIcons.edit),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_editLineItem(context);
|
_editLineItem(context);
|
||||||
}),
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +56,6 @@ class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _allocateStock(BuildContext context) async {
|
Future<void> _allocateStock(BuildContext context) async {
|
||||||
|
|
||||||
if (order == null) {
|
if (order == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -73,12 +66,10 @@ class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
|||||||
fields["stock_item"]?["filters"] = {
|
fields["stock_item"]?["filters"] = {
|
||||||
"in_stock": true,
|
"in_stock": true,
|
||||||
"available": true,
|
"available": true,
|
||||||
"part": widget.item.partId.toString()
|
"part": widget.item.partId.toString(),
|
||||||
};
|
};
|
||||||
fields["quantity"]?["value"] = widget.item.unallocatedQuantity.toString();
|
fields["quantity"]?["value"] = widget.item.unallocatedQuantity.toString();
|
||||||
fields["shipment"]?["filters"] = {
|
fields["shipment"]?["filters"] = {"order": order!.pk.toString()};
|
||||||
"order": order!.pk.toString()
|
|
||||||
};
|
|
||||||
|
|
||||||
launchApiForm(
|
launchApiForm(
|
||||||
context,
|
context,
|
||||||
@ -89,9 +80,8 @@ class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
|||||||
icon: TablerIcons.transition_right,
|
icon: TablerIcons.transition_right,
|
||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _editLineItem(BuildContext context) async {
|
Future<void> _editLineItem(BuildContext context) async {
|
||||||
@ -109,13 +99,12 @@ class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
showSnackIcon(L10().lineItemUpdated, success: true);
|
showSnackIcon(L10().lineItemUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<SpeedDialChild> actionButtons(BuildContext context) {
|
List<SpeedDialChild> actionButtons(BuildContext context) {
|
||||||
|
|
||||||
List<SpeedDialChild> buttons = [];
|
List<SpeedDialChild> buttons = [];
|
||||||
|
|
||||||
if (order != null && order!.isOpen) {
|
if (order != null && order!.isOpen) {
|
||||||
@ -125,8 +114,8 @@ class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
|||||||
label: L10().allocateStock,
|
label: L10().allocateStock,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
_allocateStock(context);
|
_allocateStock(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +127,6 @@ class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
|||||||
List<SpeedDialChild> actions = [];
|
List<SpeedDialChild> actions = [];
|
||||||
|
|
||||||
if (order != null && order!.isOpen && InvenTreeSOLineItem().canCreate) {
|
if (order != null && order!.isOpen && InvenTreeSOLineItem().canCreate) {
|
||||||
|
|
||||||
if (api.supportsBarcodeSOAllocateEndpoint) {
|
if (api.supportsBarcodeSOAllocateEndpoint) {
|
||||||
actions.add(
|
actions.add(
|
||||||
SpeedDialChild(
|
SpeedDialChild(
|
||||||
@ -149,11 +137,11 @@ class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
|||||||
context,
|
context,
|
||||||
handler: SOAllocateStockHandler(
|
handler: SOAllocateStockHandler(
|
||||||
salesOrder: order,
|
salesOrder: order,
|
||||||
lineItem: widget.item
|
lineItem: widget.item,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,8 +181,8 @@ class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
|||||||
if (part is InvenTreePart) {
|
if (part is InvenTreePart) {
|
||||||
part.goToDetailPage(context);
|
part.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Available quantity
|
// Available quantity
|
||||||
@ -202,8 +190,8 @@ class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().availableStock),
|
title: Text(L10().availableStock),
|
||||||
leading: Icon(TablerIcons.packages),
|
leading: Icon(TablerIcons.packages),
|
||||||
trailing: Text(simpleNumberString(widget.item.availableStock))
|
trailing: Text(simpleNumberString(widget.item.availableStock)),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Allocated quantity
|
// Allocated quantity
|
||||||
@ -215,10 +203,10 @@ class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
|||||||
trailing: Text(
|
trailing: Text(
|
||||||
widget.item.allocatedString,
|
widget.item.allocatedString,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: widget.item.isAllocated ? COLOR_SUCCESS : COLOR_WARNING
|
color: widget.item.isAllocated ? COLOR_SUCCESS : COLOR_WARNING,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Shipped quantity
|
// Shipped quantity
|
||||||
@ -229,11 +217,11 @@ class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
|||||||
trailing: Text(
|
trailing: Text(
|
||||||
widget.item.progressString,
|
widget.item.progressString,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: widget.item.isComplete ? COLOR_SUCCESS : COLOR_WARNING
|
color: widget.item.isComplete ? COLOR_SUCCESS : COLOR_WARNING,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
leading: Icon(TablerIcons.truck)
|
leading: Icon(TablerIcons.truck),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Reference
|
// Reference
|
||||||
@ -242,8 +230,8 @@ class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().reference),
|
title: Text(L10().reference),
|
||||||
subtitle: Text(widget.item.reference),
|
subtitle: Text(widget.item.reference),
|
||||||
leading: Icon(TablerIcons.hash)
|
leading: Icon(TablerIcons.hash),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,7 +242,7 @@ class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
|||||||
title: Text(L10().notes),
|
title: Text(L10().notes),
|
||||||
subtitle: Text(widget.item.notes),
|
subtitle: Text(widget.item.notes),
|
||||||
leading: Icon(TablerIcons.note),
|
leading: Icon(TablerIcons.note),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,7 +256,7 @@ class _SOLineDetailWidgetState extends RefreshableState<SoLineDetailWidget> {
|
|||||||
onTap: () async {
|
onTap: () async {
|
||||||
await openLink(widget.item.link);
|
await openLink(widget.item.link);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,28 +9,26 @@ import "package:inventree/api.dart";
|
|||||||
import "package:inventree/app_colors.dart";
|
import "package:inventree/app_colors.dart";
|
||||||
import "package:inventree/widget/progress.dart";
|
import "package:inventree/widget/progress.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Paginated widget class for displaying a list of sales order line items
|
* Paginated widget class for displaying a list of sales order line items
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class PaginatedSOLineList extends PaginatedSearchWidget {
|
class PaginatedSOLineList extends PaginatedSearchWidget {
|
||||||
const PaginatedSOLineList(Map<String, String> filters) : super(filters: filters);
|
const PaginatedSOLineList(Map<String, String> filters)
|
||||||
|
: super(filters: filters);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get searchTitle => L10().lineItems;
|
String get searchTitle => L10().lineItems;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PaginatedSOLineListState createState() => _PaginatedSOLineListState();
|
_PaginatedSOLineListState createState() => _PaginatedSOLineListState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* State class for PaginatedSOLineList
|
* State class for PaginatedSOLineList
|
||||||
*/
|
*/
|
||||||
class _PaginatedSOLineListState extends PaginatedSearchState<PaginatedSOLineList> {
|
class _PaginatedSOLineListState
|
||||||
|
extends PaginatedSearchState<PaginatedSOLineList> {
|
||||||
_PaginatedSOLineListState() : super();
|
_PaginatedSOLineListState() : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -43,13 +41,19 @@ class _PaginatedSOLineListState extends PaginatedSearchState<PaginatedSOLineList
|
|||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, Map<String, dynamic>> get filterOptions => {
|
Map<String, Map<String, dynamic>> get filterOptions => {};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
final page = await InvenTreeSOLineItem().listPaginated(limit, offset, filters: params);
|
int limit,
|
||||||
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
|
final page = await InvenTreeSOLineItem().listPaginated(
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
filters: params,
|
||||||
|
);
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,24 +67,30 @@ class _PaginatedSOLineListState extends PaginatedSearchState<PaginatedSOLineList
|
|||||||
title: Text(part.name),
|
title: Text(part.name),
|
||||||
subtitle: Text(part.description),
|
subtitle: Text(part.description),
|
||||||
leading: InvenTreeAPI().getThumbnail(part.thumbnail),
|
leading: InvenTreeAPI().getThumbnail(part.thumbnail),
|
||||||
trailing: Text(item.progressString, style: TextStyle(color: item.isComplete ? COLOR_SUCCESS : COLOR_WARNING)),
|
trailing: Text(
|
||||||
|
item.progressString,
|
||||||
|
style: TextStyle(
|
||||||
|
color: item.isComplete ? COLOR_SUCCESS : COLOR_WARNING,
|
||||||
|
),
|
||||||
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
await item.reload();
|
await item.reload();
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => SoLineDetailWidget(item)),
|
||||||
builder: (context) => SoLineDetailWidget(item))
|
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(L10().error),
|
title: Text(L10().error),
|
||||||
subtitle: Text("Missing part detail", style: TextStyle(color: COLOR_DANGER)),
|
subtitle: Text(
|
||||||
|
"Missing part detail",
|
||||||
|
style: TextStyle(color: COLOR_DANGER),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||||
import "package:inventree/app_colors.dart";
|
import "package:inventree/app_colors.dart";
|
||||||
@ -9,19 +8,19 @@ import "package:inventree/inventree/model.dart";
|
|||||||
import "package:inventree/l10.dart";
|
import "package:inventree/l10.dart";
|
||||||
|
|
||||||
class PaginatedSOShipmentList extends PaginatedSearchWidget {
|
class PaginatedSOShipmentList extends PaginatedSearchWidget {
|
||||||
|
const PaginatedSOShipmentList(Map<String, String> filters)
|
||||||
const PaginatedSOShipmentList(Map<String, String> filters) : super(filters: filters);
|
: super(filters: filters);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get searchTitle => L10().shipments;
|
String get searchTitle => L10().shipments;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PaginatedSOShipmentListState createState() => _PaginatedSOShipmentListState();
|
_PaginatedSOShipmentListState createState() =>
|
||||||
|
_PaginatedSOShipmentListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _PaginatedSOShipmentListState
|
||||||
class _PaginatedSOShipmentListState extends PaginatedSearchState<PaginatedSOShipmentList> {
|
extends PaginatedSearchState<PaginatedSOShipmentList> {
|
||||||
|
|
||||||
_PaginatedSOShipmentListState() : super();
|
_PaginatedSOShipmentListState() : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -34,22 +33,30 @@ class _PaginatedSOShipmentListState extends PaginatedSearchState<PaginatedSOShip
|
|||||||
Map<String, Map<String, dynamic>> get filterOptions => {};
|
Map<String, Map<String, dynamic>> get filterOptions => {};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
final page = await InvenTreeSalesOrderShipment().listPaginated(limit, offset, filters: params);
|
int limit,
|
||||||
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
|
final page = await InvenTreeSalesOrderShipment().listPaginated(
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
filters: params,
|
||||||
|
);
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||||
|
|
||||||
InvenTreeSalesOrderShipment shipment = model as InvenTreeSalesOrderShipment;
|
InvenTreeSalesOrderShipment shipment = model as InvenTreeSalesOrderShipment;
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(shipment.reference),
|
title: Text(shipment.reference),
|
||||||
subtitle: Text(shipment.tracking_number),
|
subtitle: Text(shipment.tracking_number),
|
||||||
leading: shipment.shipped ? Icon(TablerIcons.calendar_check, color: COLOR_SUCCESS) : Icon(TablerIcons.calendar_cancel, color: COLOR_WARNING),
|
leading: shipment.shipped
|
||||||
trailing: shipment.shipped ? Text(shipment.shipment_date ?? "") : null
|
? Icon(TablerIcons.calendar_check, color: COLOR_SUCCESS)
|
||||||
|
: Icon(TablerIcons.calendar_cancel, color: COLOR_WARNING),
|
||||||
|
trailing: shipment.shipped ? Text(shipment.shipment_date ?? "") : null,
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,12 +15,10 @@ import "package:inventree/preferences.dart";
|
|||||||
|
|
||||||
import "package:inventree/widget/refreshable_state.dart";
|
import "package:inventree/widget/refreshable_state.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Abstract base widget class for rendering a PaginatedSearchState
|
* Abstract base widget class for rendering a PaginatedSearchState
|
||||||
*/
|
*/
|
||||||
abstract class PaginatedSearchWidget extends StatefulWidget {
|
abstract class PaginatedSearchWidget extends StatefulWidget {
|
||||||
|
|
||||||
const PaginatedSearchWidget({this.filters = const {}, this.title = ""});
|
const PaginatedSearchWidget({this.filters = const {}, this.title = ""});
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
@ -30,12 +28,12 @@ abstract class PaginatedSearchWidget extends StatefulWidget {
|
|||||||
final Map<String, String> filters;
|
final Map<String, String> filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic stateful widget for displaying paginated data retrieved via the API
|
* Generic stateful widget for displaying paginated data retrieved via the API
|
||||||
*/
|
*/
|
||||||
abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends State<T> with BaseWidgetProperties {
|
abstract class PaginatedSearchState<T extends PaginatedSearchWidget>
|
||||||
|
extends State<T>
|
||||||
|
with BaseWidgetProperties {
|
||||||
static const _pageSize = 25;
|
static const _pageSize = 25;
|
||||||
|
|
||||||
bool showSearchWidget = false;
|
bool showSearchWidget = false;
|
||||||
@ -73,7 +71,6 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
|
|
||||||
// Construct the boolean filter options for this list
|
// Construct the boolean filter options for this list
|
||||||
Future<Map<String, String>> constructFilters() async {
|
Future<Map<String, String>> constructFilters() async {
|
||||||
|
|
||||||
Map<String, String> f = {};
|
Map<String, String> f = {};
|
||||||
|
|
||||||
for (String k in filterOptions.keys) {
|
for (String k in filterOptions.keys) {
|
||||||
@ -95,7 +92,10 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
|
|
||||||
// Return the selected ordering "field" for this list widget
|
// Return the selected ordering "field" for this list widget
|
||||||
Future<String> orderingField() async {
|
Future<String> orderingField() async {
|
||||||
dynamic field = await InvenTreeSettingsManager().getValue("${prefix}ordering_field", null);
|
dynamic field = await InvenTreeSettingsManager().getValue(
|
||||||
|
"${prefix}ordering_field",
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
if (field != null && orderingOptions.containsKey(field.toString())) {
|
if (field != null && orderingOptions.containsKey(field.toString())) {
|
||||||
// A valid ordering field has been found
|
// A valid ordering field has been found
|
||||||
@ -110,7 +110,10 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
|
|
||||||
// Return the selected ordering "order" ("+" or "-") for this list widget
|
// Return the selected ordering "order" ("+" or "-") for this list widget
|
||||||
Future<String> orderingOrder() async {
|
Future<String> orderingOrder() async {
|
||||||
dynamic order = await InvenTreeSettingsManager().getValue("${prefix}ordering_order", "+");
|
dynamic order = await InvenTreeSettingsManager().getValue(
|
||||||
|
"${prefix}ordering_order",
|
||||||
|
"+",
|
||||||
|
);
|
||||||
|
|
||||||
return order == "+" ? "+" : "-";
|
return order == "+" ? "+" : "-";
|
||||||
}
|
}
|
||||||
@ -137,10 +140,10 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
// Construct the 'ordering' options
|
// Construct the 'ordering' options
|
||||||
List<Map<String, dynamic>> _opts = [];
|
List<Map<String, dynamic>> _opts = [];
|
||||||
|
|
||||||
orderingOptions.forEach((k, v) => _opts.add({
|
orderingOptions.forEach(
|
||||||
"value": k.toString(),
|
(k, v) =>
|
||||||
"display_name": v.toString()
|
_opts.add({"value": k.toString(), "display_name": v.toString()}),
|
||||||
}));
|
);
|
||||||
|
|
||||||
if (_field == null && _opts.isNotEmpty) {
|
if (_field == null && _opts.isNotEmpty) {
|
||||||
_field = _opts.first["value"];
|
_field = _opts.first["value"];
|
||||||
@ -160,16 +163,10 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
"required": true,
|
"required": true,
|
||||||
"value": _order,
|
"value": _order,
|
||||||
"choices": [
|
"choices": [
|
||||||
{
|
{"value": "+", "display_name": "Ascending"},
|
||||||
"value": "+",
|
{"value": "-", "display_name": "Descending"},
|
||||||
"display_name": "Ascending",
|
],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"value": "-",
|
|
||||||
"display_name": "Descending",
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add in selected filter options
|
// Add in selected filter options
|
||||||
@ -219,7 +216,6 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
fields,
|
fields,
|
||||||
icon: TablerIcons.circle_check,
|
icon: TablerIcons.circle_check,
|
||||||
onSuccess: (Map<String, dynamic> data) async {
|
onSuccess: (Map<String, dynamic> data) async {
|
||||||
|
|
||||||
// Extract data from the processed form
|
// Extract data from the processed form
|
||||||
String f = (data["ordering_field"] ?? _field) as String;
|
String f = (data["ordering_field"] ?? _field) as String;
|
||||||
String o = (data["ordering_order"] ?? _order) as String;
|
String o = (data["ordering_order"] ?? _order) as String;
|
||||||
@ -235,7 +231,7 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
|
|
||||||
// Refresh data from the server
|
// Refresh data from the server
|
||||||
_pagingController.refresh();
|
_pagingController.refresh();
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +241,6 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
int resultCount = 0;
|
int resultCount = 0;
|
||||||
|
|
||||||
String resultsString() {
|
String resultsString() {
|
||||||
|
|
||||||
if (resultCount <= 0) {
|
if (resultCount <= 0) {
|
||||||
return noResultsText;
|
return noResultsText;
|
||||||
} else {
|
} else {
|
||||||
@ -260,7 +255,8 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
Timer? _debounceTimer;
|
Timer? _debounceTimer;
|
||||||
|
|
||||||
// Pagination controller
|
// Pagination controller
|
||||||
final PagingController<int, InvenTreeModel> _pagingController = PagingController(firstPageKey: 0);
|
final PagingController<int, InvenTreeModel> _pagingController =
|
||||||
|
PagingController(firstPageKey: 0);
|
||||||
|
|
||||||
void refresh() {
|
void refresh() {
|
||||||
_pagingController.refresh();
|
_pagingController.refresh();
|
||||||
@ -286,8 +282,11 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
* Each implementing class must override this function,
|
* Each implementing class must override this function,
|
||||||
* and return an InvenTreePageResponse object with the correct data format
|
* and return an InvenTreePageResponse object with the correct data format
|
||||||
*/
|
*/
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
|
int limit,
|
||||||
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
// Default implementation returns null - must be overridden
|
// Default implementation returns null - must be overridden
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -301,7 +300,6 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
|
|
||||||
// Include user search term
|
// Include user search term
|
||||||
if (searchTerm.isNotEmpty) {
|
if (searchTerm.isNotEmpty) {
|
||||||
|
|
||||||
String _search = searchTerm;
|
String _search = searchTerm;
|
||||||
|
|
||||||
// Include original search in search test
|
// Include original search in search test
|
||||||
@ -329,11 +327,7 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
params.addAll(f);
|
params.addAll(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
final page = await requestPage(
|
final page = await requestPage(_pageSize, pageKey, params);
|
||||||
_pageSize,
|
|
||||||
pageKey,
|
|
||||||
params
|
|
||||||
);
|
|
||||||
|
|
||||||
// We may have disposed of the widget while the request was in progress
|
// We may have disposed of the widget while the request was in progress
|
||||||
// If this is the case, abort
|
// If this is the case, abort
|
||||||
@ -367,16 +361,12 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
_pagingController.error = error;
|
_pagingController.error = error;
|
||||||
|
|
||||||
sentryReportError(
|
sentryReportError("paginator.fetchPage", error, stackTrace);
|
||||||
"paginator.fetchPage",
|
|
||||||
error, stackTrace,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback function when the search term is updated
|
// Callback function when the search term is updated
|
||||||
void updateSearchTerm() {
|
void updateSearchTerm() {
|
||||||
|
|
||||||
if (searchTerm == searchController.text) {
|
if (searchTerm == searchController.text) {
|
||||||
// No change
|
// No change
|
||||||
return;
|
return;
|
||||||
@ -410,7 +400,6 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
// Function to construct a single paginated item
|
// Function to construct a single paginated item
|
||||||
// Must be overridden in an implementing subclass
|
// Must be overridden in an implementing subclass
|
||||||
Widget buildItem(BuildContext context, InvenTreeModel item) {
|
Widget buildItem(BuildContext context, InvenTreeModel item) {
|
||||||
|
|
||||||
// This method must be overridden by the child class
|
// This method must be overridden by the child class
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text("*** UNIMPLEMENTED ***"),
|
title: Text("*** UNIMPLEMENTED ***"),
|
||||||
@ -424,11 +413,7 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
List<Widget> children = [buildTitleWidget(context), Divider()];
|
||||||
List<Widget> children = [
|
|
||||||
buildTitleWidget(context),
|
|
||||||
Divider(),
|
|
||||||
];
|
|
||||||
|
|
||||||
if (showSearchWidget) {
|
if (showSearchWidget) {
|
||||||
children.add(buildSearchInput(context));
|
children.add(buildSearchInput(context));
|
||||||
@ -449,13 +434,13 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
},
|
},
|
||||||
noItemsFoundIndicatorBuilder: (context) {
|
noItemsFoundIndicatorBuilder: (context) {
|
||||||
return NoResultsWidget(noResultsText);
|
return NoResultsWidget(noResultsText);
|
||||||
}
|
},
|
||||||
),
|
),
|
||||||
separatorBuilder: (context, item) => const Divider(height: 1),
|
separatorBuilder: (context, item) => const Divider(height: 1),
|
||||||
)
|
),
|
||||||
]
|
],
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return RefreshIndicator(
|
return RefreshIndicator(
|
||||||
@ -473,28 +458,34 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
* Build the title widget for this list
|
* Build the title widget for this list
|
||||||
*/
|
*/
|
||||||
Widget buildTitleWidget(BuildContext context) {
|
Widget buildTitleWidget(BuildContext context) {
|
||||||
|
|
||||||
const double icon_size = 32;
|
const double icon_size = 32;
|
||||||
|
|
||||||
List<Widget> _icons = [];
|
List<Widget> _icons = [];
|
||||||
|
|
||||||
if (filterOptions.isNotEmpty || orderingOptions.isNotEmpty) {
|
if (filterOptions.isNotEmpty || orderingOptions.isNotEmpty) {
|
||||||
_icons.add(IconButton(
|
_icons.add(
|
||||||
|
IconButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
_setOrderingOptions(context);
|
_setOrderingOptions(context);
|
||||||
},
|
},
|
||||||
icon: Icon(Icons.filter_alt, size: icon_size)
|
icon: Icon(Icons.filter_alt, size: icon_size),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_icons.add(IconButton(
|
_icons.add(
|
||||||
|
IconButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
showSearchWidget = !showSearchWidget;
|
showSearchWidget = !showSearchWidget;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
icon: Icon(showSearchWidget ? Icons.zoom_out : Icons.search, size: icon_size)
|
icon: Icon(
|
||||||
));
|
showSearchWidget ? Icons.zoom_out : Icons.search,
|
||||||
|
size: icon_size,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
// _icons.add(IconButton(
|
// _icons.add(IconButton(
|
||||||
// onPressed: () async {
|
// onPressed: () async {
|
||||||
@ -506,20 +497,13 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
widget.searchTitle,
|
widget.searchTitle,
|
||||||
style: TextStyle(
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
"${L10().results}: ${resultCount}",
|
"${L10().results}: ${resultCount}",
|
||||||
style: TextStyle(
|
style: TextStyle(fontStyle: FontStyle.italic),
|
||||||
fontStyle: FontStyle.italic
|
|
||||||
),
|
|
||||||
),
|
|
||||||
trailing: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: _icons,
|
|
||||||
),
|
),
|
||||||
|
trailing: Row(mainAxisSize: MainAxisSize.min, children: _icons),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -530,7 +514,9 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
trailing: GestureDetector(
|
trailing: GestureDetector(
|
||||||
child: Icon(
|
child: Icon(
|
||||||
searchController.text.isEmpty ? TablerIcons.search : TablerIcons.backspace,
|
searchController.text.isEmpty
|
||||||
|
? TablerIcons.search
|
||||||
|
: TablerIcons.backspace,
|
||||||
color: searchController.text.isNotEmpty ? COLOR_DANGER : COLOR_ACTION,
|
color: searchController.text.isNotEmpty ? COLOR_DANGER : COLOR_ACTION,
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
@ -545,31 +531,22 @@ abstract class PaginatedSearchState<T extends PaginatedSearchWidget> extends Sta
|
|||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
updateSearchTerm();
|
updateSearchTerm();
|
||||||
},
|
},
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(hintText: L10().search),
|
||||||
hintText: L10().search,
|
|
||||||
),
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class NoResultsWidget extends StatelessWidget {
|
class NoResultsWidget extends StatelessWidget {
|
||||||
|
|
||||||
const NoResultsWidget(this.description);
|
const NoResultsWidget(this.description);
|
||||||
|
|
||||||
final String description;
|
final String description;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(
|
title: Text(description, style: TextStyle(fontStyle: FontStyle.italic)),
|
||||||
description,
|
|
||||||
style: TextStyle(fontStyle: FontStyle.italic),
|
|
||||||
),
|
|
||||||
leading: Icon(TablerIcons.exclamation_circle, color: COLOR_WARNING),
|
leading: Icon(TablerIcons.exclamation_circle, color: COLOR_WARNING),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
|
||||||
|
|
||||||
@ -14,13 +13,15 @@ import "package:inventree/widget/paginator.dart";
|
|||||||
import "package:inventree/widget/progress.dart";
|
import "package:inventree/widget/progress.dart";
|
||||||
import "package:inventree/widget/refreshable_state.dart";
|
import "package:inventree/widget/refreshable_state.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Widget for displaying a Bill of Materials for a specified Part instance
|
* Widget for displaying a Bill of Materials for a specified Part instance
|
||||||
*/
|
*/
|
||||||
class BillOfMaterialsWidget extends StatefulWidget {
|
class BillOfMaterialsWidget extends StatefulWidget {
|
||||||
|
const BillOfMaterialsWidget(
|
||||||
const BillOfMaterialsWidget(this.part, {this.isParentComponent = true, Key? key}) : super(key: key);
|
this.part, {
|
||||||
|
this.isParentComponent = true,
|
||||||
|
Key? key,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
final InvenTreePart part;
|
final InvenTreePart part;
|
||||||
|
|
||||||
@ -53,12 +54,11 @@ class _BillOfMaterialsState extends RefreshableState<BillOfMaterialsWidget> {
|
|||||||
showFilterOptions = !showFilterOptions;
|
showFilterOptions = !showFilterOptions;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget getBody(BuildContext context) {
|
Widget getBody(BuildContext context) {
|
||||||
|
|
||||||
Map<String, String> filters = {};
|
Map<String, String> filters = {};
|
||||||
|
|
||||||
if (widget.isParentComponent) {
|
if (widget.isParentComponent) {
|
||||||
@ -72,7 +72,11 @@ class _BillOfMaterialsState extends RefreshableState<BillOfMaterialsWidget> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
leading: InvenTreeAPI().getThumbnail(widget.part.thumbnail),
|
leading: InvenTreeAPI().getThumbnail(widget.part.thumbnail),
|
||||||
title: Text(widget.part.fullname),
|
title: Text(widget.part.fullname),
|
||||||
subtitle: Text(widget.isParentComponent ? L10().billOfMaterials : L10().usedInDetails),
|
subtitle: Text(
|
||||||
|
widget.isParentComponent
|
||||||
|
? L10().billOfMaterials
|
||||||
|
: L10().usedInDetails,
|
||||||
|
),
|
||||||
trailing: Text(L10().quantity),
|
trailing: Text(L10().quantity),
|
||||||
),
|
),
|
||||||
Divider(thickness: 1.25),
|
Divider(thickness: 1.25),
|
||||||
@ -87,13 +91,14 @@ class _BillOfMaterialsState extends RefreshableState<BillOfMaterialsWidget> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a paginated widget displaying a list of BomItem objects
|
* Create a paginated widget displaying a list of BomItem objects
|
||||||
*/
|
*/
|
||||||
class PaginatedBomList extends PaginatedSearchWidget {
|
class PaginatedBomList extends PaginatedSearchWidget {
|
||||||
|
const PaginatedBomList(
|
||||||
const PaginatedBomList(Map<String, String> filters, {this.isParentPart = true}) : super(filters: filters);
|
Map<String, String> filters, {
|
||||||
|
this.isParentPart = true,
|
||||||
|
}) : super(filters: filters);
|
||||||
|
|
||||||
final bool isParentPart;
|
final bool isParentPart;
|
||||||
|
|
||||||
@ -104,9 +109,7 @@ class PaginatedBomList extends PaginatedSearchWidget {
|
|||||||
_PaginatedBomListState createState() => _PaginatedBomListState();
|
_PaginatedBomListState createState() => _PaginatedBomListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _PaginatedBomListState extends PaginatedSearchState<PaginatedBomList> {
|
class _PaginatedBomListState extends PaginatedSearchState<PaginatedBomList> {
|
||||||
|
|
||||||
_PaginatedBomListState() : super();
|
_PaginatedBomListState() : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -123,23 +126,31 @@ class _PaginatedBomListState extends PaginatedSearchState<PaginatedBomList> {
|
|||||||
"sub_part_assembly": {
|
"sub_part_assembly": {
|
||||||
"label": L10().filterAssembly,
|
"label": L10().filterAssembly,
|
||||||
"help_text": L10().filterAssemblyDetail,
|
"help_text": L10().filterAssemblyDetail,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
|
int limit,
|
||||||
final page = await InvenTreeBomItem().listPaginated(limit, offset, filters: params);
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
|
final page = await InvenTreeBomItem().listPaginated(
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
filters: params,
|
||||||
|
);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||||
|
|
||||||
InvenTreeBomItem bomItem = model as InvenTreeBomItem;
|
InvenTreeBomItem bomItem = model as InvenTreeBomItem;
|
||||||
|
|
||||||
InvenTreePart? subPart = widget.isParentPart ? bomItem.subPart : bomItem.part;
|
InvenTreePart? subPart = widget.isParentPart
|
||||||
|
? bomItem.subPart
|
||||||
|
: bomItem.part;
|
||||||
|
|
||||||
String title = subPart?.fullname ?? "error - no name";
|
String title = subPart?.fullname ?? "error - no name";
|
||||||
|
|
||||||
@ -151,8 +162,9 @@ class _PaginatedBomListState extends PaginatedSearchState<PaginatedBomList> {
|
|||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
leading: InvenTreeAPI().getThumbnail(subPart?.thumbnail ?? ""),
|
leading: InvenTreeAPI().getThumbnail(subPart?.thumbnail ?? ""),
|
||||||
onTap: subPart == null ? null : () async {
|
onTap: subPart == null
|
||||||
|
? null
|
||||||
|
: () async {
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
var part = await InvenTreePart().get(subPart.pk);
|
var part = await InvenTreePart().get(subPart.pk);
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
|
@ -13,9 +13,7 @@ import "package:inventree/widget/progress.dart";
|
|||||||
import "package:inventree/widget/snacks.dart";
|
import "package:inventree/widget/snacks.dart";
|
||||||
import "package:inventree/widget/refreshable_state.dart";
|
import "package:inventree/widget/refreshable_state.dart";
|
||||||
|
|
||||||
|
|
||||||
class CategoryDisplayWidget extends StatefulWidget {
|
class CategoryDisplayWidget extends StatefulWidget {
|
||||||
|
|
||||||
const CategoryDisplayWidget(this.category, {Key? key}) : super(key: key);
|
const CategoryDisplayWidget(this.category, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
final InvenTreePartCategory? category;
|
final InvenTreePartCategory? category;
|
||||||
@ -24,9 +22,7 @@ class CategoryDisplayWidget extends StatefulWidget {
|
|||||||
_CategoryDisplayState createState() => _CategoryDisplayState();
|
_CategoryDisplayState createState() => _CategoryDisplayState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
||||||
|
|
||||||
_CategoryDisplayState();
|
_CategoryDisplayState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -45,7 +41,7 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
_editCategoryDialog(context);
|
_editCategoryDialog(context);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,7 +59,7 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
child: Icon(TablerIcons.box),
|
child: Icon(TablerIcons.box),
|
||||||
label: L10().partCreateDetail,
|
label: L10().partCreateDetail,
|
||||||
onTap: _newPart,
|
onTap: _newPart,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,8 +70,8 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
label: L10().categoryCreateDetail,
|
label: L10().categoryCreateDetail,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_newCategory(context);
|
_newCategory(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +92,7 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
showSnackIcon(L10().categoryUpdated, success: true);
|
showSnackIcon(L10().categoryUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +103,6 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> request(BuildContext context) async {
|
Future<void> request(BuildContext context) async {
|
||||||
|
|
||||||
// Update the category
|
// Update the category
|
||||||
if (widget.category != null) {
|
if (widget.category != null) {
|
||||||
final bool result = await widget.category?.reload() ?? false;
|
final bool result = await widget.category?.reload() ?? false;
|
||||||
@ -126,18 +121,20 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
title: Text(
|
title: Text(
|
||||||
L10().partCategoryTopLevel,
|
L10().partCategoryTopLevel,
|
||||||
style: TextStyle(fontStyle: FontStyle.italic),
|
style: TextStyle(fontStyle: FontStyle.italic),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
List<Widget> children = [
|
List<Widget> children = [
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text("${widget.category?.name}",
|
title: Text(
|
||||||
style: TextStyle(fontWeight: FontWeight.bold)
|
"${widget.category?.name}",
|
||||||
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
subtitle: Text("${widget.category?.description}"),
|
subtitle: Text("${widget.category?.description}"),
|
||||||
leading: widget.category!.customIcon != null ? Icon(widget.category!.customIcon) : Icon(TablerIcons.sitemap)
|
leading: widget.category!.customIcon != null
|
||||||
|
? Icon(widget.category!.customIcon)
|
||||||
|
: Icon(TablerIcons.sitemap),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -146,18 +143,18 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().parentCategory),
|
title: Text(L10().parentCategory),
|
||||||
subtitle: Text("${widget.category?.parentPathString}"),
|
subtitle: Text("${widget.category?.parentPathString}"),
|
||||||
leading: Icon(
|
leading: Icon(TablerIcons.arrow_move_up, color: COLOR_ACTION),
|
||||||
TablerIcons.arrow_move_up,
|
|
||||||
color: COLOR_ACTION,
|
|
||||||
),
|
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
|
||||||
int parentId = widget.category?.parentId ?? -1;
|
int parentId = widget.category?.parentId ?? -1;
|
||||||
|
|
||||||
if (parentId < 0) {
|
if (parentId < 0) {
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null)));
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => CategoryDisplayWidget(null),
|
||||||
|
),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
var cat = await InvenTreePartCategory().get(parentId);
|
var cat = await InvenTreePartCategory().get(parentId);
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
@ -167,38 +164,26 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Card(
|
return Card(child: Column(children: children));
|
||||||
child: Column(
|
|
||||||
children: children
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Widget> getTabIcons(BuildContext context) {
|
List<Widget> getTabIcons(BuildContext context) {
|
||||||
|
return [Tab(text: L10().details), Tab(text: L10().parts)];
|
||||||
return [
|
|
||||||
Tab(text: L10().details),
|
|
||||||
Tab(text: L10().parts),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Widget> getTabs(BuildContext context) {
|
List<Widget> getTabs(BuildContext context) {
|
||||||
return [
|
return [Column(children: detailTiles()), Column(children: partsTiles())];
|
||||||
Column(children: detailTiles()),
|
|
||||||
Column(children: partsTiles()),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct the "details" panel
|
// Construct the "details" panel
|
||||||
List<Widget> detailTiles() {
|
List<Widget> detailTiles() {
|
||||||
|
|
||||||
Map<String, String> filters = {};
|
Map<String, String> filters = {};
|
||||||
|
|
||||||
int? parent = widget.category?.pk;
|
int? parent = widget.category?.pk;
|
||||||
@ -212,12 +197,9 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
List<Widget> tiles = <Widget>[
|
List<Widget> tiles = <Widget>[
|
||||||
getCategoryDescriptionCard(),
|
getCategoryDescriptionCard(),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: PaginatedPartCategoryList(
|
child: PaginatedPartCategoryList(filters, title: L10().subcategories),
|
||||||
filters,
|
|
||||||
title: L10().subcategories,
|
|
||||||
),
|
|
||||||
flex: 10,
|
flex: 10,
|
||||||
)
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
@ -225,31 +207,21 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
|
|
||||||
// Construct the "parts" panel
|
// Construct the "parts" panel
|
||||||
List<Widget> partsTiles() {
|
List<Widget> partsTiles() {
|
||||||
|
|
||||||
Map<String, String> filters = {
|
Map<String, String> filters = {
|
||||||
"category": widget.category?.pk.toString() ?? "null",
|
"category": widget.category?.pk.toString() ?? "null",
|
||||||
};
|
};
|
||||||
|
|
||||||
return [
|
return [Expanded(child: PaginatedPartList(filters), flex: 10)];
|
||||||
Expanded(
|
|
||||||
child: PaginatedPartList(filters),
|
|
||||||
flex: 10,
|
|
||||||
)
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _newCategory(BuildContext context) async {
|
Future<void> _newCategory(BuildContext context) async {
|
||||||
|
|
||||||
int pk = widget.category?.pk ?? -1;
|
int pk = widget.category?.pk ?? -1;
|
||||||
|
|
||||||
InvenTreePartCategory().createForm(
|
InvenTreePartCategory().createForm(
|
||||||
context,
|
context,
|
||||||
L10().categoryCreate,
|
L10().categoryCreate,
|
||||||
data: {
|
data: {"parent": (pk > 0) ? pk : null},
|
||||||
"parent": (pk > 0) ? pk : null,
|
|
||||||
},
|
|
||||||
onSuccess: (result) async {
|
onSuccess: (result) async {
|
||||||
|
|
||||||
Map<String, dynamic> data = result as Map<String, dynamic>;
|
Map<String, dynamic> data = result as Map<String, dynamic>;
|
||||||
|
|
||||||
if (data.containsKey("pk")) {
|
if (data.containsKey("pk")) {
|
||||||
@ -260,29 +232,25 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
} else {
|
} else {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _newPart() async {
|
Future<void> _newPart() async {
|
||||||
|
|
||||||
int pk = widget.category?.pk ?? -1;
|
int pk = widget.category?.pk ?? -1;
|
||||||
|
|
||||||
InvenTreePart().createForm(
|
InvenTreePart().createForm(
|
||||||
context,
|
context,
|
||||||
L10().partCreate,
|
L10().partCreate,
|
||||||
data: {
|
data: {"category": (pk > 0) ? pk : null},
|
||||||
"category": (pk > 0) ? pk : null
|
|
||||||
},
|
|
||||||
onSuccess: (result) async {
|
onSuccess: (result) async {
|
||||||
|
|
||||||
Map<String, dynamic> data = result as Map<String, dynamic>;
|
Map<String, dynamic> data = result as Map<String, dynamic>;
|
||||||
|
|
||||||
if (data.containsKey("pk")) {
|
if (data.containsKey("pk")) {
|
||||||
var part = InvenTreePart.fromJson(data);
|
var part = InvenTreePart.fromJson(data);
|
||||||
part.goToDetailPage(context);
|
part.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,19 +9,15 @@ import "package:inventree/api.dart";
|
|||||||
import "package:inventree/l10.dart";
|
import "package:inventree/l10.dart";
|
||||||
|
|
||||||
class PartCategoryList extends StatefulWidget {
|
class PartCategoryList extends StatefulWidget {
|
||||||
|
|
||||||
const PartCategoryList(this.filters);
|
const PartCategoryList(this.filters);
|
||||||
|
|
||||||
final Map<String, String> filters;
|
final Map<String, String> filters;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PartCategoryListState createState() => _PartCategoryListState();
|
_PartCategoryListState createState() => _PartCategoryListState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _PartCategoryListState extends RefreshableState<PartCategoryList> {
|
class _PartCategoryListState extends RefreshableState<PartCategoryList> {
|
||||||
|
|
||||||
_PartCategoryListState();
|
_PartCategoryListState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -34,19 +30,21 @@ class _PartCategoryListState extends RefreshableState<PartCategoryList> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PaginatedPartCategoryList extends PaginatedSearchWidget {
|
class PaginatedPartCategoryList extends PaginatedSearchWidget {
|
||||||
|
const PaginatedPartCategoryList(
|
||||||
const PaginatedPartCategoryList(Map<String, String> filters, {String title = ""}) : super(filters: filters, title: title);
|
Map<String, String> filters, {
|
||||||
|
String title = "",
|
||||||
|
}) : super(filters: filters, title: title);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get searchTitle => title.isNotEmpty ? title : L10().partCategories;
|
String get searchTitle => title.isNotEmpty ? title : L10().partCategories;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PaginatedPartCategoryListState createState() => _PaginatedPartCategoryListState();
|
_PaginatedPartCategoryListState createState() =>
|
||||||
|
_PaginatedPartCategoryListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _PaginatedPartCategoryListState
|
||||||
class _PaginatedPartCategoryListState extends PaginatedSearchState<PaginatedPartCategoryList> {
|
extends PaginatedSearchState<PaginatedPartCategoryList> {
|
||||||
|
|
||||||
// _PaginatedPartCategoryListState(Map<String, String> filters, bool searchEnabled) : super(filters, searchEnabled);
|
// _PaginatedPartCategoryListState(Map<String, String> filters, bool searchEnabled) : super(filters, searchEnabled);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -59,16 +57,12 @@ class _PaginatedPartCategoryListState extends PaginatedSearchState<PaginatedPart
|
|||||||
"label": L10().includeSubcategories,
|
"label": L10().includeSubcategories,
|
||||||
"help_text": L10().includeSubcategoriesDetail,
|
"help_text": L10().includeSubcategoriesDetail,
|
||||||
"tristate": false,
|
"tristate": false,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, String> get orderingOptions {
|
Map<String, String> get orderingOptions {
|
||||||
|
Map<String, String> options = {"name": L10().name, "level": L10().level};
|
||||||
Map<String, String> options = {
|
|
||||||
"name": L10().name,
|
|
||||||
"level": L10().level,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Note: API v69 changed 'parts' to 'part_count'
|
// Note: API v69 changed 'parts' to 'part_count'
|
||||||
if (InvenTreeAPI().apiVersion >= 69) {
|
if (InvenTreeAPI().apiVersion >= 69) {
|
||||||
@ -81,16 +75,22 @@ class _PaginatedPartCategoryListState extends PaginatedSearchState<PaginatedPart
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
|
int limit,
|
||||||
final page = await InvenTreePartCategory().listPaginated(limit, offset, filters: params);
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
|
final page = await InvenTreePartCategory().listPaginated(
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
filters: params,
|
||||||
|
);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||||
|
|
||||||
InvenTreePartCategory category = model as InvenTreePartCategory;
|
InvenTreePartCategory category = model as InvenTreePartCategory;
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
|
@ -27,24 +27,19 @@ import "package:inventree/widget/snacks.dart";
|
|||||||
import "package:inventree/widget/stock/stock_list.dart";
|
import "package:inventree/widget/stock/stock_list.dart";
|
||||||
import "package:inventree/widget/company/supplier_part_list.dart";
|
import "package:inventree/widget/company/supplier_part_list.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Widget for displaying a detail view of a single Part instance
|
* Widget for displaying a detail view of a single Part instance
|
||||||
*/
|
*/
|
||||||
class PartDetailWidget extends StatefulWidget {
|
class PartDetailWidget extends StatefulWidget {
|
||||||
|
|
||||||
const PartDetailWidget(this.part, {Key? key}) : super(key: key);
|
const PartDetailWidget(this.part, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
final InvenTreePart part;
|
final InvenTreePart part;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PartDisplayState createState() => _PartDisplayState(part);
|
_PartDisplayState createState() => _PartDisplayState(part);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||||
|
|
||||||
_PartDisplayState(this.part);
|
_PartDisplayState(this.part);
|
||||||
|
|
||||||
InvenTreePart part;
|
InvenTreePart part;
|
||||||
@ -81,8 +76,8 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
tooltip: L10().editPart,
|
tooltip: L10().editPart,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_editPartDialog(context);
|
_editPartDialog(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return actions;
|
return actions;
|
||||||
@ -95,10 +90,12 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
if (InvenTreePart().canEdit) {
|
if (InvenTreePart().canEdit) {
|
||||||
actions.add(
|
actions.add(
|
||||||
customBarcodeAction(
|
customBarcodeAction(
|
||||||
context, this,
|
context,
|
||||||
widget.part.customBarcode, "part",
|
this,
|
||||||
widget.part.pk
|
widget.part.customBarcode,
|
||||||
)
|
"part",
|
||||||
|
widget.part.pk,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,8 +113,8 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
label: L10().stockItemCreate,
|
label: L10().stockItemCreate,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_newStockItem(context);
|
_newStockItem(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,10 +129,10 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
labels,
|
labels,
|
||||||
widget.part.pk,
|
widget.part.pk,
|
||||||
"part",
|
"part",
|
||||||
"part=${widget.part.pk}"
|
"part=${widget.part.pk}",
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,14 +150,22 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> request(BuildContext context) async {
|
Future<void> request(BuildContext context) async {
|
||||||
|
|
||||||
final bool result = await part.reload();
|
final bool result = await part.reload();
|
||||||
|
|
||||||
// Load page settings from local storage
|
// Load page settings from local storage
|
||||||
showPricing = await InvenTreeSettingsManager().getBool(INV_PART_SHOW_PRICING, true);
|
showPricing = await InvenTreeSettingsManager().getBool(
|
||||||
showParameters = await InvenTreeSettingsManager().getBool(INV_PART_SHOW_PARAMETERS, true);
|
INV_PART_SHOW_PRICING,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
showParameters = await InvenTreeSettingsManager().getBool(
|
||||||
|
INV_PART_SHOW_PARAMETERS,
|
||||||
|
true,
|
||||||
|
);
|
||||||
showBom = await InvenTreeSettingsManager().getBool(INV_PART_SHOW_BOM, true);
|
showBom = await InvenTreeSettingsManager().getBool(INV_PART_SHOW_BOM, true);
|
||||||
allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
|
allowLabelPrinting = await InvenTreeSettingsManager().getBool(
|
||||||
|
INV_ENABLE_LABEL_PRINTING,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
if (!result || part.pk == -1) {
|
if (!result || part.pk == -1) {
|
||||||
// Part could not be loaded, for some reason
|
// Part could not be loaded, for some reason
|
||||||
@ -211,11 +216,9 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Request the number of BOM items
|
// Request the number of BOM items
|
||||||
InvenTreePart().count(
|
InvenTreePart().count(filters: {"in_bom_for": part.pk.toString()}).then((
|
||||||
filters: {
|
int value,
|
||||||
"in_bom_for": part.pk.toString(),
|
) {
|
||||||
}
|
|
||||||
).then((int value) {
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
bomCount = value;
|
bomCount = value;
|
||||||
@ -224,11 +227,9 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Request number of "used in" parts
|
// Request number of "used in" parts
|
||||||
InvenTreeBomItem().count(
|
InvenTreeBomItem().count(filters: {"uses": part.pk.toString()}).then((
|
||||||
filters: {
|
int value,
|
||||||
"uses": part.pk.toString(),
|
) {
|
||||||
}
|
|
||||||
).then((int value) {
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
usedInCount = value;
|
usedInCount = value;
|
||||||
@ -237,11 +238,9 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Request the number of variant items
|
// Request the number of variant items
|
||||||
InvenTreePart().count(
|
InvenTreePart().count(filters: {"variant_of": part.pk.toString()}).then((
|
||||||
filters: {
|
int value,
|
||||||
"variant_of": part.pk.toString(),
|
) {
|
||||||
}
|
|
||||||
).then((int value) {
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
variantCount = value;
|
variantCount = value;
|
||||||
@ -253,16 +252,14 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
allowLabelPrinting &= api.supportsMixin("labels");
|
allowLabelPrinting &= api.supportsMixin("labels");
|
||||||
|
|
||||||
if (allowLabelPrinting) {
|
if (allowLabelPrinting) {
|
||||||
|
String model_type = api.supportsModernLabelPrinting
|
||||||
String model_type = api.supportsModernLabelPrinting ? InvenTreePart.MODEL_TYPE : "part";
|
? InvenTreePart.MODEL_TYPE
|
||||||
|
: "part";
|
||||||
String item_key = api.supportsModernLabelPrinting ? "items" : "part";
|
String item_key = api.supportsModernLabelPrinting ? "items" : "part";
|
||||||
|
|
||||||
_labels = await getLabelTemplates(
|
_labels = await getLabelTemplates(model_type, {
|
||||||
model_type,
|
item_key: widget.part.pk.toString(),
|
||||||
{
|
});
|
||||||
item_key: widget.part.pk.toString()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
@ -273,14 +270,13 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _editPartDialog(BuildContext context) {
|
void _editPartDialog(BuildContext context) {
|
||||||
|
|
||||||
part.editForm(
|
part.editForm(
|
||||||
context,
|
context,
|
||||||
L10().editPart,
|
L10().editPart,
|
||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
showSnackIcon(L10().partEdited, success: true);
|
showSnackIcon(L10().partEdited, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,24 +285,18 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text(part.fullname),
|
title: Text(part.fullname),
|
||||||
subtitle: Text(part.description),
|
subtitle: Text(part.description),
|
||||||
trailing: Text(
|
trailing: Text(part.stockString(), style: TextStyle(fontSize: 20)),
|
||||||
part.stockString(),
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 20,
|
|
||||||
)
|
|
||||||
),
|
|
||||||
leading: GestureDetector(
|
leading: GestureDetector(
|
||||||
child: api.getImage(part.thumbnail),
|
child: api.getImage(part.thumbnail),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => PartImageWidget(part)),
|
||||||
builder: (context) => PartImageWidget(part)
|
|
||||||
)
|
|
||||||
).then((value) {
|
).then((value) {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
});
|
});
|
||||||
}),
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -315,13 +305,10 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
* Build a list of tiles to display under the part description
|
* Build a list of tiles to display under the part description
|
||||||
*/
|
*/
|
||||||
List<Widget> partTiles() {
|
List<Widget> partTiles() {
|
||||||
|
|
||||||
List<Widget> tiles = [];
|
List<Widget> tiles = [];
|
||||||
|
|
||||||
// Image / name / description
|
// Image / name / description
|
||||||
tiles.add(
|
tiles.add(headerTile());
|
||||||
headerTile()
|
|
||||||
);
|
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
tiles.add(progressIndicator());
|
tiles.add(progressIndicator());
|
||||||
@ -331,23 +318,13 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
if (!part.isActive) {
|
if (!part.isActive) {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(
|
title: Text(L10().inactive, style: TextStyle(color: COLOR_DANGER)),
|
||||||
L10().inactive,
|
|
||||||
style: TextStyle(
|
|
||||||
color: COLOR_DANGER
|
|
||||||
)
|
|
||||||
),
|
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
L10().inactiveDetail,
|
L10().inactiveDetail,
|
||||||
style: TextStyle(
|
style: TextStyle(color: COLOR_DANGER),
|
||||||
color: COLOR_DANGER
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
leading: Icon(
|
leading: Icon(TablerIcons.exclamation_circle, color: COLOR_DANGER),
|
||||||
TablerIcons.exclamation_circle,
|
|
||||||
color: COLOR_DANGER
|
|
||||||
),
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,15 +333,11 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().templatePart),
|
title: Text(L10().templatePart),
|
||||||
subtitle: Text(parentPart!.fullname),
|
subtitle: Text(parentPart!.fullname),
|
||||||
leading: api.getImage(
|
leading: api.getImage(parentPart!.thumbnail, width: 32, height: 32),
|
||||||
parentPart!.thumbnail,
|
|
||||||
width: 32,
|
|
||||||
height: 32,
|
|
||||||
),
|
|
||||||
onTap: () {
|
onTap: () {
|
||||||
parentPart?.goToDetailPage(context);
|
parentPart?.goToDetailPage(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,7 +350,6 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
leading: Icon(TablerIcons.sitemap, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.sitemap, color: COLOR_ACTION),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
if (part.categoryId > 0) {
|
if (part.categoryId > 0) {
|
||||||
|
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
var cat = await InvenTreePartCategory().get(part.categoryId);
|
var cat = await InvenTreePartCategory().get(part.categoryId);
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
@ -387,7 +359,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -396,10 +368,14 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
subtitle: Text(L10().partCategoryTopLevel),
|
subtitle: Text(L10().partCategoryTopLevel),
|
||||||
leading: Icon(TablerIcons.sitemap, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.sitemap, color: COLOR_ACTION),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(context, MaterialPageRoute(
|
Navigator.push(
|
||||||
builder: (context) => CategoryDisplayWidget(null)));
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => CategoryDisplayWidget(null),
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,16 +390,13 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => PartList(
|
builder: (context) => PartList({
|
||||||
{
|
|
||||||
"variant_of": part.pk.toString(),
|
"variant_of": part.pk.toString(),
|
||||||
},
|
}, title: L10().variants),
|
||||||
title: L10().variants
|
),
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,19 +407,16 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
leading: Icon(TablerIcons.packages),
|
leading: Icon(TablerIcons.packages),
|
||||||
trailing: Text(
|
trailing: Text(
|
||||||
part.stockString(),
|
part.stockString(),
|
||||||
style: TextStyle(
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (showPricing && partPricing != null) {
|
if (showPricing && partPricing != null) {
|
||||||
|
|
||||||
String pricing = formatPriceRange(
|
String pricing = formatPriceRange(
|
||||||
partPricing?.overallMin,
|
partPricing?.overallMin,
|
||||||
partPricing?.overallMax,
|
partPricing?.overallMax,
|
||||||
currency: partPricing?.currency
|
currency: partPricing?.currency,
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -455,15 +425,14 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
leading: Icon(TablerIcons.currency_dollar, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.currency_dollar, color: COLOR_ACTION),
|
||||||
trailing: Text(
|
trailing: Text(
|
||||||
pricing.isNotEmpty ? pricing : L10().noPricingAvailable,
|
pricing.isNotEmpty ? pricing : L10().noPricingAvailable,
|
||||||
style: TextStyle(
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => PartPricingWidget(part: part, partPricing: partPricing),
|
builder: (context) =>
|
||||||
|
PartPricingWidget(part: part, partPricing: partPricing),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -473,7 +442,6 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
|
|
||||||
// Tiles for "purchaseable" parts
|
// Tiles for "purchaseable" parts
|
||||||
if (part.isPurchaseable) {
|
if (part.isPurchaseable) {
|
||||||
|
|
||||||
// On order
|
// On order
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
@ -484,14 +452,12 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
// TODO - Order views
|
// TODO - Order views
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tiles for an "assembly" part
|
// Tiles for an "assembly" part
|
||||||
if (part.isAssembly) {
|
if (part.isAssembly) {
|
||||||
|
|
||||||
if (showBom && bomCount > 0) {
|
if (showBom && bomCount > 0) {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
@ -499,11 +465,15 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
leading: Icon(TablerIcons.list_tree, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.list_tree, color: COLOR_ACTION),
|
||||||
trailing: Text(bomCount.toString()),
|
trailing: Text(bomCount.toString()),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(context, MaterialPageRoute(
|
Navigator.push(
|
||||||
builder: (context) => BillOfMaterialsWidget(part, isParentComponent: true)
|
context,
|
||||||
));
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
BillOfMaterialsWidget(part, isParentComponent: true),
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,7 +486,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
// TODO
|
// TODO
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -533,11 +503,12 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => BillOfMaterialsWidget(part, isParentComponent: false)
|
builder: (context) =>
|
||||||
)
|
BillOfMaterialsWidget(part, isParentComponent: false),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -548,7 +519,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text("${part.keywords}"),
|
title: Text("${part.keywords}"),
|
||||||
leading: Icon(TablerIcons.tags),
|
leading: Icon(TablerIcons.tags),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -561,13 +532,12 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
part.openLink();
|
part.openLink();
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tiles for "component" part
|
// Tiles for "component" part
|
||||||
if (part.isComponent && part.usedInCount > 0) {
|
if (part.isComponent && part.usedInCount > 0) {
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().usedIn),
|
title: Text(L10().usedIn),
|
||||||
@ -577,12 +547,11 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
// TODO
|
// TODO
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (part.isPurchaseable) {
|
if (part.isPurchaseable) {
|
||||||
|
|
||||||
if (part.supplierCount > 0) {
|
if (part.supplierCount > 0) {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
@ -592,12 +561,13 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => SupplierPartList({
|
MaterialPageRoute(
|
||||||
"part": part.pk.toString()
|
builder: (context) =>
|
||||||
}))
|
SupplierPartList({"part": part.pk.toString()}),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -611,10 +581,10 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => NotesWidget(part))
|
MaterialPageRoute(builder: (context) => NotesWidget(part)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -630,16 +600,15 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
InvenTreePartAttachment(),
|
InvenTreePartAttachment(),
|
||||||
part.pk,
|
part.pk,
|
||||||
L10().part,
|
L10().part,
|
||||||
part.canEdit
|
part.canEdit,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return tiles for each stock item
|
// Return tiles for each stock item
|
||||||
@ -654,9 +623,13 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
L10().stockItems,
|
L10().stockItems,
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
subtitle: part.stockItems.isEmpty ? Text(L10().stockItemsNotAvailable) : null,
|
subtitle: part.stockItems.isEmpty
|
||||||
trailing: part.stockItems.isNotEmpty ? Text("${part.stockItems.length}") : null,
|
? Text(L10().stockItemsNotAvailable)
|
||||||
)
|
: null,
|
||||||
|
trailing: part.stockItems.isNotEmpty
|
||||||
|
? Text("${part.stockItems.length}")
|
||||||
|
: null,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
@ -666,7 +639,6 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
* Launch a form to create a new StockItem for this part
|
* Launch a form to create a new StockItem for this part
|
||||||
*/
|
*/
|
||||||
Future<void> _newStockItem(BuildContext context) async {
|
Future<void> _newStockItem(BuildContext context) async {
|
||||||
|
|
||||||
var fields = InvenTreeStockItem().formFields();
|
var fields = InvenTreeStockItem().formFields();
|
||||||
|
|
||||||
// Serial number cannot be directly edited here
|
// Serial number cannot be directly edited here
|
||||||
@ -677,9 +649,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
|
|
||||||
int? default_location = part.defaultLocation;
|
int? default_location = part.defaultLocation;
|
||||||
|
|
||||||
Map<String, dynamic> data = {
|
Map<String, dynamic> data = {"part": part.pk.toString()};
|
||||||
"part": part.pk.toString()
|
|
||||||
};
|
|
||||||
|
|
||||||
if (default_location != null) {
|
if (default_location != null) {
|
||||||
data["location"] = default_location;
|
data["location"] = default_location;
|
||||||
@ -688,15 +658,22 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
if (part.isTrackable) {
|
if (part.isTrackable) {
|
||||||
// read the next available serial number
|
// read the next available serial number
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
var response = await api.get("/api/part/${part.pk}/serial-numbers/", expectedStatusCode: null);
|
var response = await api.get(
|
||||||
|
"/api/part/${part.pk}/serial-numbers/",
|
||||||
|
expectedStatusCode: null,
|
||||||
|
);
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
|
|
||||||
if (response.isValid() && response.statusCode == 200) {
|
if (response.isValid() && response.statusCode == 200) {
|
||||||
data["serial_numbers"] = response.data["next"] ?? response.data["latest"];
|
data["serial_numbers"] =
|
||||||
|
response.data["next"] ?? response.data["latest"];
|
||||||
}
|
}
|
||||||
|
|
||||||
print("response: " + response.statusCode.toString() + response.data.toString());
|
print(
|
||||||
|
"response: " +
|
||||||
|
response.statusCode.toString() +
|
||||||
|
response.data.toString(),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// Cannot set serial numbers for non-trackable parts
|
// Cannot set serial numbers for non-trackable parts
|
||||||
fields.remove("serial_numbers");
|
fields.remove("serial_numbers");
|
||||||
@ -710,23 +687,19 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
fields: fields,
|
fields: fields,
|
||||||
data: data,
|
data: data,
|
||||||
onSuccess: (result) async {
|
onSuccess: (result) async {
|
||||||
|
|
||||||
Map<String, dynamic> data = result as Map<String, dynamic>;
|
Map<String, dynamic> data = result as Map<String, dynamic>;
|
||||||
|
|
||||||
if (data.containsKey("pk")) {
|
if (data.containsKey("pk")) {
|
||||||
var item = InvenTreeStockItem.fromJson(data);
|
var item = InvenTreeStockItem.fromJson(data);
|
||||||
item.goToDetailPage(context);
|
item.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Widget> getTabIcons(BuildContext context) {
|
List<Widget> getTabIcons(BuildContext context) {
|
||||||
List<Widget> icons = [
|
List<Widget> icons = [Tab(text: L10().details), Tab(text: L10().stock)];
|
||||||
Tab(text: L10().details),
|
|
||||||
Tab(text: L10().stock)
|
|
||||||
];
|
|
||||||
|
|
||||||
if (showParameters) {
|
if (showParameters) {
|
||||||
icons.add(Tab(text: L10().parameters));
|
icons.add(Tab(text: L10().parameters));
|
||||||
@ -740,11 +713,9 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
List<Widget> tabs = [
|
List<Widget> tabs = [
|
||||||
SingleChildScrollView(
|
SingleChildScrollView(
|
||||||
physics: AlwaysScrollableScrollPhysics(),
|
physics: AlwaysScrollableScrollPhysics(),
|
||||||
child: Column(
|
child: Column(children: partTiles()),
|
||||||
children: partTiles(),
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
PaginatedStockItemList({"part": part.pk.toString()})
|
PaginatedStockItemList({"part": part.pk.toString()}),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (showParameters) {
|
if (showParameters) {
|
||||||
@ -753,5 +724,4 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
|
|
||||||
return tabs;
|
return tabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,19 +11,15 @@ import "package:inventree/widget/snacks.dart";
|
|||||||
import "package:inventree/l10.dart";
|
import "package:inventree/l10.dart";
|
||||||
|
|
||||||
class PartImageWidget extends StatefulWidget {
|
class PartImageWidget extends StatefulWidget {
|
||||||
|
|
||||||
const PartImageWidget(this.part, {Key? key}) : super(key: key);
|
const PartImageWidget(this.part, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
final InvenTreePart part;
|
final InvenTreePart part;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PartImageState createState() => _PartImageState(part);
|
_PartImageState createState() => _PartImageState(part);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _PartImageState extends RefreshableState<PartImageWidget> {
|
class _PartImageState extends RefreshableState<PartImageWidget> {
|
||||||
|
|
||||||
_PartImageState(this.part);
|
_PartImageState(this.part);
|
||||||
|
|
||||||
final InvenTreePart part;
|
final InvenTreePart part;
|
||||||
@ -38,17 +34,14 @@ class _PartImageState extends RefreshableState<PartImageWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
List<Widget> appBarActions(BuildContext context) {
|
List<Widget> appBarActions(BuildContext context) {
|
||||||
|
|
||||||
List<Widget> actions = [];
|
List<Widget> actions = [];
|
||||||
|
|
||||||
if (part.canEdit) {
|
if (part.canEdit) {
|
||||||
|
|
||||||
// File upload
|
// File upload
|
||||||
actions.add(
|
actions.add(
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(TablerIcons.file_upload),
|
icon: Icon(TablerIcons.file_upload),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
|
||||||
FilePickerDialog.pickFile(
|
FilePickerDialog.pickFile(
|
||||||
onPicked: (File file) async {
|
onPicked: (File file) async {
|
||||||
final result = await part.uploadImage(file);
|
final result = await part.uploadImage(file);
|
||||||
@ -58,11 +51,10 @@ class _PartImageState extends RefreshableState<PartImageWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
refresh(context);
|
refresh(context);
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
},
|
},
|
||||||
)
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,5 +65,4 @@ class _PartImageState extends RefreshableState<PartImageWidget> {
|
|||||||
Widget getBody(BuildContext context) {
|
Widget getBody(BuildContext context) {
|
||||||
return InvenTreeAPI().getImage(part.image);
|
return InvenTreeAPI().getImage(part.image);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -9,9 +9,7 @@ import "package:inventree/inventree/part.dart";
|
|||||||
import "package:inventree/widget/paginator.dart";
|
import "package:inventree/widget/paginator.dart";
|
||||||
import "package:inventree/widget/refreshable_state.dart";
|
import "package:inventree/widget/refreshable_state.dart";
|
||||||
|
|
||||||
|
|
||||||
class PartList extends StatefulWidget {
|
class PartList extends StatefulWidget {
|
||||||
|
|
||||||
const PartList(this.filters, {this.title = ""});
|
const PartList(this.filters, {this.title = ""});
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
@ -22,9 +20,7 @@ class PartList extends StatefulWidget {
|
|||||||
_PartListState createState() => _PartListState(filters, title);
|
_PartListState createState() => _PartListState(filters, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _PartListState extends RefreshableState<PartList> {
|
class _PartListState extends RefreshableState<PartList> {
|
||||||
|
|
||||||
_PartListState(this.filters, this.title);
|
_PartListState(this.filters, this.title);
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
@ -40,13 +36,11 @@ class _PartListState extends RefreshableState<PartList> {
|
|||||||
Widget getBody(BuildContext context) {
|
Widget getBody(BuildContext context) {
|
||||||
return PaginatedPartList(filters);
|
return PaginatedPartList(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PaginatedPartList extends PaginatedSearchWidget {
|
class PaginatedPartList extends PaginatedSearchWidget {
|
||||||
|
const PaginatedPartList(Map<String, String> filters)
|
||||||
const PaginatedPartList(Map<String, String> filters) : super(filters: filters);
|
: super(filters: filters);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get searchTitle => L10().parts;
|
String get searchTitle => L10().parts;
|
||||||
@ -55,9 +49,7 @@ class PaginatedPartList extends PaginatedSearchWidget {
|
|||||||
_PaginatedPartListState createState() => _PaginatedPartListState();
|
_PaginatedPartListState createState() => _PaginatedPartListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _PaginatedPartListState extends PaginatedSearchState<PaginatedPartList> {
|
class _PaginatedPartListState extends PaginatedSearchState<PaginatedPartList> {
|
||||||
|
|
||||||
_PaginatedPartListState() : super();
|
_PaginatedPartListState() : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -84,7 +76,7 @@ class _PaginatedPartListState extends PaginatedSearchState<PaginatedPartList> {
|
|||||||
},
|
},
|
||||||
"assembly": {
|
"assembly": {
|
||||||
"label": L10().filterAssembly,
|
"label": L10().filterAssembly,
|
||||||
"help_text": L10().filterAssemblyDetail
|
"help_text": L10().filterAssemblyDetail,
|
||||||
},
|
},
|
||||||
"component": {
|
"component": {
|
||||||
"label": L10().filterComponent,
|
"label": L10().filterComponent,
|
||||||
@ -92,7 +84,7 @@ class _PaginatedPartListState extends PaginatedSearchState<PaginatedPartList> {
|
|||||||
},
|
},
|
||||||
"is_template": {
|
"is_template": {
|
||||||
"label": L10().filterTemplate,
|
"label": L10().filterTemplate,
|
||||||
"help_text": L10().filterTemplateDetail
|
"help_text": L10().filterTemplateDetail,
|
||||||
},
|
},
|
||||||
"trackable": {
|
"trackable": {
|
||||||
"label": L10().filterTrackable,
|
"label": L10().filterTrackable,
|
||||||
@ -105,18 +97,25 @@ class _PaginatedPartListState extends PaginatedSearchState<PaginatedPartList> {
|
|||||||
"has_stock": {
|
"has_stock": {
|
||||||
"label": L10().filterInStock,
|
"label": L10().filterInStock,
|
||||||
"help_text": L10().filterInStockDetail,
|
"help_text": L10().filterInStockDetail,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
final page = await InvenTreePart().listPaginated(limit, offset, filters: params);
|
int limit,
|
||||||
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
|
final page = await InvenTreePart().listPaginated(
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
filters: params,
|
||||||
|
);
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||||
|
|
||||||
InvenTreePart part = model as InvenTreePart;
|
InvenTreePart part = model as InvenTreePart;
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
@ -124,10 +123,7 @@ class _PaginatedPartListState extends PaginatedSearchState<PaginatedPartList> {
|
|||||||
subtitle: Text(part.description),
|
subtitle: Text(part.description),
|
||||||
trailing: Text(
|
trailing: Text(
|
||||||
part.stockString(),
|
part.stockString(),
|
||||||
style: TextStyle(
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.bold
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
leading: InvenTreeAPI().getThumbnail(part.thumbnail),
|
leading: InvenTreeAPI().getThumbnail(part.thumbnail),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
@ -11,7 +11,6 @@ import "package:inventree/widget/refreshable_state.dart";
|
|||||||
* Widget for displaying a list of parameters associated with a given Part instance
|
* Widget for displaying a list of parameters associated with a given Part instance
|
||||||
*/
|
*/
|
||||||
class PartParameterWidget extends StatefulWidget {
|
class PartParameterWidget extends StatefulWidget {
|
||||||
|
|
||||||
const PartParameterWidget(this.part);
|
const PartParameterWidget(this.part);
|
||||||
|
|
||||||
final InvenTreePart part;
|
final InvenTreePart part;
|
||||||
@ -20,7 +19,6 @@ class PartParameterWidget extends StatefulWidget {
|
|||||||
_ParameterWidgetState createState() => _ParameterWidgetState();
|
_ParameterWidgetState createState() => _ParameterWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _ParameterWidgetState extends RefreshableState<PartParameterWidget> {
|
class _ParameterWidgetState extends RefreshableState<PartParameterWidget> {
|
||||||
_ParameterWidgetState();
|
_ParameterWidgetState();
|
||||||
|
|
||||||
@ -36,28 +34,18 @@ class _ParameterWidgetState extends RefreshableState<PartParameterWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget getBody(BuildContext context) {
|
Widget getBody(BuildContext context) {
|
||||||
|
Map<String, String> filters = {"part": widget.part.pk.toString()};
|
||||||
|
|
||||||
Map<String, String> filters = {
|
return Column(children: [Expanded(child: PaginatedParameterList(filters))]);
|
||||||
"part": widget.part.pk.toString()
|
|
||||||
};
|
|
||||||
|
|
||||||
return Column(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: PaginatedParameterList(filters)
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Widget for displaying a paginated list of Part parameters
|
* Widget for displaying a paginated list of Part parameters
|
||||||
*/
|
*/
|
||||||
class PaginatedParameterList extends PaginatedSearchWidget {
|
class PaginatedParameterList extends PaginatedSearchWidget {
|
||||||
|
const PaginatedParameterList(Map<String, String> filters)
|
||||||
const PaginatedParameterList(Map<String, String> filters) : super(filters: filters);
|
: super(filters: filters);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get searchTitle => L10().parameters;
|
String get searchTitle => L10().parameters;
|
||||||
@ -66,18 +54,15 @@ class PaginatedParameterList extends PaginatedSearchWidget {
|
|||||||
_PaginatedParameterState createState() => _PaginatedParameterState();
|
_PaginatedParameterState createState() => _PaginatedParameterState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _PaginatedParameterState
|
||||||
class _PaginatedParameterState extends PaginatedSearchState<PaginatedParameterList> {
|
extends PaginatedSearchState<PaginatedParameterList> {
|
||||||
|
|
||||||
_PaginatedParameterState() : super();
|
_PaginatedParameterState() : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get prefix => "parameters_";
|
String get prefix => "parameters_";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, String> get orderingOptions => {
|
Map<String, String> get orderingOptions => {};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, Map<String, dynamic>> get filterOptions => {
|
Map<String, Map<String, dynamic>> get filterOptions => {
|
||||||
@ -85,15 +70,21 @@ class _PaginatedParameterState extends PaginatedSearchState<PaginatedParameterLi
|
|||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
|
int limit,
|
||||||
final page = await InvenTreePartParameter().listPaginated(limit, offset, filters: params);
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
|
final page = await InvenTreePartParameter().listPaginated(
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
filters: params,
|
||||||
|
);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> editParameter(InvenTreePartParameter parameter) async {
|
Future<void> editParameter(InvenTreePartParameter parameter) async {
|
||||||
|
|
||||||
// Checkbox values are handled separately
|
// Checkbox values are handled separately
|
||||||
if (parameter.is_checkbox) {
|
if (parameter.is_checkbox) {
|
||||||
return;
|
return;
|
||||||
@ -103,14 +94,13 @@ class _PaginatedParameterState extends PaginatedSearchState<PaginatedParameterLi
|
|||||||
L10().editParameter,
|
L10().editParameter,
|
||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
updateSearchTerm();
|
updateSearchTerm();
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||||
|
|
||||||
InvenTreePartParameter parameter = model as InvenTreePartParameter;
|
InvenTreePartParameter parameter = model as InvenTreePartParameter;
|
||||||
|
|
||||||
String title = parameter.name;
|
String title = parameter.name;
|
||||||
@ -128,18 +118,19 @@ class _PaginatedParameterState extends PaginatedSearchState<PaginatedParameterLi
|
|||||||
onChanged: (bool value) {
|
onChanged: (bool value) {
|
||||||
if (parameter.canEdit) {
|
if (parameter.canEdit) {
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
parameter.update(
|
parameter.update(values: {"data": value.toString()}).then((
|
||||||
values: {
|
value,
|
||||||
"data": value.toString()
|
) async {
|
||||||
}
|
|
||||||
).then((value) async{
|
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
updateSearchTerm();
|
updateSearchTerm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
) : Text(parameter.value),
|
)
|
||||||
onTap: parameter.is_checkbox ? null : () async {
|
: Text(parameter.value),
|
||||||
|
onTap: parameter.is_checkbox
|
||||||
|
? null
|
||||||
|
: () async {
|
||||||
if (parameter.canEdit) {
|
if (parameter.canEdit) {
|
||||||
editParameter(parameter);
|
editParameter(parameter);
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,11 @@ import "package:inventree/widget/refreshable_state.dart";
|
|||||||
import "package:inventree/helpers.dart";
|
import "package:inventree/helpers.dart";
|
||||||
|
|
||||||
class PartPricingWidget extends StatefulWidget {
|
class PartPricingWidget extends StatefulWidget {
|
||||||
|
const PartPricingWidget({
|
||||||
const PartPricingWidget({Key? key, required this.part, required this.partPricing}) : super(key: key);
|
Key? key,
|
||||||
|
required this.part,
|
||||||
|
required this.partPricing,
|
||||||
|
}) : super(key: key);
|
||||||
final InvenTreePart part;
|
final InvenTreePart part;
|
||||||
final InvenTreePartPricing? partPricing;
|
final InvenTreePartPricing? partPricing;
|
||||||
|
|
||||||
@ -17,7 +20,6 @@ class PartPricingWidget extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getAppBarTitle() {
|
String getAppBarTitle() {
|
||||||
return L10().partPricing;
|
return L10().partPricing;
|
||||||
@ -25,14 +27,13 @@ class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
List<Widget> getTiles(BuildContext context) {
|
List<Widget> getTiles(BuildContext context) {
|
||||||
|
|
||||||
List<Widget> tiles = [
|
List<Widget> tiles = [
|
||||||
Card(
|
Card(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text(widget.part.fullname),
|
title: Text(widget.part.fullname),
|
||||||
subtitle: Text(widget.part.description),
|
subtitle: Text(widget.part.description),
|
||||||
leading: api.getThumbnail(widget.part.thumbnail)
|
leading: api.getThumbnail(widget.part.thumbnail),
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -41,7 +42,7 @@ class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().noPricingAvailable),
|
title: Text(L10().noPricingAvailable),
|
||||||
subtitle: Text(L10().noPricingDataFound),
|
subtitle: Text(L10().noPricingDataFound),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
@ -50,10 +51,7 @@ class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
|||||||
final pricing = widget.partPricing!;
|
final pricing = widget.partPricing!;
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(title: Text(L10().currency), trailing: Text(pricing.currency)),
|
||||||
title: Text(L10().currency),
|
|
||||||
trailing: Text(pricing.currency),
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -63,10 +61,10 @@ class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
|||||||
formatPriceRange(
|
formatPriceRange(
|
||||||
pricing.overallMin,
|
pricing.overallMin,
|
||||||
pricing.overallMax,
|
pricing.overallMax,
|
||||||
currency: pricing.currency
|
currency: pricing.currency,
|
||||||
)
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (pricing.overallMin != null) {
|
if (pricing.overallMin != null) {
|
||||||
@ -74,9 +72,9 @@ class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().priceOverrideMin),
|
title: Text(L10().priceOverrideMin),
|
||||||
trailing: Text(
|
trailing: Text(
|
||||||
renderCurrency(pricing.overallMin, pricing.overrideMinCurrency)
|
renderCurrency(pricing.overallMin, pricing.overrideMinCurrency),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,9 +83,9 @@ class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().priceOverrideMax),
|
title: Text(L10().priceOverrideMax),
|
||||||
trailing: Text(
|
trailing: Text(
|
||||||
renderCurrency(pricing.overallMax, pricing.overrideMaxCurrency)
|
renderCurrency(pricing.overallMax, pricing.overrideMaxCurrency),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,10 +96,10 @@ class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
|||||||
formatPriceRange(
|
formatPriceRange(
|
||||||
pricing.internalCostMin,
|
pricing.internalCostMin,
|
||||||
pricing.internalCostMax,
|
pricing.internalCostMax,
|
||||||
currency: pricing.currency
|
currency: pricing.currency,
|
||||||
)
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (widget.part.isTemplate) {
|
if (widget.part.isTemplate) {
|
||||||
@ -112,10 +110,10 @@ class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
|||||||
formatPriceRange(
|
formatPriceRange(
|
||||||
pricing.variantCostMin,
|
pricing.variantCostMin,
|
||||||
pricing.variantCostMax,
|
pricing.variantCostMax,
|
||||||
currency: pricing.currency
|
currency: pricing.currency,
|
||||||
)
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,10 +125,10 @@ class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
|||||||
formatPriceRange(
|
formatPriceRange(
|
||||||
pricing.bomCostMin,
|
pricing.bomCostMin,
|
||||||
pricing.bomCostMax,
|
pricing.bomCostMax,
|
||||||
currency: pricing.currency
|
currency: pricing.currency,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,10 +140,10 @@ class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
|||||||
formatPriceRange(
|
formatPriceRange(
|
||||||
pricing.purchaseCostMin,
|
pricing.purchaseCostMin,
|
||||||
pricing.purchaseCostMax,
|
pricing.purchaseCostMax,
|
||||||
currency: pricing.currency
|
currency: pricing.currency,
|
||||||
)
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -155,10 +153,10 @@ class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
|||||||
formatPriceRange(
|
formatPriceRange(
|
||||||
pricing.supplierPriceMin,
|
pricing.supplierPriceMin,
|
||||||
pricing.supplierPriceMax,
|
pricing.supplierPriceMax,
|
||||||
currency: pricing.currency
|
currency: pricing.currency,
|
||||||
)
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,10 +170,10 @@ class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
|||||||
formatPriceRange(
|
formatPriceRange(
|
||||||
pricing.salePriceMin,
|
pricing.salePriceMin,
|
||||||
pricing.salePriceMax,
|
pricing.salePriceMax,
|
||||||
currency: pricing.currency
|
currency: pricing.currency,
|
||||||
)
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -185,14 +183,13 @@ class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
|||||||
formatPriceRange(
|
formatPriceRange(
|
||||||
pricing.saleHistoryMin,
|
pricing.saleHistoryMin,
|
||||||
pricing.saleHistoryMax,
|
pricing.saleHistoryMax,
|
||||||
currency: pricing.currency
|
currency: pricing.currency,
|
||||||
)
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,19 +10,15 @@ import "package:inventree/inventree/company.dart";
|
|||||||
import "package:inventree/widget/refreshable_state.dart";
|
import "package:inventree/widget/refreshable_state.dart";
|
||||||
|
|
||||||
class PartSupplierWidget extends StatefulWidget {
|
class PartSupplierWidget extends StatefulWidget {
|
||||||
|
|
||||||
const PartSupplierWidget(this.part, {Key? key}) : super(key: key);
|
const PartSupplierWidget(this.part, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
final InvenTreePart part;
|
final InvenTreePart part;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PartSupplierState createState() => _PartSupplierState(part);
|
_PartSupplierState createState() => _PartSupplierState(part);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _PartSupplierState extends RefreshableState<PartSupplierWidget> {
|
class _PartSupplierState extends RefreshableState<PartSupplierWidget> {
|
||||||
|
|
||||||
_PartSupplierState(this.part);
|
_PartSupplierState(this.part);
|
||||||
|
|
||||||
final InvenTreePart part;
|
final InvenTreePart part;
|
||||||
@ -46,7 +42,6 @@ class _PartSupplierState extends RefreshableState<PartSupplierWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _supplierPartTile(BuildContext context, int index) {
|
Widget _supplierPartTile(BuildContext context, int index) {
|
||||||
|
|
||||||
InvenTreeSupplierPart _part = _supplierParts[index];
|
InvenTreeSupplierPart _part = _supplierParts[index];
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
@ -73,5 +68,4 @@ class _PartSupplierState extends RefreshableState<PartSupplierWidget> {
|
|||||||
itemBuilder: _supplierPartTile,
|
itemBuilder: _supplierPartTile,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
import "dart:io";
|
import "dart:io";
|
||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
@ -7,17 +5,11 @@ import "package:flutter_overlay_loader/flutter_overlay_loader.dart";
|
|||||||
import "package:inventree/app_colors.dart";
|
import "package:inventree/app_colors.dart";
|
||||||
import "package:one_context/one_context.dart";
|
import "package:one_context/one_context.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A simplified linear progress bar widget,
|
* A simplified linear progress bar widget,
|
||||||
* with standardized color depiction
|
* with standardized color depiction
|
||||||
*/
|
*/
|
||||||
Widget ProgressBar(
|
Widget ProgressBar(double value, {double maximum = 1.0}) {
|
||||||
double value,
|
|
||||||
{
|
|
||||||
double maximum = 1.0
|
|
||||||
}) {
|
|
||||||
|
|
||||||
double v = 0;
|
double v = 0;
|
||||||
|
|
||||||
if (value <= 0 || maximum <= 0) {
|
if (value <= 0 || maximum <= 0) {
|
||||||
@ -33,20 +25,14 @@ Widget ProgressBar(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Construct a circular progress indicator
|
* Construct a circular progress indicator
|
||||||
*/
|
*/
|
||||||
Widget progressIndicator() {
|
Widget progressIndicator() {
|
||||||
|
return Center(child: CircularProgressIndicator());
|
||||||
return Center(
|
|
||||||
child: CircularProgressIndicator()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void showLoadingOverlay() {
|
void showLoadingOverlay() {
|
||||||
|
|
||||||
// Do not show overlay if running unit tests
|
// Do not show overlay if running unit tests
|
||||||
if (Platform.environment.containsKey("FLUTTER_TEST")) {
|
if (Platform.environment.containsKey("FLUTTER_TEST")) {
|
||||||
return;
|
return;
|
||||||
@ -60,11 +46,12 @@ void showLoadingOverlay() {
|
|||||||
|
|
||||||
Loader.show(
|
Loader.show(
|
||||||
context,
|
context,
|
||||||
themeData: Theme.of(context).copyWith(colorScheme: ColorScheme.fromSwatch())
|
themeData: Theme.of(
|
||||||
|
context,
|
||||||
|
).copyWith(colorScheme: ColorScheme.fromSwatch()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void hideLoadingOverlay() {
|
void hideLoadingOverlay() {
|
||||||
if (Loader.isShown) {
|
if (Loader.isShown) {
|
||||||
Loader.hide();
|
Loader.hide();
|
||||||
|
@ -10,12 +10,10 @@ import "package:inventree/widget/back.dart";
|
|||||||
import "package:inventree/widget/drawer.dart";
|
import "package:inventree/widget/drawer.dart";
|
||||||
import "package:inventree/widget/search.dart";
|
import "package:inventree/widget/search.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Simple mixin class which defines simple methods for defining widget properties
|
* Simple mixin class which defines simple methods for defining widget properties
|
||||||
*/
|
*/
|
||||||
mixin BaseWidgetProperties {
|
mixin BaseWidgetProperties {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return a list of appBar actions
|
* Return a list of appBar actions
|
||||||
* By default, no appBar actions are available
|
* By default, no appBar actions are available
|
||||||
@ -23,7 +21,9 @@ mixin BaseWidgetProperties {
|
|||||||
List<Widget> appBarActions(BuildContext context) => [];
|
List<Widget> appBarActions(BuildContext context) => [];
|
||||||
|
|
||||||
// Return a title for the appBar (placeholder)
|
// Return a title for the appBar (placeholder)
|
||||||
String getAppBarTitle() { return "--- app bar ---"; }
|
String getAppBarTitle() {
|
||||||
|
return "--- app bar ---";
|
||||||
|
}
|
||||||
|
|
||||||
// Function to construct a drawer (override if needed)
|
// Function to construct a drawer (override if needed)
|
||||||
Widget getDrawer(BuildContext context) {
|
Widget getDrawer(BuildContext context) {
|
||||||
@ -38,7 +38,6 @@ mixin BaseWidgetProperties {
|
|||||||
|
|
||||||
// Function to construct a body
|
// Function to construct a body
|
||||||
Widget getBody(BuildContext context) {
|
Widget getBody(BuildContext context) {
|
||||||
|
|
||||||
// Default implementation is to return a ListView
|
// Default implementation is to return a ListView
|
||||||
// Override getTiles to replace the internal context
|
// Override getTiles to replace the internal context
|
||||||
return ListView(
|
return ListView(
|
||||||
@ -51,7 +50,6 @@ mixin BaseWidgetProperties {
|
|||||||
* Construct the top AppBar for this view
|
* Construct the top AppBar for this view
|
||||||
*/
|
*/
|
||||||
AppBar? buildAppBar(BuildContext context, GlobalKey<ScaffoldState> key) {
|
AppBar? buildAppBar(BuildContext context, GlobalKey<ScaffoldState> key) {
|
||||||
|
|
||||||
List<Widget> tabs = getTabIcons(context);
|
List<Widget> tabs = getTabIcons(context);
|
||||||
|
|
||||||
return AppBar(
|
return AppBar(
|
||||||
@ -70,8 +68,10 @@ mixin BaseWidgetProperties {
|
|||||||
* - Button to access global search
|
* - Button to access global search
|
||||||
* - Button to access barcode scan
|
* - Button to access barcode scan
|
||||||
*/
|
*/
|
||||||
BottomAppBar? buildBottomAppBar(BuildContext context, GlobalKey<ScaffoldState> key) {
|
BottomAppBar? buildBottomAppBar(
|
||||||
|
BuildContext context,
|
||||||
|
GlobalKey<ScaffoldState> key,
|
||||||
|
) {
|
||||||
const double iconSize = 40;
|
const double iconSize = 40;
|
||||||
|
|
||||||
List<Widget> icons = [
|
List<Widget> icons = [
|
||||||
@ -91,9 +91,7 @@ mixin BaseWidgetProperties {
|
|||||||
if (InvenTreeAPI().checkConnection()) {
|
if (InvenTreeAPI().checkConnection()) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (context) => SearchWidget(true)),
|
||||||
builder: (context) => SearchWidget(true)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -106,7 +104,7 @@ mixin BaseWidgetProperties {
|
|||||||
scanBarcode(context);
|
scanBarcode(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
return BottomAppBar(
|
return BottomAppBar(
|
||||||
@ -125,8 +123,8 @@ mixin BaseWidgetProperties {
|
|||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.max,
|
mainAxisSize: MainAxisSize.max,
|
||||||
children: icons,
|
children: icons,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +144,6 @@ mixin BaseWidgetProperties {
|
|||||||
* Build out action buttons for a given widget
|
* Build out action buttons for a given widget
|
||||||
*/
|
*/
|
||||||
Widget? buildSpeedDial(BuildContext context) {
|
Widget? buildSpeedDial(BuildContext context) {
|
||||||
|
|
||||||
final actions = actionButtons(context);
|
final actions = actionButtons(context);
|
||||||
final barcodeActions = barcodeButtons(context);
|
final barcodeActions = barcodeButtons(context);
|
||||||
|
|
||||||
@ -165,7 +162,7 @@ mixin BaseWidgetProperties {
|
|||||||
spacing: 14,
|
spacing: 14,
|
||||||
childPadding: const EdgeInsets.all(5),
|
childPadding: const EdgeInsets.all(5),
|
||||||
spaceBetweenChildren: 15,
|
spaceBetweenChildren: 15,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,31 +175,25 @@ mixin BaseWidgetProperties {
|
|||||||
spacing: 14,
|
spacing: 14,
|
||||||
childPadding: const EdgeInsets.all(5),
|
childPadding: const EdgeInsets.all(5),
|
||||||
spaceBetweenChildren: 15,
|
spaceBetweenChildren: 15,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Wrap(
|
return Wrap(direction: Axis.horizontal, children: children, spacing: 15);
|
||||||
direction: Axis.horizontal,
|
|
||||||
children: children,
|
|
||||||
spacing: 15,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return list of "tabs" for this widget
|
// Return list of "tabs" for this widget
|
||||||
List<Widget> getTabIcons(BuildContext context) => [];
|
List<Widget> getTabIcons(BuildContext context) => [];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Abstract base class which provides generic "refresh" functionality.
|
* Abstract base class which provides generic "refresh" functionality.
|
||||||
*
|
*
|
||||||
* - Drag down and release to 'refresh' the widget
|
* - Drag down and release to 'refresh' the widget
|
||||||
* - Define some method which runs to 'refresh' the widget state
|
* - Define some method which runs to 'refresh' the widget state
|
||||||
*/
|
*/
|
||||||
abstract class RefreshableState<T extends StatefulWidget> extends State<T> with BaseWidgetProperties {
|
abstract class RefreshableState<T extends StatefulWidget> extends State<T>
|
||||||
|
with BaseWidgetProperties {
|
||||||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
final refreshKey = GlobalKey<RefreshIndicatorState>();
|
final refreshKey = GlobalKey<RefreshIndicatorState>();
|
||||||
|
|
||||||
@ -235,7 +226,6 @@ abstract class RefreshableState<T extends StatefulWidget> extends State<T> with
|
|||||||
|
|
||||||
// Refresh the widget - handler for custom request() method
|
// Refresh the widget - handler for custom request() method
|
||||||
Future<void> refresh(BuildContext context) async {
|
Future<void> refresh(BuildContext context) async {
|
||||||
|
|
||||||
// Escape if the widget is no longer loaded
|
// Escape if the widget is no longer loaded
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
return;
|
return;
|
||||||
@ -259,13 +249,14 @@ abstract class RefreshableState<T extends StatefulWidget> extends State<T> with
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
// Save the context for future use
|
// Save the context for future use
|
||||||
_context = context;
|
_context = context;
|
||||||
|
|
||||||
List<Widget> tabs = getTabIcons(context);
|
List<Widget> tabs = getTabIcons(context);
|
||||||
|
|
||||||
Widget body = tabs.isEmpty ? getBody(context) : TabBarView(children: getTabs(context));
|
Widget body = tabs.isEmpty
|
||||||
|
? getBody(context)
|
||||||
|
: TabBarView(children: getTabs(context));
|
||||||
|
|
||||||
Scaffold view = Scaffold(
|
Scaffold view = Scaffold(
|
||||||
key: scaffoldKey,
|
key: scaffoldKey,
|
||||||
@ -282,17 +273,14 @@ abstract class RefreshableState<T extends StatefulWidget> extends State<T> with
|
|||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
},
|
},
|
||||||
child: body
|
child: body,
|
||||||
),
|
),
|
||||||
bottomNavigationBar: buildBottomAppBar(context, scaffoldKey),
|
bottomNavigationBar: buildBottomAppBar(context, scaffoldKey),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Default implementation is *not* tabbed
|
// Default implementation is *not* tabbed
|
||||||
if (tabs.isNotEmpty) {
|
if (tabs.isNotEmpty) {
|
||||||
return DefaultTabController(
|
return DefaultTabController(length: tabs.length, child: view);
|
||||||
length: tabs.length,
|
|
||||||
child: view,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
@ -23,21 +23,17 @@ import "package:inventree/widget/order/sales_order_list.dart";
|
|||||||
import "package:inventree/widget/company/company_list.dart";
|
import "package:inventree/widget/company/company_list.dart";
|
||||||
import "package:inventree/widget/company/supplier_part_list.dart";
|
import "package:inventree/widget/company/supplier_part_list.dart";
|
||||||
|
|
||||||
|
|
||||||
// Widget for performing database-wide search
|
// Widget for performing database-wide search
|
||||||
class SearchWidget extends StatefulWidget {
|
class SearchWidget extends StatefulWidget {
|
||||||
|
|
||||||
const SearchWidget(this.hasAppbar);
|
const SearchWidget(this.hasAppbar);
|
||||||
|
|
||||||
final bool hasAppbar;
|
final bool hasAppbar;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_SearchDisplayState createState() => _SearchDisplayState(hasAppbar);
|
_SearchDisplayState createState() => _SearchDisplayState(hasAppbar);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
||||||
|
|
||||||
_SearchDisplayState(this.hasAppBar) : super();
|
_SearchDisplayState(this.hasAppBar) : super();
|
||||||
|
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
@ -80,7 +76,6 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
* Determine if the search is still running
|
* Determine if the search is still running
|
||||||
*/
|
*/
|
||||||
bool isSearching() {
|
bool isSearching() {
|
||||||
|
|
||||||
if (searchController.text.isEmpty) {
|
if (searchController.text.isEmpty) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -128,7 +123,6 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
// Callback when the text is being edited
|
// Callback when the text is being edited
|
||||||
// Incorporates a debounce timer to restrict search frequency
|
// Incorporates a debounce timer to restrict search frequency
|
||||||
void onSearchTextChanged(String text, {bool immediate = false}) {
|
void onSearchTextChanged(String text, {bool immediate = false}) {
|
||||||
|
|
||||||
if (debounceTimer?.isActive ?? false) {
|
if (debounceTimer?.isActive ?? false) {
|
||||||
debounceTimer!.cancel();
|
debounceTimer!.cancel();
|
||||||
}
|
}
|
||||||
@ -152,7 +146,6 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
int getSearchResultCount(Map<String, dynamic> results, String key) {
|
int getSearchResultCount(Map<String, dynamic> results, String key) {
|
||||||
|
|
||||||
dynamic result = results[key];
|
dynamic result = results[key];
|
||||||
|
|
||||||
if (result == null || result is! Map) {
|
if (result == null || result is! Map) {
|
||||||
@ -170,16 +163,13 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
|
|
||||||
// Actually perform the search query
|
// Actually perform the search query
|
||||||
Future<void> _perform_search(Map<String, dynamic> body) async {
|
Future<void> _perform_search(Map<String, dynamic> body) async {
|
||||||
InvenTreeAPI().post(
|
InvenTreeAPI().post("search/", body: body, expectedStatusCode: 200).then((
|
||||||
"search/",
|
APIResponse response,
|
||||||
body: body,
|
) {
|
||||||
expectedStatusCode: 200).then((APIResponse response) {
|
|
||||||
|
|
||||||
String searchTerm = (body["search"] ?? "").toString();
|
String searchTerm = (body["search"] ?? "").toString();
|
||||||
|
|
||||||
// Only update if the results correspond to the current search term
|
// Only update if the results correspond to the current search term
|
||||||
if (searchTerm == searchController.text && mounted) {
|
if (searchTerm == searchController.text && mounted) {
|
||||||
|
|
||||||
decrementPendingSearches();
|
decrementPendingSearches();
|
||||||
|
|
||||||
Map<String, dynamic> results = {};
|
Map<String, dynamic> results = {};
|
||||||
@ -188,19 +178,49 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
results = response.data as Map<String, dynamic>;
|
results = response.data as Map<String, dynamic>;
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
nPartResults = getSearchResultCount(results, InvenTreePart.MODEL_TYPE);
|
nPartResults = getSearchResultCount(
|
||||||
nCategoryResults = getSearchResultCount(results, InvenTreePartCategory.MODEL_TYPE);
|
results,
|
||||||
nStockResults = getSearchResultCount(results, InvenTreeStockItem.MODEL_TYPE);
|
InvenTreePart.MODEL_TYPE,
|
||||||
nLocationResults = getSearchResultCount(results, InvenTreeStockLocation.MODEL_TYPE);
|
);
|
||||||
nPurchaseOrderResults = getSearchResultCount(results, InvenTreePurchaseOrder.MODEL_TYPE);
|
nCategoryResults = getSearchResultCount(
|
||||||
nSalesOrderResults = getSearchResultCount(results, InvenTreeSalesOrder.MODEL_TYPE);
|
results,
|
||||||
nSupplierPartResults = getSearchResultCount(results, InvenTreeSupplierPart.MODEL_TYPE);
|
InvenTreePartCategory.MODEL_TYPE,
|
||||||
nManufacturerPartResults = getSearchResultCount(results, InvenTreeManufacturerPart.MODEL_TYPE);
|
);
|
||||||
nCompanyResults = getSearchResultCount(results, InvenTreeCompany.MODEL_TYPE);
|
nStockResults = getSearchResultCount(
|
||||||
|
results,
|
||||||
|
InvenTreeStockItem.MODEL_TYPE,
|
||||||
|
);
|
||||||
|
nLocationResults = getSearchResultCount(
|
||||||
|
results,
|
||||||
|
InvenTreeStockLocation.MODEL_TYPE,
|
||||||
|
);
|
||||||
|
nPurchaseOrderResults = getSearchResultCount(
|
||||||
|
results,
|
||||||
|
InvenTreePurchaseOrder.MODEL_TYPE,
|
||||||
|
);
|
||||||
|
nSalesOrderResults = getSearchResultCount(
|
||||||
|
results,
|
||||||
|
InvenTreeSalesOrder.MODEL_TYPE,
|
||||||
|
);
|
||||||
|
nSupplierPartResults = getSearchResultCount(
|
||||||
|
results,
|
||||||
|
InvenTreeSupplierPart.MODEL_TYPE,
|
||||||
|
);
|
||||||
|
nManufacturerPartResults = getSearchResultCount(
|
||||||
|
results,
|
||||||
|
InvenTreeManufacturerPart.MODEL_TYPE,
|
||||||
|
);
|
||||||
|
nCompanyResults = getSearchResultCount(
|
||||||
|
results,
|
||||||
|
InvenTreeCompany.MODEL_TYPE,
|
||||||
|
);
|
||||||
|
|
||||||
// Special case for company search results
|
// Special case for company search results
|
||||||
nCustomerResults = getSearchResultCount(results, "customer");
|
nCustomerResults = getSearchResultCount(results, "customer");
|
||||||
nManufacturerResults = getSearchResultCount(results, "manufacturer");
|
nManufacturerResults = getSearchResultCount(
|
||||||
|
results,
|
||||||
|
"manufacturer",
|
||||||
|
);
|
||||||
nSupplierResults = getSearchResultCount(results, "supplier");
|
nSupplierResults = getSearchResultCount(results, "supplier");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -237,7 +257,6 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
|
|
||||||
// Consolidated search allows us to perform *all* searches in a single query
|
// Consolidated search allows us to perform *all* searches in a single query
|
||||||
if (api.supportsConsolidatedSearch) {
|
if (api.supportsConsolidatedSearch) {
|
||||||
|
|
||||||
Map<String, dynamic> body = {
|
Map<String, dynamic> body = {
|
||||||
"limit": 1,
|
"limit": 1,
|
||||||
"search": term,
|
"search": term,
|
||||||
@ -262,17 +281,13 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (body.isNotEmpty) {
|
if (body.isNotEmpty) {
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
nPendingSearches = 1;
|
nPendingSearches = 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
_search_query = CancelableOperation.fromFuture(
|
_search_query = CancelableOperation.fromFuture(_perform_search(body));
|
||||||
_perform_search(body),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
legacySearch(term);
|
legacySearch(term);
|
||||||
@ -283,7 +298,6 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
* Perform "legacy" search (without consolidated search API endpoint
|
* Perform "legacy" search (without consolidated search API endpoint
|
||||||
*/
|
*/
|
||||||
Future<void> legacySearch(String term) async {
|
Future<void> legacySearch(String term) async {
|
||||||
|
|
||||||
// Search parts
|
// Search parts
|
||||||
if (InvenTreePart().canView) {
|
if (InvenTreePart().canView) {
|
||||||
nPendingSearches++;
|
nPendingSearches++;
|
||||||
@ -302,7 +316,7 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
// Search part categories
|
// Search part categories
|
||||||
if (InvenTreePartCategory().canView) {
|
if (InvenTreePartCategory().canView) {
|
||||||
nPendingSearches++;
|
nPendingSearches++;
|
||||||
InvenTreePartCategory().count(searchQuery: term,).then((int n) {
|
InvenTreePartCategory().count(searchQuery: term).then((int n) {
|
||||||
if (term == searchController.text) {
|
if (term == searchController.text) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
decrementPendingSearches();
|
decrementPendingSearches();
|
||||||
@ -347,12 +361,9 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
// Search purchase orders
|
// Search purchase orders
|
||||||
if (InvenTreePurchaseOrder().canView) {
|
if (InvenTreePurchaseOrder().canView) {
|
||||||
nPendingSearches++;
|
nPendingSearches++;
|
||||||
InvenTreePurchaseOrder().count(
|
InvenTreePurchaseOrder()
|
||||||
searchQuery: term,
|
.count(searchQuery: term, filters: {"outstanding": "true"})
|
||||||
filters: {
|
.then((int n) {
|
||||||
"outstanding": "true"
|
|
||||||
}
|
|
||||||
).then((int n) {
|
|
||||||
if (term == searchController.text) {
|
if (term == searchController.text) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
decrementPendingSearches();
|
decrementPendingSearches();
|
||||||
@ -367,16 +378,13 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
List<Widget> getTiles(BuildContext context) {
|
List<Widget> getTiles(BuildContext context) {
|
||||||
|
|
||||||
List<Widget> tiles = [];
|
List<Widget> tiles = [];
|
||||||
|
|
||||||
// Search input
|
// Search input
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: TextFormField(
|
title: TextFormField(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(hintText: L10().queryEmpty),
|
||||||
hintText: L10().queryEmpty,
|
|
||||||
),
|
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
readOnly: false,
|
readOnly: false,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
@ -385,12 +393,13 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
onChanged: (String text) {
|
onChanged: (String text) {
|
||||||
onSearchTextChanged(text);
|
onSearchTextChanged(text);
|
||||||
},
|
},
|
||||||
onFieldSubmitted: (String text) {
|
onFieldSubmitted: (String text) {},
|
||||||
},
|
|
||||||
),
|
),
|
||||||
trailing: GestureDetector(
|
trailing: GestureDetector(
|
||||||
child: Icon(
|
child: Icon(
|
||||||
searchController.text.isEmpty ? TablerIcons.search : TablerIcons.backspace,
|
searchController.text.isEmpty
|
||||||
|
? TablerIcons.search
|
||||||
|
: TablerIcons.backspace,
|
||||||
color: searchController.text.isEmpty ? COLOR_ACTION : COLOR_DANGER,
|
color: searchController.text.isEmpty ? COLOR_ACTION : COLOR_DANGER,
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
@ -398,8 +407,7 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
onSearchTextChanged("", immediate: true);
|
onSearchTextChanged("", immediate: true);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
String query = searchController.text;
|
String query = searchController.text;
|
||||||
@ -417,15 +425,11 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => PartList(
|
builder: (context) => PartList({"original_search": query}),
|
||||||
{
|
),
|
||||||
"original_search": query
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,15 +444,12 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => PartCategoryList(
|
builder: (context) =>
|
||||||
{
|
PartCategoryList({"original_search": query}),
|
||||||
"original_search": query
|
),
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,15 +464,11 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => StockItemList(
|
builder: (context) => StockItemList({"original_search": query}),
|
||||||
{
|
),
|
||||||
"original_search": query,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,15 +483,12 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => StockLocationList(
|
builder: (context) =>
|
||||||
{
|
StockLocationList({"original_search": query}),
|
||||||
"original_search": query
|
),
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -510,14 +504,12 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => PurchaseOrderListWidget(
|
builder: (context) => PurchaseOrderListWidget(
|
||||||
filters: {
|
filters: {"original_search": query},
|
||||||
"original_search": query
|
),
|
||||||
}
|
),
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -532,15 +524,12 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => SalesOrderListWidget(
|
builder: (context) =>
|
||||||
filters: {
|
SalesOrderListWidget(filters: {"original_search": query}),
|
||||||
"original_search": query
|
),
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,16 +544,13 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => CompanyListWidget(
|
builder: (context) => CompanyListWidget(L10().companies, {
|
||||||
L10().companies,
|
"original_search": query,
|
||||||
{
|
}),
|
||||||
"original_search": query
|
),
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,17 +565,14 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => CompanyListWidget(
|
builder: (context) => CompanyListWidget(L10().customers, {
|
||||||
L10().customers,
|
|
||||||
{
|
|
||||||
"original_search": query,
|
"original_search": query,
|
||||||
"is_customer": "true"
|
"is_customer": "true",
|
||||||
}
|
}),
|
||||||
)
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -604,17 +587,14 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => CompanyListWidget(
|
builder: (context) => CompanyListWidget(L10().manufacturers, {
|
||||||
L10().manufacturers,
|
|
||||||
{
|
|
||||||
"original_search": query,
|
"original_search": query,
|
||||||
"is_manufacturer": "true"
|
"is_manufacturer": "true",
|
||||||
}
|
}),
|
||||||
)
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -629,17 +609,14 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => CompanyListWidget(
|
builder: (context) => CompanyListWidget(L10().suppliers, {
|
||||||
L10().suppliers,
|
|
||||||
{
|
|
||||||
"original_search": query,
|
"original_search": query,
|
||||||
"is_supplier": "true"
|
"is_supplier": "true",
|
||||||
}
|
}),
|
||||||
)
|
),
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -654,15 +631,12 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => SupplierPartList(
|
builder: (context) =>
|
||||||
{
|
SupplierPartList({"original_search": query}),
|
||||||
"original_search": query
|
),
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -672,7 +646,7 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
title: Text(L10().searching),
|
title: Text(L10().searching),
|
||||||
leading: Icon(TablerIcons.search),
|
leading: Icon(TablerIcons.search),
|
||||||
trailing: CircularProgressIndicator(),
|
trailing: CircularProgressIndicator(),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -684,7 +658,7 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
style: TextStyle(fontStyle: FontStyle.italic),
|
style: TextStyle(fontStyle: FontStyle.italic),
|
||||||
),
|
),
|
||||||
leading: Icon(TablerIcons.zoom_cancel),
|
leading: Icon(TablerIcons.zoom_cancel),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
for (Widget result in results) {
|
for (Widget result in results) {
|
||||||
@ -694,5 +668,4 @@ class _SearchDisplayState extends RefreshableState<SearchWidget> {
|
|||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,13 @@ import "package:inventree/l10.dart";
|
|||||||
/*
|
/*
|
||||||
* Display a configurable 'snackbar' at the bottom of the screen
|
* Display a configurable 'snackbar' at the bottom of the screen
|
||||||
*/
|
*/
|
||||||
void showSnackIcon(String text, {IconData? icon, Function()? onAction, bool? success, String? actionText}) {
|
void showSnackIcon(
|
||||||
|
String text, {
|
||||||
|
IconData? icon,
|
||||||
|
Function()? onAction,
|
||||||
|
bool? success,
|
||||||
|
String? actionText,
|
||||||
|
}) {
|
||||||
debug("showSnackIcon: '${text}'");
|
debug("showSnackIcon: '${text}'");
|
||||||
|
|
||||||
// Escape quickly if we do not have context
|
// Escape quickly if we do not have context
|
||||||
@ -34,7 +39,6 @@ void showSnackIcon(String text, {IconData? icon, Function()? onAction, bool? suc
|
|||||||
if (icon == null && onAction == null) {
|
if (icon == null && onAction == null) {
|
||||||
icon = TablerIcons.circle_check;
|
icon = TablerIcons.circle_check;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (success != null && success == false) {
|
} else if (success != null && success == false) {
|
||||||
backgroundColor = Colors.deepOrange;
|
backgroundColor = Colors.deepOrange;
|
||||||
|
|
||||||
@ -45,35 +49,32 @@ void showSnackIcon(String text, {IconData? icon, Function()? onAction, bool? suc
|
|||||||
|
|
||||||
String _action = actionText ?? L10().details;
|
String _action = actionText ?? L10().details;
|
||||||
|
|
||||||
List<Widget> childs = [
|
List<Widget> childs = [Text(text), Spacer()];
|
||||||
Text(text),
|
|
||||||
Spacer(),
|
|
||||||
];
|
|
||||||
|
|
||||||
if (icon != null) {
|
if (icon != null) {
|
||||||
childs.add(Icon(icon));
|
childs.add(Icon(icon));
|
||||||
}
|
}
|
||||||
|
|
||||||
OneContext().showSnackBar(builder: (context) => SnackBar(
|
OneContext().showSnackBar(
|
||||||
|
builder: (context) => SnackBar(
|
||||||
content: GestureDetector(
|
content: GestureDetector(
|
||||||
child: Row(
|
child: Row(children: childs),
|
||||||
children: childs
|
|
||||||
),
|
|
||||||
onTap: () {
|
onTap: () {
|
||||||
ScaffoldMessenger.of(context!).hideCurrentSnackBar();
|
ScaffoldMessenger.of(context!).hideCurrentSnackBar();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
action: onAction == null ? null : SnackBarAction(
|
action: onAction == null
|
||||||
|
? null
|
||||||
|
: SnackBarAction(
|
||||||
label: _action,
|
label: _action,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// Immediately dismiss the notification
|
// Immediately dismiss the notification
|
||||||
ScaffoldMessenger.of(context!).hideCurrentSnackBar();
|
ScaffoldMessenger.of(context!).hideCurrentSnackBar();
|
||||||
onAction();
|
onAction();
|
||||||
}
|
},
|
||||||
),
|
),
|
||||||
duration: Duration(seconds: onAction == null ? 5 : 10),
|
duration: Duration(seconds: onAction == null ? 5 : 10),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
@ -2,7 +2,6 @@ import "package:flutter/material.dart";
|
|||||||
import "package:inventree/app_colors.dart";
|
import "package:inventree/app_colors.dart";
|
||||||
|
|
||||||
class Spinner extends StatefulWidget {
|
class Spinner extends StatefulWidget {
|
||||||
|
|
||||||
const Spinner({
|
const Spinner({
|
||||||
this.color = COLOR_GRAY_LIGHT,
|
this.color = COLOR_GRAY_LIGHT,
|
||||||
Key? key,
|
Key? key,
|
||||||
@ -27,12 +26,8 @@ class _SpinnerState extends State<Spinner> with SingleTickerProviderStateMixin {
|
|||||||
_controller = AnimationController(
|
_controller = AnimationController(
|
||||||
vsync: this,
|
vsync: this,
|
||||||
duration: Duration(milliseconds: 2000),
|
duration: Duration(milliseconds: 2000),
|
||||||
)
|
)..repeat();
|
||||||
..repeat();
|
_child = Icon(widget.icon, color: widget.color);
|
||||||
_child = Icon(
|
|
||||||
widget.icon,
|
|
||||||
color: widget.color
|
|
||||||
);
|
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
@ -45,9 +40,6 @@ class _SpinnerState extends State<Spinner> with SingleTickerProviderStateMixin {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return RotationTransition(
|
return RotationTransition(turns: _controller!, child: _child);
|
||||||
turns: _controller!,
|
|
||||||
child: _child,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,12 +18,10 @@ import "package:inventree/widget/snacks.dart";
|
|||||||
import "package:inventree/widget/stock/stock_list.dart";
|
import "package:inventree/widget/stock/stock_list.dart";
|
||||||
import "package:inventree/labels.dart";
|
import "package:inventree/labels.dart";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Widget for displaying detail view for a single StockLocation instance
|
* Widget for displaying detail view for a single StockLocation instance
|
||||||
*/
|
*/
|
||||||
class LocationDisplayWidget extends StatefulWidget {
|
class LocationDisplayWidget extends StatefulWidget {
|
||||||
|
|
||||||
LocationDisplayWidget(this.location, {Key? key}) : super(key: key);
|
LocationDisplayWidget(this.location, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
final InvenTreeStockLocation? location;
|
final InvenTreeStockLocation? location;
|
||||||
@ -35,7 +33,6 @@ class LocationDisplayWidget extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
||||||
|
|
||||||
_LocationDisplayState(this.location);
|
_LocationDisplayState(this.location);
|
||||||
|
|
||||||
final InvenTreeStockLocation? location;
|
final InvenTreeStockLocation? location;
|
||||||
@ -59,8 +56,8 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
tooltip: L10().locateLocation,
|
tooltip: L10().locateLocation,
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
api.locateItemOrLocation(context, location: location!.pk);
|
api.locateItemOrLocation(context, location: location!.pk);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,12 +69,11 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
tooltip: L10().editLocation,
|
tooltip: L10().editLocation,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_editLocationDialog(context);
|
_editLocationDialog(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,8 +95,8 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
).then((value) {
|
).then((value) {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +111,7 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
handler: POReceiveBarcodeHandler(location: location),
|
handler: POReceiveBarcodeHandler(location: location),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,18 +128,20 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
).then((value) {
|
).then((value) {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign or un-assign barcodes
|
// Assign or un-assign barcodes
|
||||||
actions.add(
|
actions.add(
|
||||||
customBarcodeAction(
|
customBarcodeAction(
|
||||||
context, this,
|
context,
|
||||||
location!.customBarcode, "stocklocation",
|
this,
|
||||||
location!.pk
|
location!.customBarcode,
|
||||||
)
|
"stocklocation",
|
||||||
|
location!.pk,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,8 +160,8 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
label: L10().locationCreate,
|
label: L10().locationCreate,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
_newLocation(context);
|
_newLocation(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,8 +173,8 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
label: L10().stockItemCreate,
|
label: L10().stockItemCreate,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
_newStockItem(context);
|
_newStockItem(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,10 +189,10 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
labels,
|
labels,
|
||||||
widget.location!.pk,
|
widget.location!.pk,
|
||||||
"location",
|
"location",
|
||||||
"location=${widget.location!.pk}"
|
"location=${widget.location!.pk}",
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +215,7 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
showSnackIcon(L10().locationUpdated, success: true);
|
showSnackIcon(L10().locationUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,22 +236,24 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Map<String, dynamic>> _labels = [];
|
List<Map<String, dynamic>> _labels = [];
|
||||||
bool allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
|
bool allowLabelPrinting = await InvenTreeSettingsManager().getBool(
|
||||||
|
INV_ENABLE_LABEL_PRINTING,
|
||||||
|
true,
|
||||||
|
);
|
||||||
allowLabelPrinting &= api.supportsMixin("labels");
|
allowLabelPrinting &= api.supportsMixin("labels");
|
||||||
|
|
||||||
if (allowLabelPrinting) {
|
if (allowLabelPrinting) {
|
||||||
|
|
||||||
if (widget.location != null) {
|
if (widget.location != null) {
|
||||||
|
String model_type = api.supportsModernLabelPrinting
|
||||||
|
? InvenTreeStockLocation.MODEL_TYPE
|
||||||
|
: "location";
|
||||||
|
String item_key = api.supportsModernLabelPrinting
|
||||||
|
? "items"
|
||||||
|
: "location";
|
||||||
|
|
||||||
String model_type = api.supportsModernLabelPrinting ? InvenTreeStockLocation.MODEL_TYPE : "location";
|
_labels = await getLabelTemplates(model_type, {
|
||||||
String item_key = api.supportsModernLabelPrinting ? "items" : "location";
|
item_key: widget.location!.pk.toString(),
|
||||||
|
});
|
||||||
_labels = await getLabelTemplates(
|
|
||||||
model_type,
|
|
||||||
{
|
|
||||||
item_key: widget.location!.pk.toString()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,9 +270,7 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
InvenTreeStockLocation().createForm(
|
InvenTreeStockLocation().createForm(
|
||||||
context,
|
context,
|
||||||
L10().locationCreate,
|
L10().locationCreate,
|
||||||
data: {
|
data: {"parent": (pk > 0) ? pk : null},
|
||||||
"parent": (pk > 0) ? pk : null,
|
|
||||||
},
|
|
||||||
onSuccess: (result) async {
|
onSuccess: (result) async {
|
||||||
Map<String, dynamic> data = result as Map<String, dynamic>;
|
Map<String, dynamic> data = result as Map<String, dynamic>;
|
||||||
|
|
||||||
@ -280,7 +278,7 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
var loc = InvenTreeStockLocation.fromJson(data);
|
var loc = InvenTreeStockLocation.fromJson(data);
|
||||||
loc.goToDetailPage(context);
|
loc.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +286,6 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
* Launch a dialog form to create a new stock item
|
* Launch a dialog form to create a new stock item
|
||||||
*/
|
*/
|
||||||
Future<void> _newStockItem(BuildContext context) async {
|
Future<void> _newStockItem(BuildContext context) async {
|
||||||
|
|
||||||
var fields = InvenTreeStockItem().formFields();
|
var fields = InvenTreeStockItem().formFields();
|
||||||
|
|
||||||
// Serial number field is not required here
|
// Serial number field is not required here
|
||||||
@ -312,7 +309,7 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
var item = InvenTreeStockItem.fromJson(data);
|
var item = InvenTreeStockItem.fromJson(data);
|
||||||
item.goToDetailPage(context);
|
item.goToDetailPage(context);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,17 +319,19 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
L10().stockTopLevel,
|
L10().stockTopLevel,
|
||||||
style: TextStyle(fontStyle: FontStyle.italic)
|
style: TextStyle(fontStyle: FontStyle.italic),
|
||||||
),
|
),
|
||||||
leading: Icon(TablerIcons.packages),
|
leading: Icon(TablerIcons.packages),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
List<Widget> children = [
|
List<Widget> children = [
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text("${location!.name}"),
|
title: Text("${location!.name}"),
|
||||||
subtitle: Text("${location!.description}"),
|
subtitle: Text("${location!.description}"),
|
||||||
leading: location!.customIcon == null ? Icon(TablerIcons.packages) : Icon(location!.customIcon)
|
leading: location!.customIcon == null
|
||||||
|
? Icon(TablerIcons.packages)
|
||||||
|
: Icon(location!.customIcon),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -346,8 +345,12 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
int parentId = location?.parentId ?? -1;
|
int parentId = location?.parentId ?? -1;
|
||||||
|
|
||||||
if (parentId < 0) {
|
if (parentId < 0) {
|
||||||
Navigator.push(context, MaterialPageRoute(
|
Navigator.push(
|
||||||
builder: (context) => LocationDisplayWidget(null)));
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => LocationDisplayWidget(null),
|
||||||
|
),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
var loc = await InvenTreeStockLocation().get(parentId);
|
var loc = await InvenTreeStockLocation().get(parentId);
|
||||||
@ -358,37 +361,26 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Card(
|
return Card(child: Column(children: children));
|
||||||
child: Column(
|
|
||||||
children: children,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Widget> getTabIcons(BuildContext context) {
|
List<Widget> getTabIcons(BuildContext context) {
|
||||||
return [
|
return [Tab(text: L10().details), Tab(text: L10().stockItems)];
|
||||||
Tab(text: L10().details),
|
|
||||||
Tab(text: L10().stockItems),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Widget> getTabs(BuildContext context) {
|
List<Widget> getTabs(BuildContext context) {
|
||||||
return [
|
return [Column(children: detailTiles()), Column(children: stockTiles())];
|
||||||
Column(children: detailTiles()),
|
|
||||||
Column(children: stockTiles()),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct the "details" panel
|
// Construct the "details" panel
|
||||||
List<Widget> detailTiles() {
|
List<Widget> detailTiles() {
|
||||||
|
|
||||||
Map<String, String> filters = {};
|
Map<String, String> filters = {};
|
||||||
|
|
||||||
int? parent = location?.pk;
|
int? parent = location?.pk;
|
||||||
@ -402,12 +394,9 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
List<Widget> tiles = [
|
List<Widget> tiles = [
|
||||||
locationDescriptionCard(),
|
locationDescriptionCard(),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: PaginatedStockLocationList(
|
child: PaginatedStockLocationList(filters, title: L10().sublocations),
|
||||||
filters,
|
|
||||||
title: L10().sublocations,
|
|
||||||
),
|
|
||||||
flex: 10,
|
flex: 10,
|
||||||
)
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
@ -419,11 +408,6 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
|
|||||||
"location": location?.pk.toString() ?? "null",
|
"location": location?.pk.toString() ?? "null",
|
||||||
};
|
};
|
||||||
|
|
||||||
return [
|
return [Expanded(child: PaginatedStockItemList(filters), flex: 10)];
|
||||||
Expanded(
|
|
||||||
child: PaginatedStockItemList(filters),
|
|
||||||
flex: 10,
|
|
||||||
)
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,7 @@ import "package:inventree/widget/paginator.dart";
|
|||||||
import "package:inventree/widget/refreshable_state.dart";
|
import "package:inventree/widget/refreshable_state.dart";
|
||||||
import "package:inventree/l10.dart";
|
import "package:inventree/l10.dart";
|
||||||
|
|
||||||
|
|
||||||
class StockLocationList extends StatefulWidget {
|
class StockLocationList extends StatefulWidget {
|
||||||
|
|
||||||
const StockLocationList(this.filters);
|
const StockLocationList(this.filters);
|
||||||
|
|
||||||
final Map<String, String> filters;
|
final Map<String, String> filters;
|
||||||
@ -18,9 +16,7 @@ class StockLocationList extends StatefulWidget {
|
|||||||
_StockLocationListState createState() => _StockLocationListState(filters);
|
_StockLocationListState createState() => _StockLocationListState(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _StockLocationListState extends RefreshableState<StockLocationList> {
|
class _StockLocationListState extends RefreshableState<StockLocationList> {
|
||||||
|
|
||||||
_StockLocationListState(this.filters);
|
_StockLocationListState(this.filters);
|
||||||
|
|
||||||
final Map<String, String> filters;
|
final Map<String, String> filters;
|
||||||
@ -34,21 +30,22 @@ class _StockLocationListState extends RefreshableState<StockLocationList> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PaginatedStockLocationList extends PaginatedSearchWidget {
|
class PaginatedStockLocationList extends PaginatedSearchWidget {
|
||||||
|
const PaginatedStockLocationList(
|
||||||
const PaginatedStockLocationList(Map<String, String> filters, {String title = ""}) : super(filters: filters, title: title);
|
Map<String, String> filters, {
|
||||||
|
String title = "",
|
||||||
|
}) : super(filters: filters, title: title);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get searchTitle => title.isNotEmpty ? title : L10().stockLocations;
|
String get searchTitle => title.isNotEmpty ? title : L10().stockLocations;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PaginatedStockLocationListState createState() => _PaginatedStockLocationListState();
|
_PaginatedStockLocationListState createState() =>
|
||||||
|
_PaginatedStockLocationListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _PaginatedStockLocationListState
|
||||||
class _PaginatedStockLocationListState extends PaginatedSearchState<PaginatedStockLocationList> {
|
extends PaginatedSearchState<PaginatedStockLocationList> {
|
||||||
|
|
||||||
_PaginatedStockLocationListState() : super();
|
_PaginatedStockLocationListState() : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -64,20 +61,26 @@ class _PaginatedStockLocationListState extends PaginatedSearchState<PaginatedSto
|
|||||||
"label": L10().includeSublocations,
|
"label": L10().includeSublocations,
|
||||||
"help_text": L10().includeSublocationsDetail,
|
"help_text": L10().includeSublocationsDetail,
|
||||||
"tristate": false,
|
"tristate": false,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
|
int limit,
|
||||||
final page = await InvenTreeStockLocation().listPaginated(limit, offset, filters: params);
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
|
final page = await InvenTreeStockLocation().listPaginated(
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
filters: params,
|
||||||
|
);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||||
|
|
||||||
InvenTreeStockLocation location = model as InvenTreeStockLocation;
|
InvenTreeStockLocation location = model as InvenTreeStockLocation;
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
|
@ -28,9 +28,7 @@ import "package:inventree/widget/stock/stock_item_history.dart";
|
|||||||
import "package:inventree/widget/stock/stock_item_test_results.dart";
|
import "package:inventree/widget/stock/stock_item_test_results.dart";
|
||||||
import "package:inventree/widget/notes_widget.dart";
|
import "package:inventree/widget/notes_widget.dart";
|
||||||
|
|
||||||
|
|
||||||
class StockDetailWidget extends StatefulWidget {
|
class StockDetailWidget extends StatefulWidget {
|
||||||
|
|
||||||
const StockDetailWidget(this.item, {Key? key}) : super(key: key);
|
const StockDetailWidget(this.item, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
final InvenTreeStockItem item;
|
final InvenTreeStockItem item;
|
||||||
@ -39,9 +37,7 @@ class StockDetailWidget extends StatefulWidget {
|
|||||||
_StockItemDisplayState createState() => _StockItemDisplayState();
|
_StockItemDisplayState createState() => _StockItemDisplayState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
||||||
|
|
||||||
_StockItemDisplayState();
|
_StockItemDisplayState();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -67,8 +63,8 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
tooltip: L10().locateItem,
|
tooltip: L10().locateItem,
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
api.locateItemOrLocation(context, item: widget.item.pk);
|
api.locateItemOrLocation(context, item: widget.item.pk);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,8 +75,8 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
tooltip: L10().editItem,
|
tooltip: L10().editItem,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_editStockItem(context);
|
_editStockItem(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,20 +85,17 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
List<SpeedDialChild> actionButtons(BuildContext context) {
|
List<SpeedDialChild> actionButtons(BuildContext context) {
|
||||||
|
|
||||||
List<SpeedDialChild> actions = [];
|
List<SpeedDialChild> actions = [];
|
||||||
|
|
||||||
if (widget.item.canEdit) {
|
if (widget.item.canEdit) {
|
||||||
|
|
||||||
// Stock adjustment actions available if item is *not* serialized
|
// Stock adjustment actions available if item is *not* serialized
|
||||||
if (!widget.item.isSerialized()) {
|
if (!widget.item.isSerialized()) {
|
||||||
|
|
||||||
actions.add(
|
actions.add(
|
||||||
SpeedDialChild(
|
SpeedDialChild(
|
||||||
child: Icon(TablerIcons.circle_check, color: Colors.blue),
|
child: Icon(TablerIcons.circle_check, color: Colors.blue),
|
||||||
label: L10().countStock,
|
label: L10().countStock,
|
||||||
onTap: _countStockDialog,
|
onTap: _countStockDialog,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
actions.add(
|
actions.add(
|
||||||
@ -110,7 +103,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
child: Icon(TablerIcons.circle_minus, color: Colors.red),
|
child: Icon(TablerIcons.circle_minus, color: Colors.red),
|
||||||
label: L10().removeStock,
|
label: L10().removeStock,
|
||||||
onTap: _removeStockDialog,
|
onTap: _removeStockDialog,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
actions.add(
|
actions.add(
|
||||||
@ -118,7 +111,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
child: Icon(TablerIcons.circle_plus, color: Colors.green),
|
child: Icon(TablerIcons.circle_plus, color: Colors.green),
|
||||||
label: L10().addStock,
|
label: L10().addStock,
|
||||||
onTap: _addStockDialog,
|
onTap: _addStockDialog,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,8 +122,8 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
label: L10().transferStock,
|
label: L10().transferStock,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_transferStockDialog(context);
|
_transferStockDialog(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,10 +138,10 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
labels,
|
labels,
|
||||||
widget.item.pk,
|
widget.item.pk,
|
||||||
"stock",
|
"stock",
|
||||||
"item=${widget.item.pk}"
|
"item=${widget.item.pk}",
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,8 +152,8 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
label: L10().stockItemDelete,
|
label: L10().stockItemDelete,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_deleteItem(context);
|
_deleteItem(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,20 +173,22 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
scanBarcode(
|
scanBarcode(
|
||||||
context,
|
context,
|
||||||
handler: StockItemScanIntoLocationHandler(widget.item)
|
handler: StockItemScanIntoLocationHandler(widget.item),
|
||||||
).then((ctx) {
|
).then((ctx) {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
actions.add(
|
actions.add(
|
||||||
customBarcodeAction(
|
customBarcodeAction(
|
||||||
context, this,
|
context,
|
||||||
|
this,
|
||||||
widget.item.customBarcode,
|
widget.item.customBarcode,
|
||||||
"stockitem", widget.item.pk
|
"stockitem",
|
||||||
)
|
widget.item.pk,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,8 +212,12 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
@override
|
@override
|
||||||
Future<void> request(BuildContext context) async {
|
Future<void> request(BuildContext context) async {
|
||||||
await api.StockStatus.load();
|
await api.StockStatus.load();
|
||||||
stockShowHistory = await InvenTreeSettingsManager().getValue(INV_STOCK_SHOW_HISTORY, false) as bool;
|
stockShowHistory =
|
||||||
stockShowTests = await InvenTreeSettingsManager().getValue(INV_STOCK_SHOW_TESTS, true) as bool;
|
await InvenTreeSettingsManager().getValue(INV_STOCK_SHOW_HISTORY, false)
|
||||||
|
as bool;
|
||||||
|
stockShowTests =
|
||||||
|
await InvenTreeSettingsManager().getValue(INV_STOCK_SHOW_TESTS, true)
|
||||||
|
as bool;
|
||||||
|
|
||||||
final bool result = widget.item.pk > 0 && await widget.item.reload();
|
final bool result = widget.item.pk > 0 && await widget.item.reload();
|
||||||
|
|
||||||
@ -238,7 +237,6 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
// Request test results (async)
|
// Request test results (async)
|
||||||
if (stockShowTests) {
|
if (stockShowTests) {
|
||||||
widget.item.getTestResults().then((value) {
|
widget.item.getTestResults().then((value) {
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
// Update
|
// Update
|
||||||
@ -248,7 +246,9 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Request the number of attachments
|
// Request the number of attachments
|
||||||
InvenTreeStockItemAttachment().countAttachments(widget.item.pk).then((int value) {
|
InvenTreeStockItemAttachment().countAttachments(widget.item.pk).then((
|
||||||
|
int value,
|
||||||
|
) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
attachmentCount = value;
|
attachmentCount = value;
|
||||||
@ -258,13 +258,18 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
|
|
||||||
// Request SalesOrder information
|
// Request SalesOrder information
|
||||||
if (widget.item.hasSalesOrder) {
|
if (widget.item.hasSalesOrder) {
|
||||||
InvenTreeSalesOrder().get(widget.item.salesOrderId).then((instance) => {
|
InvenTreeSalesOrder()
|
||||||
if (mounted) {
|
.get(widget.item.salesOrderId)
|
||||||
|
.then(
|
||||||
|
(instance) => {
|
||||||
|
if (mounted)
|
||||||
|
{
|
||||||
setState(() {
|
setState(() {
|
||||||
salesOrder = instance as InvenTreeSalesOrder?;
|
salesOrder = instance as InvenTreeSalesOrder?;
|
||||||
})
|
}),
|
||||||
}
|
},
|
||||||
});
|
},
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -275,13 +280,18 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
|
|
||||||
// Request Customer information
|
// Request Customer information
|
||||||
if (widget.item.hasCustomer) {
|
if (widget.item.hasCustomer) {
|
||||||
InvenTreeCompany().get(widget.item.customerId).then((instance) => {
|
InvenTreeCompany()
|
||||||
if (mounted) {
|
.get(widget.item.customerId)
|
||||||
|
.then(
|
||||||
|
(instance) => {
|
||||||
|
if (mounted)
|
||||||
|
{
|
||||||
setState(() {
|
setState(() {
|
||||||
customer = instance as InvenTreeCompany?;
|
customer = instance as InvenTreeCompany?;
|
||||||
})
|
}),
|
||||||
}
|
},
|
||||||
});
|
},
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -291,22 +301,23 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Map<String, dynamic>> _labels = [];
|
List<Map<String, dynamic>> _labels = [];
|
||||||
bool allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
|
bool allowLabelPrinting = await InvenTreeSettingsManager().getBool(
|
||||||
|
INV_ENABLE_LABEL_PRINTING,
|
||||||
|
true,
|
||||||
|
);
|
||||||
allowLabelPrinting &= api.supportsMixin("labels");
|
allowLabelPrinting &= api.supportsMixin("labels");
|
||||||
|
|
||||||
// Request information on labels available for this stock item
|
// Request information on labels available for this stock item
|
||||||
if (allowLabelPrinting) {
|
if (allowLabelPrinting) {
|
||||||
|
String model_type = api.supportsModernLabelPrinting
|
||||||
String model_type = api.supportsModernLabelPrinting ? InvenTreeStockItem.MODEL_TYPE : "stock";
|
? InvenTreeStockItem.MODEL_TYPE
|
||||||
|
: "stock";
|
||||||
String item_key = api.supportsModernLabelPrinting ? "items" : "item";
|
String item_key = api.supportsModernLabelPrinting ? "items" : "item";
|
||||||
|
|
||||||
// Clear the existing labels list
|
// Clear the existing labels list
|
||||||
_labels = await getLabelTemplates(
|
_labels = await getLabelTemplates(model_type, {
|
||||||
model_type,
|
item_key: widget.item.pk.toString(),
|
||||||
{
|
});
|
||||||
item_key: widget.item.pk.toString()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
@ -318,7 +329,6 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
|
|
||||||
/// Delete the stock item from the database
|
/// Delete the stock item from the database
|
||||||
Future<void> _deleteItem(BuildContext context) async {
|
Future<void> _deleteItem(BuildContext context) async {
|
||||||
|
|
||||||
confirmationDialog(
|
confirmationDialog(
|
||||||
L10().stockItemDelete,
|
L10().stockItemDelete,
|
||||||
L10().stockItemDeleteConfirm,
|
L10().stockItemDeleteConfirm,
|
||||||
@ -336,11 +346,9 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _editStockItem(BuildContext context) async {
|
Future<void> _editStockItem(BuildContext context) async {
|
||||||
|
|
||||||
var fields = InvenTreeStockItem().formFields();
|
var fields = InvenTreeStockItem().formFields();
|
||||||
|
|
||||||
// Some fields we don't want to edit!
|
// Some fields we don't want to edit!
|
||||||
@ -360,16 +368,14 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
showSnackIcon(L10().stockItemUpdated, success: true);
|
showSnackIcon(L10().stockItemUpdated, success: true);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Launch a dialog to 'add' quantity to this StockItem
|
* Launch a dialog to 'add' quantity to this StockItem
|
||||||
*/
|
*/
|
||||||
Future<void> _addStockDialog() async {
|
Future<void> _addStockDialog() async {
|
||||||
|
|
||||||
Map<String, dynamic> fields = {
|
Map<String, dynamic> fields = {
|
||||||
"pk": {
|
"pk": {
|
||||||
"parent": "items",
|
"parent": "items",
|
||||||
@ -377,11 +383,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
"hidden": true,
|
"hidden": true,
|
||||||
"value": widget.item.pk,
|
"value": widget.item.pk,
|
||||||
},
|
},
|
||||||
"quantity": {
|
"quantity": {"parent": "items", "nested": true, "value": 0},
|
||||||
"parent": "items",
|
|
||||||
"nested": true,
|
|
||||||
"value": 0,
|
|
||||||
},
|
|
||||||
"notes": {},
|
"notes": {},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -395,12 +397,11 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
_stockUpdateMessage(true);
|
_stockUpdateMessage(true);
|
||||||
refresh(context);
|
refresh(context);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _stockUpdateMessage(bool result) {
|
void _stockUpdateMessage(bool result) {
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
showSnackIcon(L10().stockItemUpdated, success: true);
|
showSnackIcon(L10().stockItemUpdated, success: true);
|
||||||
}
|
}
|
||||||
@ -410,7 +411,6 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
* Launch a dialog to 'remove' quantity from this StockItem
|
* Launch a dialog to 'remove' quantity from this StockItem
|
||||||
*/
|
*/
|
||||||
void _removeStockDialog() {
|
void _removeStockDialog() {
|
||||||
|
|
||||||
Map<String, dynamic> fields = {
|
Map<String, dynamic> fields = {
|
||||||
"pk": {
|
"pk": {
|
||||||
"parent": "items",
|
"parent": "items",
|
||||||
@ -418,11 +418,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
"hidden": true,
|
"hidden": true,
|
||||||
"value": widget.item.pk,
|
"value": widget.item.pk,
|
||||||
},
|
},
|
||||||
"quantity": {
|
"quantity": {"parent": "items", "nested": true, "value": 0},
|
||||||
"parent": "items",
|
|
||||||
"nested": true,
|
|
||||||
"value": 0,
|
|
||||||
},
|
|
||||||
"notes": {},
|
"notes": {},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -436,12 +432,11 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
_stockUpdateMessage(true);
|
_stockUpdateMessage(true);
|
||||||
refresh(context);
|
refresh(context);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _countStockDialog() async {
|
Future<void> _countStockDialog() async {
|
||||||
|
|
||||||
Map<String, dynamic> fields = {
|
Map<String, dynamic> fields = {
|
||||||
"pk": {
|
"pk": {
|
||||||
"parent": "items",
|
"parent": "items",
|
||||||
@ -467,7 +462,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
_stockUpdateMessage(true);
|
_stockUpdateMessage(true);
|
||||||
refresh(context);
|
refresh(context);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,7 +470,6 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
* Launches an API Form to transfer this stock item to a new location
|
* Launches an API Form to transfer this stock item to a new location
|
||||||
*/
|
*/
|
||||||
Future<void> _transferStockDialog(BuildContext context) async {
|
Future<void> _transferStockDialog(BuildContext context) async {
|
||||||
|
|
||||||
Map<String, dynamic> fields = widget.item.transferFields();
|
Map<String, dynamic> fields = widget.item.transferFields();
|
||||||
|
|
||||||
launchApiForm(
|
launchApiForm(
|
||||||
@ -488,28 +482,22 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
onSuccess: (data) async {
|
onSuccess: (data) async {
|
||||||
_stockUpdateMessage(true);
|
_stockUpdateMessage(true);
|
||||||
refresh(context);
|
refresh(context);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget headerTile() {
|
Widget headerTile() {
|
||||||
|
|
||||||
Widget? trailing;
|
Widget? trailing;
|
||||||
|
|
||||||
if (!widget.item.isInStock) {
|
if (!widget.item.isInStock) {
|
||||||
trailing = Text(
|
trailing = Text(L10().unavailable, style: TextStyle(color: COLOR_DANGER));
|
||||||
L10().unavailable,
|
|
||||||
style: TextStyle(
|
|
||||||
color: COLOR_DANGER
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else if (!widget.item.isSerialized()) {
|
} else if (!widget.item.isSerialized()) {
|
||||||
trailing = Text(
|
trailing = Text(
|
||||||
widget.item.quantityString(),
|
widget.item.quantityString(),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
color: api.StockStatus.color(widget.item.status),
|
color: api.StockStatus.color(widget.item.status),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,7 +509,6 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
trailing: trailing,
|
trailing: trailing,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
if (widget.item.partId > 0) {
|
if (widget.item.partId > 0) {
|
||||||
|
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
var part = await InvenTreePart().get(widget.item.partId);
|
var part = await InvenTreePart().get(widget.item.partId);
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
@ -532,7 +519,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
//trailing: Text(item.serialOrQuantityDisplay()),
|
//trailing: Text(item.serialOrQuantityDisplay()),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -558,15 +545,13 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().stockLocation),
|
title: Text(L10().stockLocation),
|
||||||
subtitle: Text("${widget.item.locationPathString}"),
|
subtitle: Text("${widget.item.locationPathString}"),
|
||||||
leading: Icon(
|
leading: Icon(TablerIcons.location, color: COLOR_ACTION),
|
||||||
TablerIcons.location,
|
|
||||||
color: COLOR_ACTION,
|
|
||||||
),
|
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
if (widget.item.locationId > 0) {
|
if (widget.item.locationId > 0) {
|
||||||
|
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
var loc = await InvenTreeStockLocation().get(widget.item.locationId);
|
var loc = await InvenTreeStockLocation().get(
|
||||||
|
widget.item.locationId,
|
||||||
|
);
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
|
|
||||||
if (loc is InvenTreeStockLocation) {
|
if (loc is InvenTreeStockLocation) {
|
||||||
@ -582,7 +567,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
title: Text(L10().stockLocation),
|
title: Text(L10().stockLocation),
|
||||||
leading: Icon(TablerIcons.location),
|
leading: Icon(TablerIcons.location),
|
||||||
subtitle: Text(L10().locationNotSet),
|
subtitle: Text(L10().locationNotSet),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,15 +578,17 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
title: Text(L10().serialNumber),
|
title: Text(L10().serialNumber),
|
||||||
leading: Icon(TablerIcons.hash),
|
leading: Icon(TablerIcons.hash),
|
||||||
subtitle: Text("${widget.item.serialNumber}"),
|
subtitle: Text("${widget.item.serialNumber}"),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
} else if (widget.item.isInStock) {
|
} else if (widget.item.isInStock) {
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: widget.item.allocated > 0 ? Text(L10().quantityAvailable) : Text(L10().quantity),
|
title: widget.item.allocated > 0
|
||||||
|
? Text(L10().quantityAvailable)
|
||||||
|
: Text(L10().quantity),
|
||||||
leading: Icon(TablerIcons.packages),
|
leading: Icon(TablerIcons.packages),
|
||||||
trailing: Text("${widget.item.quantityString()}"),
|
trailing: Text("${widget.item.quantityString()}"),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -611,18 +598,13 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
leading: Icon(TablerIcons.box_off),
|
leading: Icon(TablerIcons.box_off),
|
||||||
title: Text(
|
title: Text(
|
||||||
L10().unavailable,
|
L10().unavailable,
|
||||||
style: TextStyle(
|
style: TextStyle(color: COLOR_DANGER, fontWeight: FontWeight.bold),
|
||||||
color: COLOR_DANGER,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
L10().unavailableDetail,
|
L10().unavailableDetail,
|
||||||
style: TextStyle(
|
style: TextStyle(color: COLOR_DANGER),
|
||||||
color: COLOR_DANGER
|
),
|
||||||
)
|
),
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,11 +615,9 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
leading: Icon(TablerIcons.help_circle),
|
leading: Icon(TablerIcons.help_circle),
|
||||||
trailing: Text(
|
trailing: Text(
|
||||||
api.StockStatus.label(widget.item.status),
|
api.StockStatus.label(widget.item.status),
|
||||||
style: TextStyle(
|
style: TextStyle(color: api.StockStatus.color(widget.item.status)),
|
||||||
color: api.StockStatus.color(widget.item.status),
|
),
|
||||||
)
|
),
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Supplier part information (if available)
|
// Supplier part information (if available)
|
||||||
@ -647,20 +627,26 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
title: Text(L10().supplierPart),
|
title: Text(L10().supplierPart),
|
||||||
subtitle: Text(widget.item.supplierSKU),
|
subtitle: Text(widget.item.supplierSKU),
|
||||||
leading: Icon(TablerIcons.building, color: COLOR_ACTION),
|
leading: Icon(TablerIcons.building, color: COLOR_ACTION),
|
||||||
trailing: InvenTreeAPI().getThumbnail(widget.item.supplierImage, hideIfNull: true),
|
trailing: InvenTreeAPI().getThumbnail(
|
||||||
|
widget.item.supplierImage,
|
||||||
|
hideIfNull: true,
|
||||||
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
showLoadingOverlay();
|
showLoadingOverlay();
|
||||||
var sp = await InvenTreeSupplierPart().get(
|
var sp = await InvenTreeSupplierPart().get(
|
||||||
widget.item.supplierPartId);
|
widget.item.supplierPartId,
|
||||||
|
);
|
||||||
hideLoadingOverlay();
|
hideLoadingOverlay();
|
||||||
if (sp is InvenTreeSupplierPart) {
|
if (sp is InvenTreeSupplierPart) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context, MaterialPageRoute(
|
context,
|
||||||
builder: (context) => SupplierPartDetailWidget(sp))
|
MaterialPageRoute(
|
||||||
|
builder: (context) => SupplierPartDetailWidget(sp),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -673,7 +659,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
// TODO: Click through to the "build order"
|
// TODO: Click through to the "build order"
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -686,8 +672,8 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
trailing: Text(salesOrder?.reference ?? ""),
|
trailing: Text(salesOrder?.reference ?? ""),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
salesOrder?.goToDetailPage(context);
|
salesOrder?.goToDetailPage(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -701,7 +687,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
customer?.goToDetailPage(context);
|
customer?.goToDetailPage(context);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -711,7 +697,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
title: Text(L10().batchCode),
|
title: Text(L10().batchCode),
|
||||||
subtitle: Text(widget.item.batch),
|
subtitle: Text(widget.item.batch),
|
||||||
leading: Icon(TablerIcons.clipboard_text),
|
leading: Icon(TablerIcons.clipboard_text),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -721,18 +707,23 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
title: Text(L10().packaging),
|
title: Text(L10().packaging),
|
||||||
subtitle: Text(widget.item.packaging),
|
subtitle: Text(widget.item.packaging),
|
||||||
leading: Icon(TablerIcons.package),
|
leading: Icon(TablerIcons.package),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expiryEnabled && widget.item.expiryDate != null) {
|
if (expiryEnabled && widget.item.expiryDate != null) {
|
||||||
|
|
||||||
Widget? _expiryIcon;
|
Widget? _expiryIcon;
|
||||||
|
|
||||||
if (widget.item.expired) {
|
if (widget.item.expired) {
|
||||||
_expiryIcon = Text(L10().expiryExpired, style: TextStyle(color: COLOR_DANGER));
|
_expiryIcon = Text(
|
||||||
|
L10().expiryExpired,
|
||||||
|
style: TextStyle(color: COLOR_DANGER),
|
||||||
|
);
|
||||||
} else if (widget.item.stale) {
|
} else if (widget.item.stale) {
|
||||||
_expiryIcon = Text(L10().expiryStale, style: TextStyle(color: COLOR_WARNING));
|
_expiryIcon = Text(
|
||||||
|
L10().expiryStale,
|
||||||
|
style: TextStyle(color: COLOR_WARNING),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -741,19 +732,18 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
subtitle: Text(widget.item.expiryDateString),
|
subtitle: Text(widget.item.expiryDateString),
|
||||||
leading: Icon(TablerIcons.calendar_x),
|
leading: Icon(TablerIcons.calendar_x),
|
||||||
trailing: _expiryIcon,
|
trailing: _expiryIcon,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Last update?
|
// Last update?
|
||||||
if (widget.item.updatedDateString.isNotEmpty) {
|
if (widget.item.updatedDateString.isNotEmpty) {
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().lastUpdated),
|
title: Text(L10().lastUpdated),
|
||||||
subtitle: Text(widget.item.updatedDateString),
|
subtitle: Text(widget.item.updatedDateString),
|
||||||
leading: Icon(TablerIcons.calendar)
|
leading: Icon(TablerIcons.calendar),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -763,8 +753,8 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().lastStocktake),
|
title: Text(L10().lastStocktake),
|
||||||
subtitle: Text(widget.item.stocktakeDateString),
|
subtitle: Text(widget.item.stocktakeDateString),
|
||||||
leading: Icon(TablerIcons.calendar)
|
leading: Icon(TablerIcons.calendar),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -776,7 +766,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
widget.item.openLink();
|
widget.item.openLink();
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -790,12 +780,13 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => StockItemTestResultsWidget(widget.item))
|
builder: (context) => StockItemTestResultsWidget(widget.item),
|
||||||
|
),
|
||||||
).then((ctx) {
|
).then((ctx) {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -805,9 +796,12 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
title: Text(L10().purchasePrice),
|
title: Text(L10().purchasePrice),
|
||||||
leading: Icon(TablerIcons.currency_dollar),
|
leading: Icon(TablerIcons.currency_dollar),
|
||||||
trailing: Text(
|
trailing: Text(
|
||||||
renderCurrency(widget.item.purchasePrice, widget.item.purchasePriceCurrency)
|
renderCurrency(
|
||||||
)
|
widget.item.purchasePrice,
|
||||||
)
|
widget.item.purchasePriceCurrency,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -823,12 +817,13 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => StockItemHistoryWidget(widget.item))
|
builder: (context) => StockItemHistoryWidget(widget.item),
|
||||||
|
),
|
||||||
).then((ctx) {
|
).then((ctx) {
|
||||||
refresh(context);
|
refresh(context);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -840,10 +835,10 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => NotesWidget(widget.item))
|
MaterialPageRoute(builder: (context) => NotesWidget(widget.item)),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
@ -860,14 +855,13 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
widget.item.pk,
|
widget.item.pk,
|
||||||
L10().stockItem,
|
L10().stockItem,
|
||||||
widget.item.canEdit,
|
widget.item.canEdit,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,10 +14,12 @@ class StockItemHistoryWidget extends StatefulWidget {
|
|||||||
final InvenTreeStockItem item;
|
final InvenTreeStockItem item;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_StockItemHistoryDisplayState createState() => _StockItemHistoryDisplayState(item);
|
_StockItemHistoryDisplayState createState() =>
|
||||||
|
_StockItemHistoryDisplayState(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
class _StockItemHistoryDisplayState extends RefreshableState<StockItemHistoryWidget> {
|
class _StockItemHistoryDisplayState
|
||||||
|
extends RefreshableState<StockItemHistoryWidget> {
|
||||||
_StockItemHistoryDisplayState(this.item);
|
_StockItemHistoryDisplayState(this.item);
|
||||||
|
|
||||||
final InvenTreeStockItem item;
|
final InvenTreeStockItem item;
|
||||||
@ -30,20 +32,18 @@ class _StockItemHistoryDisplayState extends RefreshableState<StockItemHistoryWid
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget getBody(BuildContext context) {
|
Widget getBody(BuildContext context) {
|
||||||
Map<String, String> filters = {
|
Map<String, String> filters = {"item": widget.item.pk.toString()};
|
||||||
"item": widget.item.pk.toString(),
|
|
||||||
};
|
|
||||||
|
|
||||||
return PaginatedStockHistoryList(filters);
|
return PaginatedStockHistoryList(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Widget which displays a paginated stock history list
|
* Widget which displays a paginated stock history list
|
||||||
*/
|
*/
|
||||||
class PaginatedStockHistoryList extends PaginatedSearchWidget {
|
class PaginatedStockHistoryList extends PaginatedSearchWidget {
|
||||||
const PaginatedStockHistoryList(Map<String, String> filters) : super(filters: filters);
|
const PaginatedStockHistoryList(Map<String, String> filters)
|
||||||
|
: super(filters: filters);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get searchTitle => L10().stockItemHistory;
|
String get searchTitle => L10().stockItemHistory;
|
||||||
@ -72,10 +72,17 @@ class _PaginatedStockHistoryState
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
int limit, int offset, Map<String, String> params) async {
|
int limit,
|
||||||
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
await InvenTreeAPI().StockHistoryStatus.load();
|
await InvenTreeAPI().StockHistoryStatus.load();
|
||||||
|
|
||||||
final page = await InvenTreeStockItemHistory().listPaginated(limit, offset, filters: params);
|
final page = await InvenTreeStockItemHistory().listPaginated(
|
||||||
|
limit,
|
||||||
|
offset,
|
||||||
|
filters: params,
|
||||||
|
);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
@ -13,20 +13,18 @@ import "package:inventree/inventree/model.dart";
|
|||||||
import "package:inventree/widget/progress.dart";
|
import "package:inventree/widget/progress.dart";
|
||||||
import "package:inventree/widget/refreshable_state.dart";
|
import "package:inventree/widget/refreshable_state.dart";
|
||||||
|
|
||||||
|
|
||||||
class StockItemTestResultsWidget extends StatefulWidget {
|
class StockItemTestResultsWidget extends StatefulWidget {
|
||||||
|
|
||||||
const StockItemTestResultsWidget(this.item, {Key? key}) : super(key: key);
|
const StockItemTestResultsWidget(this.item, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
final InvenTreeStockItem item;
|
final InvenTreeStockItem item;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_StockItemTestResultDisplayState createState() => _StockItemTestResultDisplayState(item);
|
_StockItemTestResultDisplayState createState() =>
|
||||||
|
_StockItemTestResultDisplayState(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _StockItemTestResultDisplayState
|
||||||
class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestResultsWidget> {
|
extends RefreshableState<StockItemTestResultsWidget> {
|
||||||
|
|
||||||
_StockItemTestResultDisplayState(this.item);
|
_StockItemTestResultDisplayState(this.item);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -46,8 +44,8 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
label: L10().testResultAdd,
|
label: L10().testResultAdd,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
addTestResult(context);
|
addTestResult(context);
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,9 +60,18 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
|
|
||||||
final InvenTreeStockItem item;
|
final InvenTreeStockItem item;
|
||||||
|
|
||||||
Future <void> addTestResult(BuildContext context, {int templateId = 0, String name = "", bool nameIsEditable = true, bool result = false, String value = "", bool valueRequired = false, bool attachmentRequired = false}) async {
|
Future<void> addTestResult(
|
||||||
|
BuildContext context, {
|
||||||
Map<String, Map<String, dynamic>> fields = InvenTreeStockItemTestResult().formFields();
|
int templateId = 0,
|
||||||
|
String name = "",
|
||||||
|
bool nameIsEditable = true,
|
||||||
|
bool result = false,
|
||||||
|
String value = "",
|
||||||
|
bool valueRequired = false,
|
||||||
|
bool attachmentRequired = false,
|
||||||
|
}) async {
|
||||||
|
Map<String, Map<String, dynamic>> fields = InvenTreeStockItemTestResult()
|
||||||
|
.formFields();
|
||||||
|
|
||||||
// Add additional filters
|
// Add additional filters
|
||||||
fields["template"]?["filters"]?["part"] = "${item.partId}";
|
fields["template"]?["filters"]?["part"] = "${item.partId}";
|
||||||
@ -102,7 +109,6 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
bool match = false;
|
bool match = false;
|
||||||
|
|
||||||
for (var ii = 0; ii < outputs.length; ii++) {
|
for (var ii = 0; ii < outputs.length; ii++) {
|
||||||
|
|
||||||
// Check against templates
|
// Check against templates
|
||||||
if (outputs[ii] is InvenTreePartTestTemplate) {
|
if (outputs[ii] is InvenTreePartTestTemplate) {
|
||||||
var template = outputs[ii] as InvenTreePartTestTemplate;
|
var template = outputs[ii] as InvenTreePartTestTemplate;
|
||||||
@ -143,16 +149,17 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
title: Text(item.partName),
|
title: Text(item.partName),
|
||||||
subtitle: Text(item.partDescription),
|
subtitle: Text(item.partDescription),
|
||||||
leading: InvenTreeAPI().getThumbnail(item.partImage),
|
leading: InvenTreeAPI().getThumbnail(item.partImage),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().testResults,
|
title: Text(
|
||||||
style: TextStyle(fontWeight: FontWeight.bold)
|
L10().testResults,
|
||||||
)
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
)
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
@ -163,16 +170,17 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
var results = getTestResults();
|
var results = getTestResults();
|
||||||
|
|
||||||
if (results.isEmpty) {
|
if (results.isEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
|
ListTile(
|
||||||
title: Text(L10().testResultNone),
|
title: Text(L10().testResultNone),
|
||||||
subtitle: Text(L10().testResultNoneDetail),
|
subtitle: Text(L10().testResultNoneDetail),
|
||||||
));
|
),
|
||||||
|
);
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var item in results) {
|
for (var item in results) {
|
||||||
|
|
||||||
bool _hasResult = false;
|
bool _hasResult = false;
|
||||||
bool _required = false;
|
bool _required = false;
|
||||||
String _test = "";
|
String _test = "";
|
||||||
@ -213,11 +221,15 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
_icon = Icon(TablerIcons.circle_x, color: COLOR_DANGER);
|
_icon = Icon(TablerIcons.circle_x, color: COLOR_DANGER);
|
||||||
}
|
}
|
||||||
|
|
||||||
tiles.add(ListTile(
|
tiles.add(
|
||||||
title: Text(_test, style: TextStyle(
|
ListTile(
|
||||||
|
title: Text(
|
||||||
|
_test,
|
||||||
|
style: TextStyle(
|
||||||
fontWeight: _required ? FontWeight.bold : FontWeight.normal,
|
fontWeight: _required ? FontWeight.bold : FontWeight.normal,
|
||||||
fontStyle: _hasResult ? FontStyle.normal : FontStyle.italic
|
fontStyle: _hasResult ? FontStyle.normal : FontStyle.italic,
|
||||||
)),
|
),
|
||||||
|
),
|
||||||
subtitle: Text(_value),
|
subtitle: Text(_value),
|
||||||
trailing: Text(_date),
|
trailing: Text(_date),
|
||||||
leading: _icon,
|
leading: _icon,
|
||||||
@ -229,17 +241,16 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
templateId: _templateId,
|
templateId: _templateId,
|
||||||
nameIsEditable: !_required,
|
nameIsEditable: !_required,
|
||||||
valueRequired: _valueRequired,
|
valueRequired: _valueRequired,
|
||||||
attachmentRequired: _attachmentRequired
|
attachmentRequired: _attachmentRequired,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
));
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tiles.isEmpty) {
|
if (tiles.isEmpty) {
|
||||||
tiles.add(ListTile(
|
tiles.add(ListTile(title: Text(L10().testResultNone)));
|
||||||
title: Text(L10().testResultNone),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tiles;
|
return tiles;
|
||||||
|
@ -7,9 +7,7 @@ import "package:inventree/widget/refreshable_state.dart";
|
|||||||
import "package:inventree/l10.dart";
|
import "package:inventree/l10.dart";
|
||||||
import "package:inventree/api.dart";
|
import "package:inventree/api.dart";
|
||||||
|
|
||||||
|
|
||||||
class StockItemList extends StatefulWidget {
|
class StockItemList extends StatefulWidget {
|
||||||
|
|
||||||
const StockItemList(this.filters);
|
const StockItemList(this.filters);
|
||||||
|
|
||||||
final Map<String, String> filters;
|
final Map<String, String> filters;
|
||||||
@ -18,9 +16,7 @@ class StockItemList extends StatefulWidget {
|
|||||||
_StockListState createState() => _StockListState(filters);
|
_StockListState createState() => _StockListState(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _StockListState extends RefreshableState<StockItemList> {
|
class _StockListState extends RefreshableState<StockItemList> {
|
||||||
|
|
||||||
_StockListState(this.filters);
|
_StockListState(this.filters);
|
||||||
|
|
||||||
final Map<String, String> filters;
|
final Map<String, String> filters;
|
||||||
@ -35,20 +31,18 @@ class _StockListState extends RefreshableState<StockItemList> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PaginatedStockItemList extends PaginatedSearchWidget {
|
class PaginatedStockItemList extends PaginatedSearchWidget {
|
||||||
|
const PaginatedStockItemList(Map<String, String> filters)
|
||||||
const PaginatedStockItemList(Map<String, String> filters) : super(filters: filters);
|
: super(filters: filters);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get searchTitle => L10().stockItems;
|
String get searchTitle => L10().stockItems;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PaginatedStockItemListState createState() => _PaginatedStockItemListState();
|
_PaginatedStockItemListState createState() => _PaginatedStockItemListState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _PaginatedStockItemListState
|
||||||
class _PaginatedStockItemListState extends PaginatedSearchState<PaginatedStockItemList> {
|
extends PaginatedSearchState<PaginatedStockItemList> {
|
||||||
|
|
||||||
_PaginatedStockItemListState() : super();
|
_PaginatedStockItemListState() : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -100,7 +94,7 @@ class _PaginatedStockItemListState extends PaginatedSearchState<PaginatedStockIt
|
|||||||
"label": L10().status,
|
"label": L10().status,
|
||||||
"help_text": L10().statusCode,
|
"help_text": L10().statusCode,
|
||||||
"choices": InvenTreeAPI().StockStatus.choices,
|
"choices": InvenTreeAPI().StockStatus.choices,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!InvenTreeAPI().supportsStatusLabelEndpoints) {
|
if (!InvenTreeAPI().supportsStatusLabelEndpoints) {
|
||||||
@ -111,15 +105,18 @@ class _PaginatedStockItemListState extends PaginatedSearchState<PaginatedStockIt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<InvenTreePageResponse?> requestPage(int limit, int offset, Map<String, String> params) async {
|
Future<InvenTreePageResponse?> requestPage(
|
||||||
|
int limit,
|
||||||
|
int offset,
|
||||||
|
Map<String, String> params,
|
||||||
|
) async {
|
||||||
// Ensure StockStatus codes are loaded
|
// Ensure StockStatus codes are loaded
|
||||||
await InvenTreeAPI().StockStatus.load();
|
await InvenTreeAPI().StockStatus.load();
|
||||||
|
|
||||||
final page = await InvenTreeStockItem().listPaginated(
|
final page = await InvenTreeStockItem().listPaginated(
|
||||||
limit,
|
limit,
|
||||||
offset,
|
offset,
|
||||||
filters: params
|
filters: params,
|
||||||
);
|
);
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
@ -127,7 +124,6 @@ class _PaginatedStockItemListState extends PaginatedSearchState<PaginatedStockIt
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
Widget buildItem(BuildContext context, InvenTreeModel model) {
|
||||||
|
|
||||||
InvenTreeStockItem item = model as InvenTreeStockItem;
|
InvenTreeStockItem item = model as InvenTreeStockItem;
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
@ -136,13 +132,14 @@ class _PaginatedStockItemListState extends PaginatedSearchState<PaginatedStockIt
|
|||||||
leading: InvenTreeAPI().getThumbnail(item.partThumbnail),
|
leading: InvenTreeAPI().getThumbnail(item.partThumbnail),
|
||||||
trailing: SizedBox(
|
trailing: SizedBox(
|
||||||
width: 48,
|
width: 48,
|
||||||
child: Text("${item.displayQuantity}",
|
child: Text(
|
||||||
|
"${item.displayQuantity}",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: InvenTreeAPI().StockStatus.color(item.status),
|
color: InvenTreeAPI().StockStatus.color(item.status),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
item.goToDetailPage(context);
|
item.goToDetailPage(context);
|
||||||
|
@ -10,23 +10,20 @@ import "package:inventree/user_profile.dart";
|
|||||||
|
|
||||||
import "setup.dart";
|
import "setup.dart";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
setupTestEnv();
|
setupTestEnv();
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
|
|
||||||
await setupServerProfile(select: true);
|
await setupServerProfile(select: true);
|
||||||
|
|
||||||
// Ensure the profile is selected
|
// Ensure the profile is selected
|
||||||
assert(! await UserProfileDBManager().selectProfileByName("Missing Profile"));
|
assert(
|
||||||
|
!await UserProfileDBManager().selectProfileByName("Missing Profile"),
|
||||||
|
);
|
||||||
assert(await UserProfileDBManager().selectProfileByName(testServerName));
|
assert(await UserProfileDBManager().selectProfileByName(testServerName));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
group("Login Tests:", () {
|
group("Login Tests:", () {
|
||||||
|
|
||||||
test("Disconnected", () async {
|
test("Disconnected", () async {
|
||||||
// Test that calling disconnect() does the right thing
|
// Test that calling disconnect() does the right thing
|
||||||
var api = InvenTreeAPI();
|
var api = InvenTreeAPI();
|
||||||
@ -37,7 +34,6 @@ void main() {
|
|||||||
expect(api.isConnected(), equals(false));
|
expect(api.isConnected(), equals(false));
|
||||||
expect(api.isConnecting(), equals(false));
|
expect(api.isConnecting(), equals(false));
|
||||||
expect(api.hasToken, equals(false));
|
expect(api.hasToken, equals(false));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Login Failure", () async {
|
test("Login Failure", () async {
|
||||||
@ -66,7 +62,6 @@ void main() {
|
|||||||
|
|
||||||
debugContains("Token request failed: STATUS 401");
|
debugContains("Token request failed: STATUS 401");
|
||||||
debugContains("showSnackIcon: 'Not Connected'");
|
debugContains("showSnackIcon: 'Not Connected'");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Bad Token", () async {
|
test("Bad Token", () async {
|
||||||
@ -125,6 +120,5 @@ void main() {
|
|||||||
debugContains("Received token from server");
|
debugContains("Received token from server");
|
||||||
debugContains("showSnackIcon: 'Connected to Server'");
|
debugContains("showSnackIcon: 'Connected to Server'");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
@ -18,7 +18,6 @@ import "package:inventree/inventree/stock.dart";
|
|||||||
|
|
||||||
import "setup.dart";
|
import "setup.dart";
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
setupTestEnv();
|
setupTestEnv();
|
||||||
|
|
||||||
@ -64,14 +63,12 @@ void main() {
|
|||||||
debugContains("showSnackIcon: 'No match for barcode'");
|
debugContains("showSnackIcon: 'No match for barcode'");
|
||||||
assert(debugMessageCount() == 3);
|
assert(debugMessageCount() == 3);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
group("Test StockItemScanIntoLocationHandler:", () {
|
group("Test StockItemScanIntoLocationHandler:", () {
|
||||||
// Tests for scanning a stock item into a location
|
// Tests for scanning a stock item into a location
|
||||||
|
|
||||||
test("Scan Into Location", () async {
|
test("Scan Into Location", () async {
|
||||||
|
|
||||||
final item = await InvenTreeStockItem().get(1) as InvenTreeStockItem?;
|
final item = await InvenTreeStockItem().get(1) as InvenTreeStockItem?;
|
||||||
assert(item != null);
|
assert(item != null);
|
||||||
|
|
||||||
@ -90,7 +87,6 @@ void main() {
|
|||||||
await handler.processBarcode('{"stocklocation": 1}');
|
await handler.processBarcode('{"stocklocation": 1}');
|
||||||
await item.reload();
|
await item.reload();
|
||||||
assert(item.locationId == 1);
|
assert(item.locationId == 1);
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -98,7 +94,8 @@ void main() {
|
|||||||
// Tests for scanning items into a stock location
|
// Tests for scanning items into a stock location
|
||||||
|
|
||||||
test("Scan In Items", () async {
|
test("Scan In Items", () async {
|
||||||
final location = await InvenTreeStockLocation().get(1) as InvenTreeStockLocation?;
|
final location =
|
||||||
|
await InvenTreeStockLocation().get(1) as InvenTreeStockLocation?;
|
||||||
|
|
||||||
assert(location != null);
|
assert(location != null);
|
||||||
assert(location!.pk == 1);
|
assert(location!.pk == 1);
|
||||||
@ -115,7 +112,6 @@ void main() {
|
|||||||
assert(item!.pk == id);
|
assert(item!.pk == id);
|
||||||
assert(item!.locationId == 1);
|
assert(item!.locationId == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -123,7 +119,8 @@ void main() {
|
|||||||
// Tests for scanning a location into a parent location
|
// Tests for scanning a location into a parent location
|
||||||
|
|
||||||
test("Scan Parent", () async {
|
test("Scan Parent", () async {
|
||||||
final location = await InvenTreeStockLocation().get(7) as InvenTreeStockLocation?;
|
final location =
|
||||||
|
await InvenTreeStockLocation().get(7) as InvenTreeStockLocation?;
|
||||||
|
|
||||||
assert(location != null);
|
assert(location != null);
|
||||||
assert(location!.pk == 7);
|
assert(location!.pk == 7);
|
||||||
@ -146,14 +143,10 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
group("Test PartBarcodes:", () {
|
group("Test PartBarcodes:", () {
|
||||||
|
|
||||||
// Assign a custom barcode to a Part instance
|
// Assign a custom barcode to a Part instance
|
||||||
test("Assign Barcode", () async {
|
test("Assign Barcode", () async {
|
||||||
|
|
||||||
// Unlink barcode first
|
// Unlink barcode first
|
||||||
await InvenTreeAPI().unlinkBarcode({
|
await InvenTreeAPI().unlinkBarcode({"part": "2"});
|
||||||
"part": "2"
|
|
||||||
});
|
|
||||||
|
|
||||||
final part = await InvenTreePart().get(2) as InvenTreePart?;
|
final part = await InvenTreePart().get(2) as InvenTreePart?;
|
||||||
|
|
||||||
@ -164,19 +157,14 @@ void main() {
|
|||||||
assert(part!.customBarcode.isEmpty);
|
assert(part!.customBarcode.isEmpty);
|
||||||
|
|
||||||
// Assign custom barcode data to the part
|
// Assign custom barcode data to the part
|
||||||
await InvenTreeAPI().linkBarcode({
|
await InvenTreeAPI().linkBarcode({"part": "2", "barcode": "xyz-123"});
|
||||||
"part": "2",
|
|
||||||
"barcode": "xyz-123"
|
|
||||||
});
|
|
||||||
|
|
||||||
await part!.reload();
|
await part!.reload();
|
||||||
assert(part.customBarcode.isNotEmpty);
|
assert(part.customBarcode.isNotEmpty);
|
||||||
|
|
||||||
// Check we can de-register a barcode also
|
// Check we can de-register a barcode also
|
||||||
// Unlink barcode first
|
// Unlink barcode first
|
||||||
await InvenTreeAPI().unlinkBarcode({
|
await InvenTreeAPI().unlinkBarcode({"part": "2"});
|
||||||
"part": "2"
|
|
||||||
});
|
|
||||||
|
|
||||||
await part.reload();
|
await part.reload();
|
||||||
assert(part.customBarcode.isEmpty);
|
assert(part.customBarcode.isEmpty);
|
||||||
|
@ -10,7 +10,6 @@ import "package:inventree/inventree/part.dart";
|
|||||||
|
|
||||||
import "setup.dart";
|
import "setup.dart";
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
setupTestEnv();
|
setupTestEnv();
|
||||||
|
|
||||||
@ -35,18 +34,13 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Filter by parent category
|
// Filter by parent category
|
||||||
results = await InvenTreePartCategory().list(
|
results = await InvenTreePartCategory().list(filters: {"parent": "1"});
|
||||||
filters: {
|
|
||||||
"parent": "1",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert(results.length == 3);
|
assert(results.length == 3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group("Part Tests:", () {
|
group("Part Tests:", () {
|
||||||
|
|
||||||
test("Basics", () async {
|
test("Basics", () async {
|
||||||
assert(InvenTreePart().URL == "part/");
|
assert(InvenTreePart().URL == "part/");
|
||||||
});
|
});
|
||||||
@ -68,11 +62,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Filter by category
|
// Filter by category
|
||||||
results = await InvenTreePart().list(
|
results = await InvenTreePart().list(filters: {"category": "2"});
|
||||||
filters: {
|
|
||||||
"category": "2",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert(results.length == 2);
|
assert(results.length == 2);
|
||||||
});
|
});
|
||||||
@ -99,7 +89,6 @@ void main() {
|
|||||||
assert(part.unallocatedStockString == "9000");
|
assert(part.unallocatedStockString == "9000");
|
||||||
assert(part.inStockString == "9000");
|
assert(part.inStockString == "9000");
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Part Adjust", () async {
|
test("Part Adjust", () async {
|
||||||
@ -117,11 +106,7 @@ void main() {
|
|||||||
|
|
||||||
// Change the name to something else
|
// Change the name to something else
|
||||||
|
|
||||||
response = await part.update(
|
response = await part.update(values: {"name": "Woogle"});
|
||||||
values: {
|
|
||||||
"name": "Woogle",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert(response.isValid());
|
assert(response.isValid());
|
||||||
assert(response.statusCode == 200);
|
assert(response.statusCode == 200);
|
||||||
@ -130,11 +115,7 @@ void main() {
|
|||||||
assert(part.name == "Woogle");
|
assert(part.name == "Woogle");
|
||||||
|
|
||||||
// And change it back again
|
// And change it back again
|
||||||
response = await part.update(
|
response = await part.update(values: {"name": "M2x4 LPHS"});
|
||||||
values: {
|
|
||||||
"name": "M2x4 LPHS"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
assert(response.isValid());
|
assert(response.isValid());
|
||||||
assert(response.statusCode == 200);
|
assert(response.statusCode == 200);
|
||||||
@ -144,5 +125,4 @@ void main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
@ -10,23 +10,34 @@ import "setup.dart";
|
|||||||
void main() {
|
void main() {
|
||||||
setupTestEnv();
|
setupTestEnv();
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {});
|
||||||
});
|
|
||||||
|
|
||||||
group("Settings Tests:", () {
|
group("Settings Tests:", () {
|
||||||
test("Default Values", () async {
|
test("Default Values", () async {
|
||||||
// Boolean values
|
// Boolean values
|
||||||
expect(await InvenTreeSettingsManager().getBool("test", false), equals(false));
|
expect(
|
||||||
expect(await InvenTreeSettingsManager().getBool("test", true), equals(true));
|
await InvenTreeSettingsManager().getBool("test", false),
|
||||||
|
equals(false),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
await InvenTreeSettingsManager().getBool("test", true),
|
||||||
|
equals(true),
|
||||||
|
);
|
||||||
|
|
||||||
// String values
|
// String values
|
||||||
expect(await InvenTreeSettingsManager().getValue("test", "x"), equals("x"));
|
expect(
|
||||||
|
await InvenTreeSettingsManager().getValue("test", "x"),
|
||||||
|
equals("x"),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Set value", () async {
|
test("Set value", () async {
|
||||||
await InvenTreeSettingsManager().setValue("abc", "xyz");
|
await InvenTreeSettingsManager().setValue("abc", "xyz");
|
||||||
|
|
||||||
expect(await InvenTreeSettingsManager().getValue("abc", "123"), equals("xyz"));
|
expect(
|
||||||
|
await InvenTreeSettingsManager().getValue("abc", "123"),
|
||||||
|
equals("xyz"),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Booleans", () async {
|
test("Booleans", () async {
|
||||||
@ -36,16 +47,21 @@ void main() {
|
|||||||
|
|
||||||
// Use default values when a setting does not exist
|
// Use default values when a setting does not exist
|
||||||
assert(await InvenTreeSettingsManager().getBool("chicken", true) == true);
|
assert(await InvenTreeSettingsManager().getBool("chicken", true) == true);
|
||||||
assert(await InvenTreeSettingsManager().getBool("chicken", false) == false);
|
assert(
|
||||||
|
await InvenTreeSettingsManager().getBool("chicken", false) == false,
|
||||||
|
);
|
||||||
|
|
||||||
// Explicitly set to true
|
// Explicitly set to true
|
||||||
await InvenTreeSettingsManager().setValue("chicken", true);
|
await InvenTreeSettingsManager().setValue("chicken", true);
|
||||||
assert(await InvenTreeSettingsManager().getBool("chicken", false) == true);
|
assert(
|
||||||
|
await InvenTreeSettingsManager().getBool("chicken", false) == true,
|
||||||
|
);
|
||||||
|
|
||||||
// Explicitly set to false
|
// Explicitly set to false
|
||||||
await InvenTreeSettingsManager().setValue("chicken", false);
|
await InvenTreeSettingsManager().setValue("chicken", false);
|
||||||
assert(await InvenTreeSettingsManager().getBool("chicken", true) == false);
|
assert(
|
||||||
|
await InvenTreeSettingsManager().getBool("chicken", true) == false,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import "package:flutter/services.dart";
|
import "package:flutter/services.dart";
|
||||||
import "package:flutter_test/flutter_test.dart";
|
import "package:flutter_test/flutter_test.dart";
|
||||||
import "package:inventree/api.dart";
|
import "package:inventree/api.dart";
|
||||||
@ -16,7 +15,9 @@ void setupTestEnv() {
|
|||||||
CustomBinding();
|
CustomBinding();
|
||||||
|
|
||||||
// Mock the path provider
|
// Mock the path provider
|
||||||
const MethodChannel channel = MethodChannel("plugins.flutter.io/path_provider");
|
const MethodChannel channel = MethodChannel(
|
||||||
|
"plugins.flutter.io/path_provider",
|
||||||
|
);
|
||||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||||
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
|
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
|
||||||
return ".";
|
return ".";
|
||||||
@ -29,40 +30,43 @@ const String testServerName = "Test Server";
|
|||||||
const String testUsername = "testuser";
|
const String testUsername = "testuser";
|
||||||
const String testPassword = "testpassword";
|
const String testPassword = "testpassword";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Request an API token for the given profile
|
* Request an API token for the given profile
|
||||||
*/
|
*/
|
||||||
Future<bool> fetchProfileToken({
|
Future<bool> fetchProfileToken({
|
||||||
UserProfile? profile,
|
UserProfile? profile,
|
||||||
String username = testUsername,
|
String username = testUsername,
|
||||||
String password = testPassword
|
String password = testPassword,
|
||||||
}) async {
|
}) async {
|
||||||
|
|
||||||
profile ??= await UserProfileDBManager().getProfileByName(testServerName);
|
profile ??= await UserProfileDBManager().getProfileByName(testServerName);
|
||||||
|
|
||||||
assert(profile != null);
|
assert(profile != null);
|
||||||
|
|
||||||
final response = await InvenTreeAPI().fetchToken(profile!, username, password);
|
final response = await InvenTreeAPI().fetchToken(
|
||||||
|
profile!,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
);
|
||||||
return response.successful();
|
return response.successful();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setup a valid profile, and return it
|
* Setup a valid profile, and return it
|
||||||
*/
|
*/
|
||||||
Future<UserProfile> setupServerProfile({bool select = true, bool fetchToken = false}) async {
|
Future<UserProfile> setupServerProfile({
|
||||||
|
bool select = true,
|
||||||
|
bool fetchToken = false,
|
||||||
|
}) async {
|
||||||
// Setup a valid server profile
|
// Setup a valid server profile
|
||||||
|
|
||||||
UserProfile? profile = await UserProfileDBManager().getProfileByName(testServerName);
|
UserProfile? profile = await UserProfileDBManager().getProfileByName(
|
||||||
|
testServerName,
|
||||||
|
);
|
||||||
|
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
// Profile does not already exist - create it!
|
// Profile does not already exist - create it!
|
||||||
bool result = await UserProfileDBManager().addProfile(
|
bool result = await UserProfileDBManager().addProfile(
|
||||||
UserProfile(
|
UserProfile(server: testServerAddress, name: testServerName),
|
||||||
server: testServerAddress,
|
|
||||||
name: testServerName
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(result);
|
assert(result);
|
||||||
@ -84,12 +88,10 @@ Future<UserProfile> setupServerProfile({bool select = true, bool fetchToken = fa
|
|||||||
return profile!;
|
return profile!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Complete all steps necessary to login to the server
|
* Complete all steps necessary to login to the server
|
||||||
*/
|
*/
|
||||||
Future<void> connectToTestServer() async {
|
Future<void> connectToTestServer() async {
|
||||||
|
|
||||||
// Setup profile, and fetch user token as necessary
|
// Setup profile, and fetch user token as necessary
|
||||||
final profile = await setupServerProfile(fetchToken: true);
|
final profile = await setupServerProfile(fetchToken: true);
|
||||||
|
|
||||||
|
@ -26,11 +26,13 @@ void main() {
|
|||||||
expect(profiles.length, equals(0));
|
expect(profiles.length, equals(0));
|
||||||
|
|
||||||
// Now, create one!
|
// Now, create one!
|
||||||
bool result = await UserProfileDBManager().addProfile(UserProfile(
|
bool result = await UserProfileDBManager().addProfile(
|
||||||
|
UserProfile(
|
||||||
name: testServerName,
|
name: testServerName,
|
||||||
server: testServerAddress,
|
server: testServerAddress,
|
||||||
selected: true,
|
selected: true,
|
||||||
));
|
),
|
||||||
|
);
|
||||||
|
|
||||||
expect(result, equals(true));
|
expect(result, equals(true));
|
||||||
|
|
||||||
@ -56,20 +58,15 @@ void main() {
|
|||||||
|
|
||||||
// Run a set of tests for user profile functionality
|
// Run a set of tests for user profile functionality
|
||||||
group("Profile Tests:", () {
|
group("Profile Tests:", () {
|
||||||
|
|
||||||
test("Add Invalid Profiles", () async {
|
test("Add Invalid Profiles", () async {
|
||||||
// Add a profile with missing data
|
// Add a profile with missing data
|
||||||
bool result = await UserProfileDBManager().addProfile(
|
bool result = await UserProfileDBManager().addProfile(UserProfile());
|
||||||
UserProfile()
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result, equals(false));
|
expect(result, equals(false));
|
||||||
|
|
||||||
// Add a profile with a new name
|
// Add a profile with a new name
|
||||||
result = await UserProfileDBManager().addProfile(
|
result = await UserProfileDBManager().addProfile(
|
||||||
UserProfile(
|
UserProfile(name: "Another Test Profile"),
|
||||||
name: "Another Test Profile",
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(result, equals(true));
|
expect(result, equals(true));
|
||||||
@ -81,7 +78,9 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("Profile Name Check", () async {
|
test("Profile Name Check", () async {
|
||||||
bool result = await UserProfileDBManager().profileNameExists("doesnotexist");
|
bool result = await UserProfileDBManager().profileNameExists(
|
||||||
|
"doesnotexist",
|
||||||
|
);
|
||||||
expect(result, equals(false));
|
expect(result, equals(false));
|
||||||
|
|
||||||
result = await UserProfileDBManager().profileNameExists("Test Server");
|
result = await UserProfileDBManager().profileNameExists("Test Server");
|
||||||
@ -100,7 +99,10 @@ void main() {
|
|||||||
expect(p.name, equals(testServerName));
|
expect(p.name, equals(testServerName));
|
||||||
expect(p.server, equals(testServerAddress));
|
expect(p.server, equals(testServerAddress));
|
||||||
|
|
||||||
expect(p.toString(), equals("<${p.key}> Test Server : http://localhost:8000/"));
|
expect(
|
||||||
|
p.toString(),
|
||||||
|
equals("<${p.key}> Test Server : http://localhost:8000/"),
|
||||||
|
);
|
||||||
|
|
||||||
// Test that we can update the profile
|
// Test that we can update the profile
|
||||||
p.name = "different name";
|
p.name = "different name";
|
||||||
@ -110,5 +112,4 @@ void main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter/services.dart";
|
import "package:flutter/services.dart";
|
||||||
import "package:flutter_test/flutter_test.dart";
|
import "package:flutter_test/flutter_test.dart";
|
||||||
@ -7,14 +5,10 @@ import "package:inventree/barcode/barcode.dart";
|
|||||||
import "package:inventree/barcode/wedge_controller.dart";
|
import "package:inventree/barcode/wedge_controller.dart";
|
||||||
import "package:inventree/helpers.dart";
|
import "package:inventree/helpers.dart";
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets("Wedge Scanner Test", (tester) async {
|
testWidgets("Wedge Scanner Test", (tester) async {
|
||||||
|
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
MaterialApp(
|
MaterialApp(home: WedgeBarcodeController(BarcodeScanHandler())),
|
||||||
home: WedgeBarcodeController(BarcodeScanHandler())
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Generate some keyboard data
|
// Generate some keyboard data
|
||||||
@ -27,6 +21,5 @@ void main() {
|
|||||||
debugContains("scanned: abc");
|
debugContains("scanned: abc");
|
||||||
debugContains("No match for barcode");
|
debugContains("No match for barcode");
|
||||||
debugContains("Server Error");
|
debugContains("Server Error");
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
Reference in New Issue
Block a user