2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-27 04:56:48 +00:00

Stock expiry (#590)

* Add stock expiry getters

* refactor date getters

* Display expiry information

* Update release notes

* Remove unused import
This commit is contained in:
Oliver 2024-12-23 22:25:55 +11:00 committed by GitHub
parent d84f76d482
commit aac13ed5d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 75 additions and 56 deletions

View File

@ -3,6 +3,7 @@
- Fixed error message when printing a label to a remote machine
- Prevent notification sounds from pause media playback
- Display stock expiry information
- Updated translations
### 0.17.1 - December 2024

View File

@ -1532,7 +1532,7 @@ class InvenTreeAPI {
// Return a boolean global setting value
Future<bool> getGlobalBooleanSetting(String key) async {
String value = await getGlobalSetting(key);
return value.toLowerCase() == "true";
return value.toLowerCase().trim() == "true";
}
Future<String> getUserSetting(String key) async {
@ -1557,7 +1557,7 @@ class InvenTreeAPI {
// Return a boolean user setting value
Future<bool> getUserBooleanSetting(String key) async {
String value = await getUserSetting(key);
return value.toLowerCase() == "true";
return value.toLowerCase().trim() == "true";
}
/*

View File

@ -3,6 +3,7 @@ import "dart:io";
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
import "package:flutter/material.dart";
import "package:intl/intl.dart";
import "package:inventree/widget/snacks.dart";
import "package:url_launcher/url_launcher.dart";
import "package:path/path.dart" as path;
@ -156,6 +157,30 @@ class InvenTreeModel {
return value.toString().toLowerCase() == "true";
}
// Helper function to get date value from json data
DateTime? getDate(String key, {DateTime? backup, String subKey = ""}) {
dynamic value = getValue(key, backup: backup, subKey: subKey);
if (value == null) {
return backup;
}
return DateTime.tryParse(value as String);
}
// Helper function to get date as a string
String getDateString(String key, {DateTime? backup, String subKey = ""}) {
DateTime? dt = getDate(key, backup: backup, subKey: subKey);
if (dt == null) {
return "";
}
final DateFormat fmt = DateFormat("yyyy-MM-dd");
return fmt.format(dt);
}
// Return the InvenTree web server URL for this object
String get webUrl {

View File

@ -1,7 +1,5 @@
import "dart:async";
import "package:intl/intl.dart";
import "package:inventree/api.dart";
import "package:inventree/helpers.dart";
import "package:inventree/l10.dart";
@ -107,23 +105,9 @@ class InvenTreeStockItemHistory extends InvenTreeModel {
};
}
DateTime? get date {
if (jsondata.containsKey("date")) {
return DateTime.tryParse((jsondata["date"] ?? "") as String);
} else {
return null;
}
}
DateTime? get date => getDate("date");
String get dateString {
var d = date;
if (d == null) {
return "";
}
return DateFormat("yyyy-MM-dd").format(d);
}
String get dateString => getDateString("date");
String get label => getString("label");
@ -258,6 +242,7 @@ class InvenTreeStockItem extends InvenTreeModel {
"part_detail": "true",
"location_detail": "true",
"supplier_detail": "true",
"supplier_part_detail": "true",
"cascade": "false"
};
}
@ -347,46 +332,22 @@ class InvenTreeStockItem extends InvenTreeModel {
bool get hasCustomer => customerId > 0;
bool get stale => getBool("stale");
bool get expired => getBool("expired");
DateTime? get expiryDate => getDate("expiry_date");
String get expiryDateString => getDateString("expiry_date");
// Date of last update
DateTime? get updatedDate {
if (jsondata.containsKey("updated")) {
return DateTime.tryParse((jsondata["updated"] ?? "") as String);
} else {
return null;
}
}
DateTime? get updatedDate => getDate("updated");
String get updatedDateString {
var _updated = updatedDate;
String get updatedDateString => getDateString("updated");
if (_updated == null) {
return "";
}
DateTime? get stocktakeDate => getDate("stocktake_date");
final DateFormat _format = DateFormat("yyyy-MM-dd");
return _format.format(_updated);
}
DateTime? get stocktakeDate {
if (jsondata.containsKey("stocktake_date")) {
return DateTime.tryParse((jsondata["stocktake_date"] ?? "") as String);
} else {
return null;
}
}
String get stocktakeDateString {
var _stocktake = stocktakeDate;
if (_stocktake == null) {
return "";
}
final DateFormat _format = DateFormat("yyyy-MM-dd");
return _format.format(_stocktake);
}
String get stocktakeDateString => getDateString("stocktake_date");
String get partName {

View File

@ -399,6 +399,15 @@
"errorReportUploadDetails": "Upload anonymous error reports and crash logs",
"@errorReportUploadDetails": {},
"expiryDate": "Expiry Date",
"@expiryDate": {},
"expiryExpired": "Expired",
"@expiryExpired": {},
"expiryStale": "Stale",
"@expiryStale": {},
"feedback": "Feedback",
"@feedback": {},

View File

@ -53,6 +53,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
bool stockShowHistory = false;
bool stockShowTests = true;
bool expiryEnabled = false;
// Linked data fields
InvenTreePart? part;
@ -231,6 +232,8 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
Navigator.of(context).pop();
}
expiryEnabled = await api.getGlobalBooleanSetting("STOCK_ENABLE_EXPIRY");
// Request part information
part = await InvenTreePart().get(widget.item.partId) as InvenTreePart?;
@ -731,6 +734,26 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
);
}
if (expiryEnabled && widget.item.expiryDate != null) {
Widget? _expiryIcon;
if (widget.item.stale) {
_expiryIcon = Text(L10().expiryStale, style: TextStyle(color: COLOR_WARNING));
} else if (widget.item.expired) {
_expiryIcon = Text(L10().expiryExpired, style: TextStyle(color: COLOR_DANGER));
}
tiles.add(
ListTile(
title: Text(L10().expiryDate),
subtitle: Text(widget.item.expiryDateString),
leading: Icon(TablerIcons.calendar_x),
trailing: _expiryIcon,
)
);
}
// Last update?
if (widget.item.updatedDateString.isNotEmpty) {