mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-16 12:15:31 +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:
@ -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 {
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
|
Reference in New Issue
Block a user