Replace native with primary

This commit is contained in:
Sander Dorigo
2025-08-01 12:40:54 +02:00
parent 6278662014
commit cfb86c683e
11 changed files with 55 additions and 60 deletions

View File

@@ -46,7 +46,7 @@ export default () => ({
}, },
eventListeners: { eventListeners: {
['@convert-to-native.window'](event){ ['@convert-to-primary.window'](event){
console.log('I heard that! (dashboard/accounts)'); console.log('I heard that! (dashboard/accounts)');
this.convertToPrimary = event.detail; this.convertToPrimary = event.detail;
this.accountList = []; this.accountList = [];
@@ -99,17 +99,17 @@ export default () => ({
} }
dataset.label = current.label; dataset.label = current.label;
// use the "native" currency code and use the "native_entries" as array // use the "primary" currency code and use the "pc_entries" as array
if (this.convertToPrimary) { if (this.convertToPrimary) {
currencies.push(current.native_currency_code); currencies.push(current.primary_currency_code);
dataset.currency_code = current.native_currency_code; dataset.currency_code = current.primary_currency_code;
if(!current.hasOwnProperty('native_entries')) { if(!current.hasOwnProperty('pc_entries')) {
console.error('No native entries ('+this.convertToPrimary+') found for account: ', current); console.error('No primary entries ('+this.convertToPrimary+') found for account: ', current);
} }
if(current.hasOwnProperty('native_entries')) { if(current.hasOwnProperty('pc_entries')) {
collection = Object.values(current.native_entries); collection = Object.values(current.pc_entries);
} }
yAxis = 'y' + current.native_currency_code; yAxis = 'y' + current.primary_currency_code;
} }
if (!this.convertToPrimary) { if (!this.convertToPrimary) {
yAxis = 'y' + current.currency_code; yAxis = 'y' + current.currency_code;
@@ -240,12 +240,10 @@ export default () => ({
for (let iii = 0; iii < current.attributes.transactions.length; iii++) { for (let iii = 0; iii < current.attributes.transactions.length; iii++) {
let currentTransaction = current.attributes.transactions[iii]; let currentTransaction = current.attributes.transactions[iii];
//console.log(currentTransaction); //console.log(currentTransaction);
//let nativeAmountRaw = 'withdrawal' === currentTransaction.type ? parseFloat(currentTransaction.native_amount) * -1 : parseFloat(currentTransaction.native_amount);
let amountRaw = 'withdrawal' === currentTransaction.type ? parseFloat(currentTransaction.amount) * -1 : parseFloat(currentTransaction.amount); let amountRaw = 'withdrawal' === currentTransaction.type ? parseFloat(currentTransaction.amount) * -1 : parseFloat(currentTransaction.amount);
// if transfer and source is this account, multiply again // if transfer and source is this account, multiply again
if('transfer' === currentTransaction.type && parseInt(currentTransaction.source_id) === accountId) { // if('transfer' === currentTransaction.type && parseInt(currentTransaction.source_id) === accountId) { //
// nativeAmountRaw = nativeAmountRaw * -1;
amountRaw = amountRaw * -1; amountRaw = amountRaw * -1;
} }
@@ -255,8 +253,6 @@ export default () => ({
type: currentTransaction.type, type: currentTransaction.type,
amount_raw: amountRaw, amount_raw: amountRaw,
amount: formatMoney(amountRaw, currentTransaction.currency_code), amount: formatMoney(amountRaw, currentTransaction.currency_code),
// native_amount_raw: nativeAmountRaw,
// native_amount: formatMoney(nativeAmountRaw, currentTransaction.native_currency_code),
}); });
} }
groups.push(group); groups.push(group);
@@ -290,7 +286,7 @@ export default () => ({
// console.log('accounts init'); // console.log('accounts init');
Promise.all([ Promise.all([
getVariable('viewRange', '1M'), // 0 getVariable('viewRange', '1M'), // 0
getVariable('convert_to_native', false), // 1 getVariable('convert_to_primary', false), // 1
getVariable('language', 'en_US'), // 2 getVariable('language', 'en_US'), // 2
getConfiguration('cer.enabled', false) // 3 getConfiguration('cer.enabled', false) // 3
]).then((values) => { ]).then((values) => {
@@ -314,7 +310,7 @@ export default () => ({
this.loadChart(); this.loadChart();
this.loadAccounts(); this.loadAccounts();
}); });
window.store.observe('convert_to_native', () => { window.store.observe('convert_to_primary', () => {
if (!afterPromises) { if (!afterPromises) {
return; return;
} }

View File

@@ -36,7 +36,7 @@ export default () => ({
boxData: null, boxData: null,
boxOptions: null, boxOptions: null,
eventListeners: { eventListeners: {
['@convert-to-native.window'](event){ ['@convert-to-primary.window'](event){
this.convertToPrimary = event.detail; this.convertToPrimary = event.detail;
this.accountList = []; this.accountList = [];
console.log('I heard that! (dashboard/boxes)'); console.log('I heard that! (dashboard/boxes)');
@@ -86,7 +86,7 @@ export default () => ({
continue; continue;
} }
let key = current.key; let key = current.key;
// console.log('NOT NATIVE'); // console.log('NOT PRIMARY CURRENCY');
if (key.startsWith('balance-in-')) { if (key.startsWith('balance-in-')) {
this.balanceBox.amounts.push(formatMoney(current.monetary_value, current.currency_code)); this.balanceBox.amounts.push(formatMoney(current.monetary_value, current.currency_code));
continue; continue;
@@ -163,7 +163,7 @@ export default () => ({
init() { init() {
// console.log('boxes init'); // console.log('boxes init');
// TODO can be replaced by "getVariables" // TODO can be replaced by "getVariables"
Promise.all([getVariable('viewRange'), getVariable('convert_to_native', false)]).then((values) => { Promise.all([getVariable('viewRange'), getVariable('convert_to_primary', false)]).then((values) => {
// console.log('boxes after promises'); // console.log('boxes after promises');
afterPromises = true; afterPromises = true;
this.convertToPrimary = values[1]; this.convertToPrimary = values[1];
@@ -177,7 +177,7 @@ export default () => ({
this.boxData = null; this.boxData = null;
this.loadBoxes(); this.loadBoxes();
}); });
window.store.observe('convert_to_native', (newValue) => { window.store.observe('convert_to_primary', (newValue) => {
if (!afterPromises) { if (!afterPromises) {
return; return;
} }

View File

@@ -50,7 +50,7 @@ export default () => ({
}, },
eventListeners: { eventListeners: {
['@convert-to-native.window'](event){ ['@convert-to-primary.window'](event){
console.log('I heard that! (dashboard/budgets)'); console.log('I heard that! (dashboard/budgets)');
this.convertToPrimary = event.detail; this.convertToPrimary = event.detail;
chartData = null; chartData = null;
@@ -167,7 +167,7 @@ export default () => ({
init() { init() {
Promise.all([getVariable('convert_to_native', false)]).then((values) => { Promise.all([getVariable('convert_to_primary', false)]).then((values) => {
this.convertToPrimary = values[0]; this.convertToPrimary = values[0];
afterPromises = true; afterPromises = true;
if (false === this.loading) { if (false === this.loading) {
@@ -184,7 +184,7 @@ export default () => ({
this.loadChart(); this.loadChart();
} }
}); });
window.store.observe('convert_to_native', (newValue) => { window.store.observe('convert_to_primary', (newValue) => {
if (!afterPromises) { if (!afterPromises) {
return; return;
} }

View File

@@ -35,7 +35,7 @@ export default () => ({
convertToPrimary: false, convertToPrimary: false,
eventListeners: { eventListeners: {
['@convert-to-native.window'](event){ ['@convert-to-primary.window'](event){
console.log('I heard that! (dashboard/categories)'); console.log('I heard that! (dashboard/categories)');
this.convertToPrimary = event.detail; this.convertToPrimary = event.detail;
chartData = null; chartData = null;
@@ -182,7 +182,7 @@ export default () => ({
}, },
init() { init() {
// console.log('categories init'); // console.log('categories init');
Promise.all([getVariable('convert_to_native', false),]).then((values) => { Promise.all([getVariable('convert_to_primary', false),]).then((values) => {
this.convertToPrimary = values[0]; this.convertToPrimary = values[0];
afterPromises = true; afterPromises = true;
this.loadChart(); this.loadChart();
@@ -194,7 +194,7 @@ export default () => ({
this.chartData = null; this.chartData = null;
this.loadChart(); this.loadChart();
}); });
window.store.observe('convert_to_native', (newValue) => { window.store.observe('convert_to_primary', (newValue) => {
if (!afterPromises) { if (!afterPromises) {
return; return;
} }

View File

@@ -70,15 +70,15 @@ Chart.register({
let index = function () { let index = function () {
return { return {
convertToPrimary: false, convertToPrimary: false,
saveNativeSettings(event) { savePrimarySettings(event) {
let target = event.currentTarget || event.target; let target = event.currentTarget || event.target;
setVariable('convert_to_native',target.checked).then(() => { setVariable('convert_to_primary',target.checked).then(() => {
console.log('Set convert to native to: ', target.checked); console.log('Set convert to primary to: ', target.checked);
this.$dispatch('convert-to-native', target.checked); this.$dispatch('convert-to-primary', target.checked);
}); });
}, },
init() { init() {
Promise.all([getVariable('convert_to_native', false)]).then((values) => { Promise.all([getVariable('convert_to_primary', false)]).then((values) => {
this.convertToPrimary = values[0]; this.convertToPrimary = values[0];
}); });
} }

View File

@@ -96,14 +96,14 @@ export default () => ({
id: current.id, id: current.id,
name: current.attributes.name, name: current.attributes.name,
percentage: parseInt(current.attributes.percentage), percentage: parseInt(current.attributes.percentage),
amount: this.convertToPrimary ? current.attributes.native_current_amount : current.attributes.current_amount, amount: this.convertToPrimary ? current.attributes.pc_current_amount : current.attributes.current_amount,
// left to save // left to save
left_to_save: this.convertToPrimary ? current.attributes.native_left_to_save : current.attributes.left_to_save, left_to_save: this.convertToPrimary ? current.attributes.pc_left_to_save : current.attributes.left_to_save,
// target amount // target amount
target_amount: this.convertToPrimary ? current.attributes.native_target_amount : current.attributes.target_amount, target_amount: this.convertToPrimary ? current.attributes.pc_target_amount : current.attributes.target_amount,
// save per month // save per month
save_per_month: this.convertToPrimary ? current.attributes.native_save_per_month : current.attributes.save_per_month, save_per_month: this.convertToPrimary ? current.attributes.pc_save_per_month : current.attributes.save_per_month,
currency_code: this.convertToPrimary ? current.attributes.native_currency_code : current.attributes.currency_code, currency_code: this.convertToPrimary ? current.attributes.pc_currency_code : current.attributes.currency_code,
}; };
dataSet[groupName].piggies.push(piggy); dataSet[groupName].piggies.push(piggy);
@@ -129,7 +129,7 @@ export default () => ({
init() { init() {
// console.log('piggies init'); // console.log('piggies init');
apiData = []; apiData = [];
Promise.all([getVariable('convert_to_native', false)]).then((values) => { Promise.all([getVariable('convert_to_primary', false)]).then((values) => {
afterPromises = true; afterPromises = true;
this.convertToPrimary = values[0]; this.convertToPrimary = values[0];
@@ -144,7 +144,7 @@ export default () => ({
apiData = []; apiData = [];
this.loadPiggyBanks(); this.loadPiggyBanks();
}); });
window.store.observe('convert_to_native', (newValue) => { window.store.observe('convert_to_primary', (newValue) => {
if (!afterPromises) { if (!afterPromises) {
return; return;
} }

View File

@@ -160,7 +160,7 @@ export default () => ({
convertToPrimary: false, convertToPrimary: false,
processedData: null, processedData: null,
eventListeners: { eventListeners: {
['@convert-to-native.window'](event){ ['@convert-to-primary.window'](event){
console.log('I heard that! (dashboard/sankey)'); console.log('I heard that! (dashboard/sankey)');
this.convertToPrimary = event.detail; this.convertToPrimary = event.detail;
convertToPrimary = event.detail; convertToPrimary = event.detail;
@@ -227,8 +227,8 @@ export default () => ({
let amount = parseFloat(transaction.amount); let amount = parseFloat(transaction.amount);
let flowKey; let flowKey;
if (this.convertToPrimary) { if (this.convertToPrimary) {
currencyCode = transaction.native_currency_code; currencyCode = transaction.primary_currency_code;
amount = parseFloat(transaction.native_amount); amount = parseFloat(transaction.pc_amount);
} }
if ('deposit' === transaction.type) { if ('deposit' === transaction.type) {
this.parseDeposit(transaction, currencyCode, amount); this.parseDeposit(transaction, currencyCode, amount);
@@ -399,7 +399,7 @@ export default () => ({
init() { init() {
// console.log('sankey init'); // console.log('sankey init');
transactions = []; transactions = [];
Promise.all([getVariable('convert_to_native', false)]).then((values) => { Promise.all([getVariable('convert_to_primary', false)]).then((values) => {
this.convertToPrimary = values[0]; this.convertToPrimary = values[0];
convertToPrimary = values[0]; convertToPrimary = values[0];
@@ -430,7 +430,7 @@ export default () => ({
this.transactions = []; this.transactions = [];
this.loadChart(); this.loadChart();
}); });
window.store.observe('convert_to_native', (newValue) => { window.store.observe('convert_to_primary', (newValue) => {
if (!afterPromises) { if (!afterPromises) {
return; return;
} }

View File

@@ -72,7 +72,7 @@ function parseBillInfo(data) {
paid: data.attributes.paid_dates.length > 0, paid: data.attributes.paid_dates.length > 0,
}; };
if(convertToPrimary) { if(convertToPrimary) {
result.currency_code = data.attributes.native_currency_code; result.currency_code = data.attributes.primary_currency_code;
} }
@@ -160,9 +160,8 @@ function downloadSubscriptions(params) {
subscriptionData[objectGroupId].bills.push(bill); subscriptionData[objectGroupId].bills.push(bill);
if (false === bill.paid) { if (false === bill.paid) {
// bill is unpaid, count the "pay_dates" and multiply with the "amount". // bill is unpaid, count the "pay_dates" and multiply with the "amount".
// since bill is unpaid, this can only be in currency amount and native currency amount. // since bill is unpaid, this can only be in currency amount and primary currency amount.
const totalAmount = current.attributes.pay_dates.length * bill.amount; const totalAmount = current.attributes.pay_dates.length * bill.amount;
// const totalNativeAmount = current.attributes.pay_dates.length * bill.native_amount;
// for bill's currency // for bill's currency
if (!subscriptionData[objectGroupId].payment_info.hasOwnProperty(bill.currency_code)) { if (!subscriptionData[objectGroupId].payment_info.hasOwnProperty(bill.currency_code)) {
subscriptionData[objectGroupId].payment_info[bill.currency_code] = { subscriptionData[objectGroupId].payment_info[bill.currency_code] = {
@@ -217,7 +216,7 @@ export default () => ({
return formatMoney(amount, currencyCode); return formatMoney(amount, currencyCode);
}, },
eventListeners: { eventListeners: {
['@convert-to-native.window'](event){ ['@convert-to-primary.window'](event){
console.log('I heard that! (dashboard/subscriptions)'); console.log('I heard that! (dashboard/subscriptions)');
this.convertToPrimary = event.detail; this.convertToPrimary = event.detail;
convertToPrimary = event.detail; convertToPrimary = event.detail;
@@ -313,7 +312,7 @@ export default () => ({
}, },
init() { init() {
Promise.all([getVariable('convert_to_native', false)]).then((values) => { Promise.all([getVariable('convert_to_primary', false)]).then((values) => {
this.convertToPrimary = values[0]; this.convertToPrimary = values[0];
convertToPrimary = values[0]; convertToPrimary = values[0];
afterPromises = true; afterPromises = true;
@@ -332,7 +331,7 @@ export default () => ({
this.startSubscriptions(); this.startSubscriptions();
} }
}); });
window.store.observe('convert_to_native', (newValue) => { window.store.observe('convert_to_primary', (newValue) => {
if (!afterPromises) { if (!afterPromises) {
return; return;
} }

View File

@@ -82,7 +82,7 @@ let transactions = function () {
formData: { formData: {
defaultCurrency: null, defaultCurrency: null,
enabledCurrencies: [], enabledCurrencies: [],
nativeCurrencies: [], primaryCurrencies: [],
foreignCurrencies: [], foreignCurrencies: [],
budgets: [], budgets: [],
piggyBanks: [], piggyBanks: [],
@@ -149,7 +149,7 @@ let transactions = function () {
// this also locks the amount into the amount of the source account // this also locks the amount into the amount of the source account
// and the foreign amount (if different) in that of the destination account. // and the foreign amount (if different) in that of the destination account.
console.log('filter down currencies for transfer.'); console.log('filter down currencies for transfer.');
this.filterNativeCurrencies(this.entries[0].source_account.currency_code); this.filterPrimaryCurrencies(this.entries[0].source_account.currency_code);
this.filterForeignCurrencies(this.entries[0].destination_account.currency_code); this.filterForeignCurrencies(this.entries[0].destination_account.currency_code);
return; return;
} }
@@ -157,20 +157,20 @@ let transactions = function () {
if ('Asset account' === sourceType && ['Expense account', 'Debt', 'Loan', 'Mortgage'].includes(destType)) { if ('Asset account' === sourceType && ['Expense account', 'Debt', 'Loan', 'Mortgage'].includes(destType)) {
this.groupProperties.transactionType = 'withdrawal'; this.groupProperties.transactionType = 'withdrawal';
console.log('[a] Transaction type is detected to be "' + this.groupProperties.transactionType + '".'); console.log('[a] Transaction type is detected to be "' + this.groupProperties.transactionType + '".');
this.filterNativeCurrencies(this.entries[0].source_account.currency_code); this.filterPrimaryCurrencies(this.entries[0].source_account.currency_code);
return; return;
} }
if ('Asset account' === sourceType && 'unknown' === destType) { if ('Asset account' === sourceType && 'unknown' === destType) {
this.groupProperties.transactionType = 'withdrawal'; this.groupProperties.transactionType = 'withdrawal';
console.log('[b] Transaction type is detected to be "' + this.groupProperties.transactionType + '".'); console.log('[b] Transaction type is detected to be "' + this.groupProperties.transactionType + '".');
console.log(this.entries[0].source_account); console.log(this.entries[0].source_account);
this.filterNativeCurrencies(this.entries[0].source_account.currency_code); this.filterPrimaryCurrencies(this.entries[0].source_account.currency_code);
return; return;
} }
if (['Debt', 'Loan', 'Mortgage'].includes(sourceType) && 'Expense account' === destType) { if (['Debt', 'Loan', 'Mortgage'].includes(sourceType) && 'Expense account' === destType) {
this.groupProperties.transactionType = 'withdrawal'; this.groupProperties.transactionType = 'withdrawal';
console.log('[c] Transaction type is detected to be "' + this.groupProperties.transactionType + '".'); console.log('[c] Transaction type is detected to be "' + this.groupProperties.transactionType + '".');
this.filterNativeCurrencies(this.entries[0].source_account.currency_code); this.filterPrimaryCurrencies(this.entries[0].source_account.currency_code);
return; return;
} }
@@ -237,7 +237,7 @@ let transactions = function () {
} }
}, },
filterNativeCurrencies(code) { filterPrimaryCurrencies(code) {
let list = []; let list = [];
let currency; let currency;
for (let i in this.formData.enabledCurrencies) { for (let i in this.formData.enabledCurrencies) {
@@ -249,7 +249,7 @@ let transactions = function () {
} }
} }
list.push(currency); list.push(currency);
this.formData.nativeCurrencies = list; this.formData.primaryCurrencies = list;
// this also forces the currency_code on ALL entries. // this also forces the currency_code on ALL entries.
for (let i in this.entries) { for (let i in this.entries) {
@@ -296,7 +296,7 @@ let transactions = function () {
this.formStates.loadingCurrencies = false; this.formStates.loadingCurrencies = false;
this.formData.defaultCurrency = data.defaultCurrency; this.formData.defaultCurrency = data.defaultCurrency;
this.formData.enabledCurrencies = data.enabledCurrencies; this.formData.enabledCurrencies = data.enabledCurrencies;
this.formData.nativeCurrencies = data.nativeCurrencies; this.formData.primaryCurrencies = data.primaryCurrencies;
this.formData.foreignCurrencies = data.foreignCurrencies; this.formData.foreignCurrencies = data.foreignCurrencies;
}); });

View File

@@ -87,7 +87,7 @@ let transactions = function () {
formData: { formData: {
defaultCurrency: null, defaultCurrency: null,
enabledCurrencies: [], enabledCurrencies: [],
nativeCurrencies: [], primaryCurrencies: [],
foreignCurrencies: [], foreignCurrencies: [],
budgets: [], budgets: [],
piggyBanks: [], piggyBanks: [],
@@ -332,7 +332,7 @@ let transactions = function () {
this.formStates.loadingCurrencies = false; this.formStates.loadingCurrencies = false;
this.formData.defaultCurrency = data.defaultCurrency; this.formData.defaultCurrency = data.defaultCurrency;
this.formData.enabledCurrencies = data.enabledCurrencies; this.formData.enabledCurrencies = data.enabledCurrencies;
this.formData.nativeCurrencies = data.nativeCurrencies; this.formData.primaryCurrencies = data.primaryCurrencies;
this.formData.foreignCurrencies = data.foreignCurrencies; this.formData.foreignCurrencies = data.foreignCurrencies;
}); });

View File

@@ -29,7 +29,7 @@ export function loadCurrencies() {
return getter.list(params).then((response) => { return getter.list(params).then((response) => {
let returnData = { let returnData = {
defaultCurrency: {}, defaultCurrency: {},
nativeCurrencies: [], primaryCurrencies: [],
foreignCurrencies: [], foreignCurrencies: [],
enabledCurrencies: [], enabledCurrencies: [],
}; };
@@ -55,7 +55,7 @@ export function loadCurrencies() {
returnData.defaultCurrency = obj; returnData.defaultCurrency = obj;
} }
returnData.enabledCurrencies.push(obj); returnData.enabledCurrencies.push(obj);
returnData.nativeCurrencies.push(obj); returnData.primaryCurrencies.push(obj);
returnData.foreignCurrencies.push(obj); returnData.foreignCurrencies.push(obj);
} }
} }