Convert currencies

This commit is contained in:
Hillel Coren 2017-12-21 10:05:33 +02:00
parent 4683f66fc6
commit d6590455f1
2 changed files with 15 additions and 2 deletions

View File

@ -30,7 +30,7 @@ class ProductDatatable extends EntityDatatable
[ [
'cost', 'cost',
function ($model) { function ($model) {
return Utils::roundSignificant($model->cost); return Utils::formatMoney($model->cost);
}, },
], ],
[ [

View File

@ -1037,7 +1037,20 @@ ko.bindingHandlers.productTypeahead = {
} }
if (parseFloat(datum.cost)) { if (parseFloat(datum.cost)) {
if (! model.cost() || ! model.task_public_id()) { if (! model.cost() || ! model.task_public_id()) {
model.cost(roundSignificant(datum.cost, true)); // optionally handle curency conversion
var cost = datum.cost;
var client = window.model.invoice().client();
if (client) {
var clientCurrencyId = client.currency_id();
if (clientCurrencyId) {
var accountCurrencyId = {{ $account->getCurrencyId() }};
cost = fx.convert(cost, {
from: currencyMap[accountCurrencyId].code,
to: currencyMap[clientCurrencyId].code,
});
}
}
model.cost(roundSignificant(cost, true));
} }
} }
if (!model.qty() && ! model.task_public_id()) { if (!model.qty() && ! model.task_public_id()) {