Added exchange rate

This commit is contained in:
Hillel Coren 2020-08-24 13:27:01 +03:00
parent 51436e1fa4
commit a3a621a2ae
4 changed files with 9 additions and 14 deletions

View File

@ -256,14 +256,16 @@ void handleProductAction(
switch (action) {
case EntityAction.newInvoice:
final invoice = InvoiceEntity(state: state);
createEntity(
context: context,
entity: InvoiceEntity(state: state).rebuild(
entity: invoice.rebuild(
(b) => b
..lineItems.addAll(
productIds.map(
(productId) => convertProductToInvoiceItem(
company: state.company,
invoice: invoice,
product: state.productState.map[productId],
currencyMap: state.staticState.currencyMap,
),

View File

@ -9,6 +9,7 @@ import 'package:invoiceninja_flutter/redux/ui/list_ui_state.dart';
InvoiceItemEntity convertProductToInvoiceItem({
@required ProductEntity product,
@required CompanyEntity company,
@required InvoiceEntity invoice,
@required BuiltMap<String, CurrencyEntity> currencyMap,
ClientEntity client,
}) {
@ -18,11 +19,8 @@ InvoiceItemEntity convertProductToInvoiceItem({
if (company.convertProductExchangeRate &&
client != null &&
client.currencyId != company.currencyId) {
cost = cost *
getExchangeRateWithMap(currencyMap,
fromCurrencyId: company.currencyId,
toCurrencyId: client.currencyId);
cost = round(cost, currencyMap[client.currencyId].precision);
cost = round(cost * invoice.exchangeRate,
currencyMap[client.currencyId].precision);
}
return InvoiceItemEntity().rebuild((b) => b

View File

@ -181,11 +181,8 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
final product = productState.map[productId];
final client =
state.clientState.get(invoice.clientId);
final currencyId = client.getCurrencyId(
company: company,
group: state.groupState.get(client.groupId));
final currency =
state.staticState.currencyMap[currencyId];
state.staticState.currencyMap[client.currencyId];
double cost = product.price;
if (company.convertProductExchangeRate &&
@ -225,9 +222,6 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
final item = lineItems[index];
final product = productState.map[suggestion];
final client = state.clientState.get(invoice.clientId);
final currencyId = client.getCurrencyId(
company: company,
group: state.groupState.get(client.groupId));
double cost = product.price;
if (company.convertProductExchangeRate &&
@ -235,7 +229,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
client.currencyId != company.currencyId) {
cost = round(
cost * invoice.exchangeRate,
state.staticState.currencyMap[currencyId]
state.staticState.currencyMap[client?.currencyId]
.precision);
}

View File

@ -70,6 +70,7 @@ class _InvoiceItemSelectorState extends State<InvoiceItemSelector>
convertProductToInvoiceItem(
company: company,
product: entity as ProductEntity,
invoice: state.invoiceUIState.editing,
currencyMap: state.staticState.currencyMap,
client: state.clientState.get(widget.clientId),
),