mirror of
https://github.com/inventree/inventree-app.git
synced 2025-05-14 13:03:11 +00:00
Adds support for currency display (#277)
* Adds a helper function for rendering currency data * Update helper functions for StockItem model * Render purchasePrice correctly for stockitem * Use currency_formatter library instead of money_formatter * Add total price display for purchase order * icon fix
This commit is contained in:
parent
221920cbbe
commit
347e80d8e2
@ -4,6 +4,7 @@
|
|||||||
### 0.10.2 - March 2023
|
### 0.10.2 - March 2023
|
||||||
---
|
---
|
||||||
|
|
||||||
|
- Adds support for proper currency rendering
|
||||||
- Fix icon for supplier part detail widget
|
- Fix icon for supplier part detail widget
|
||||||
|
|
||||||
### 0.10.1 - February 2023
|
### 0.10.1 - February 2023
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import "dart:io";
|
import "dart:io";
|
||||||
|
import "package:currency_formatter/currency_formatter.dart";
|
||||||
|
|
||||||
import "package:audioplayers/audioplayers.dart";
|
import "package:audioplayers/audioplayers.dart";
|
||||||
import "package:one_context/one_context.dart";
|
import "package:one_context/one_context.dart";
|
||||||
@ -77,3 +78,23 @@ Future<void> playAudioFile(String path) async {
|
|||||||
final player = AudioPlayer();
|
final player = AudioPlayer();
|
||||||
player.play(AssetSource(path));
|
player.play(AssetSource(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helper function for rendering a money / currency object as a String
|
||||||
|
*/
|
||||||
|
String renderCurrency(double? amount, String currency, {int decimals = 2}) {
|
||||||
|
|
||||||
|
if (amount == null) return "-";
|
||||||
|
if (amount.isInfinite || amount.isNaN) return "-";
|
||||||
|
|
||||||
|
CurrencyFormatterSettings backupSettings = CurrencyFormatterSettings(
|
||||||
|
symbol: "\$",
|
||||||
|
symbolSide: SymbolSide.left,
|
||||||
|
);
|
||||||
|
|
||||||
|
return CurrencyFormatter.format(
|
||||||
|
amount,
|
||||||
|
CurrencyFormatter.majors[currency.toLowerCase()] ?? backupSettings
|
||||||
|
);
|
||||||
|
}
|
@ -89,6 +89,18 @@ class InvenTreePurchaseOrder extends InvenTreeModel {
|
|||||||
|
|
||||||
bool get isFailed => status == PO_STATUS_CANCELLED || status == PO_STATUS_LOST || status == PO_STATUS_RETURNED;
|
bool get isFailed => status == PO_STATUS_CANCELLED || status == PO_STATUS_LOST || status == PO_STATUS_RETURNED;
|
||||||
|
|
||||||
|
double? get totalPrice {
|
||||||
|
String price = (jsondata["total_price"] ?? "") as String;
|
||||||
|
|
||||||
|
if (price.isEmpty) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return double.tryParse(price);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String get totalPriceCurrency => (jsondata["total_price_currency"] ?? "") as String;
|
||||||
|
|
||||||
Future<List<InvenTreePOLineItem>> getLineItems() async {
|
Future<List<InvenTreePOLineItem>> getLineItems() async {
|
||||||
|
|
||||||
final results = await InvenTreePOLineItem().list(
|
final results = await InvenTreePOLineItem().list(
|
||||||
|
@ -206,6 +206,8 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
},
|
},
|
||||||
"status": {},
|
"status": {},
|
||||||
"batch": {},
|
"batch": {},
|
||||||
|
"purchase_price": {},
|
||||||
|
"purchase_price_currency": {},
|
||||||
"packaging": {},
|
"packaging": {},
|
||||||
"link": {},
|
"link": {},
|
||||||
};
|
};
|
||||||
@ -284,13 +286,21 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
|
|
||||||
int get partId => (jsondata["part"] ?? -1) as int;
|
int get partId => (jsondata["part"] ?? -1) as int;
|
||||||
|
|
||||||
String get purchasePrice => (jsondata["purchase_price"] ?? "") as String;
|
double? get purchasePrice {
|
||||||
|
String pp = (jsondata["purchase_price"] ?? "") as String;
|
||||||
|
|
||||||
|
if (pp.isEmpty) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return double.tryParse(pp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String get purchasePriceCurrency => (jsondata["purchase_price_currency"] ?? "") as String;
|
||||||
|
|
||||||
bool get hasPurchasePrice {
|
bool get hasPurchasePrice {
|
||||||
|
double? pp = purchasePrice;
|
||||||
String pp = purchasePrice;
|
return pp != null && pp > 0;
|
||||||
|
|
||||||
return pp.isNotEmpty && pp.trim() != "-";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int get purchaseOrderId => (jsondata["purchase_order"] ?? -1) as int;
|
int get purchaseOrderId => (jsondata["purchase_order"] ?? -1) as int;
|
||||||
@ -613,7 +623,7 @@ class InvenTreeStockItem extends InvenTreeModel {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1180,6 +1180,9 @@
|
|||||||
"tokenMissingFromResponse": "Access token missing from response",
|
"tokenMissingFromResponse": "Access token missing from response",
|
||||||
"@tokenMissingFromResponse": {},
|
"@tokenMissingFromResponse": {},
|
||||||
|
|
||||||
|
"totalPrice": "Total Price",
|
||||||
|
"@totalPrice": {},
|
||||||
|
|
||||||
"transfer": "Transfer",
|
"transfer": "Transfer",
|
||||||
"@transfer": {
|
"@transfer": {
|
||||||
"description": "transfer"
|
"description": "transfer"
|
||||||
|
@ -158,6 +158,14 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
|
||||||
|
tiles.add(ListTile(
|
||||||
|
title: Text(L10().totalPrice),
|
||||||
|
leading: FaIcon(FontAwesomeIcons.dollarSign),
|
||||||
|
trailing: Text(
|
||||||
|
renderCurrency(widget.order.totalPrice, widget.order.totalPriceCurrency)
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
tiles.add(ListTile(
|
tiles.add(ListTile(
|
||||||
title: Text(L10().received),
|
title: Text(L10().received),
|
||||||
leading: FaIcon(FontAwesomeIcons.clipboardCheck, color: COLOR_CLICK),
|
leading: FaIcon(FontAwesomeIcons.clipboardCheck, color: COLOR_CLICK),
|
||||||
@ -407,7 +415,7 @@ class _PurchaseOrderDetailState extends RefreshableState<PurchaseOrderDetailWidg
|
|||||||
onTap: onTabSelectionChanged,
|
onTap: onTabSelectionChanged,
|
||||||
items: [
|
items: [
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
icon: FaIcon(FontAwesomeIcons.info),
|
icon: FaIcon(FontAwesomeIcons.circleInfo),
|
||||||
label: L10().details
|
label: L10().details
|
||||||
),
|
),
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
|
@ -4,6 +4,7 @@ import "package:font_awesome_flutter/font_awesome_flutter.dart";
|
|||||||
|
|
||||||
import "package:inventree/app_colors.dart";
|
import "package:inventree/app_colors.dart";
|
||||||
import "package:inventree/barcode.dart";
|
import "package:inventree/barcode.dart";
|
||||||
|
import "package:inventree/helpers.dart";
|
||||||
import "package:inventree/l10.dart";
|
import "package:inventree/l10.dart";
|
||||||
import "package:inventree/api.dart";
|
import "package:inventree/api.dart";
|
||||||
import "package:inventree/api_form.dart";
|
import "package:inventree/api_form.dart";
|
||||||
@ -675,7 +676,9 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().purchasePrice),
|
title: Text(L10().purchasePrice),
|
||||||
leading: FaIcon(FontAwesomeIcons.dollarSign),
|
leading: FaIcon(FontAwesomeIcons.dollarSign),
|
||||||
trailing: Text(widget.item.purchasePrice),
|
trailing: Text(
|
||||||
|
renderCurrency(widget.item.purchasePrice, widget.item.purchasePriceCurrency)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
16
pubspec.lock
16
pubspec.lock
@ -257,6 +257,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.5"
|
version: "1.0.5"
|
||||||
|
currency_formatter:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: currency_formatter
|
||||||
|
sha256: "24034a969f21a55071b1cf835655c1fb1fd94e3acd498a77283e945002591fb6"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.0"
|
||||||
datetime_picker_formfield:
|
datetime_picker_formfield:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -1034,6 +1042,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.1"
|
version: "1.3.1"
|
||||||
|
universal_io:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: universal_io
|
||||||
|
sha256: "06866290206d196064fd61df4c7aea1ffe9a4e7c4ccaa8fcded42dd41948005d"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.0"
|
||||||
url_launcher:
|
url_launcher:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -11,6 +11,7 @@ dependencies:
|
|||||||
cached_network_image: ^3.2.0 # Download and cache remote images
|
cached_network_image: ^3.2.0 # Download and cache remote images
|
||||||
camera: ^0.10.3 # Camera
|
camera: ^0.10.3 # Camera
|
||||||
cupertino_icons: ^1.0.3
|
cupertino_icons: ^1.0.3
|
||||||
|
currency_formatter: ^2.0.0
|
||||||
datetime_picker_formfield: ^2.0.0 # Date / time picker
|
datetime_picker_formfield: ^2.0.0 # Date / time picker
|
||||||
device_info_plus: ^8.0.0 # Information about the device
|
device_info_plus: ^8.0.0 # Information about the device
|
||||||
dropdown_search: ^5.0.5 # Dropdown autocomplete form fields
|
dropdown_search: ^5.0.5 # Dropdown autocomplete form fields
|
||||||
|
Loading…
x
Reference in New Issue
Block a user