mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-16 04:05:28 +00:00
Part pricing detail (#655)
* Implement part pricing data and new part pricing widget * improve part pricing widget and part pricing data. Add part pricing setting. * Refactor helper func * Tweak translated string * Refactor part pricing page * Update release notes * Fixes * More cleanup --------- Co-authored-by: JarEXE <eykenj@gmail.com>
This commit is contained in:
@ -140,8 +140,7 @@ Future<void> openLink(String url) async {
|
||||
*/
|
||||
String renderCurrency(double? amount, String currency, {int decimals = 2}) {
|
||||
|
||||
if (amount == null) return "-";
|
||||
if (amount.isInfinite || amount.isNaN) return "-";
|
||||
if (amount == null || amount.isInfinite || amount.isNaN) return "-";
|
||||
|
||||
currency = currency.trim();
|
||||
|
||||
@ -157,3 +156,34 @@ String renderCurrency(double? amount, String currency, {int decimals = 2}) {
|
||||
return value;
|
||||
}
|
||||
|
||||
bool isValidNumber(double? value) {
|
||||
return value != null && !value.isNaN && !value.isInfinite;
|
||||
}
|
||||
|
||||
/*
|
||||
* Render a "range" of prices between two values.
|
||||
*/
|
||||
String formatPriceRange(double? minPrice, double? maxPrice, { String? currency }) {
|
||||
|
||||
// Account for empty or null values
|
||||
if (!isValidNumber(minPrice) && !isValidNumber(maxPrice)) {
|
||||
return "-";
|
||||
}
|
||||
|
||||
if (isValidNumber(minPrice) && isValidNumber(maxPrice)) {
|
||||
// Two values are equal
|
||||
if (minPrice == maxPrice) {
|
||||
return renderCurrency(minPrice, currency ?? "USD");
|
||||
} else {
|
||||
return "${renderCurrency(minPrice, currency ?? "USD")} - ${renderCurrency(maxPrice, currency ?? "USD")}";
|
||||
}
|
||||
}
|
||||
|
||||
if (isValidNumber(minPrice)) {
|
||||
return renderCurrency(minPrice, currency ?? "USD");
|
||||
} else if (isValidNumber(maxPrice)) {
|
||||
return renderCurrency(maxPrice, currency ?? "USD");
|
||||
} else {
|
||||
return "-";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user