Skip to content

Commit

Permalink
Fix checking for tx fee record for buy/sell and dividend records
Browse files Browse the repository at this point in the history
  • Loading branch information
dickwolff committed Apr 3, 2024
1 parent 5c8b768 commit 83ee96e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Config } from '@jest/types';
// Sync object
const config: Config.InitialOptions = {
verbose: true,
testTimeout: 30000,
testTimeout: 15000,
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
Expand Down
4 changes: 2 additions & 2 deletions src/converters/degiroConverterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GhostfolioExport } from "../models/ghostfolioExport";
describe("degiroConverterV2", () => {

beforeEach(() => {
jest.spyOn(console, "log").mockImplementation(jest.fn());
// jest.spyOn(console, "log").mockImplementation(jest.fn());
});

afterEach(() => {
Expand Down Expand Up @@ -33,7 +33,7 @@ describe("degiroConverterV2", () => {
// Assert
expect(actualExport).toBeTruthy();
expect(actualExport.activities.length).toBeGreaterThan(0);
expect(actualExport.activities.length).toBe(16);
expect(actualExport.activities.length).toBe(15);

done();
}, () => { done.fail("Should not have an error!"); });
Expand Down
29 changes: 17 additions & 12 deletions src/converters/degiroConverterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class DeGiroConverterV2 extends AbstractConverter {
continue;
}
}
else if (this.isTransactionFeeRecord(record)) {
else if (this.isTransactionFeeRecord(record, false)) {

// If it was a transaction record without any other transaction connected, skip it.
bar1.increment();
Expand Down Expand Up @@ -236,12 +236,12 @@ export class DeGiroConverterV2 extends AbstractConverter {

// Determine which of the two records is the action record (e.g. buy/sell) and which contains the transaction fees.
// Firstly, check if the current record is the TxFee record.
if (this.isTransactionFeeRecord(currentRecord)) {
if (this.isTransactionFeeRecord(currentRecord, true)) {
actionRecord = nextRecord;
txFeeRecord = currentRecord;
}
// Next, check wether the next record is NOT a TxFee record. In this case, the transaction has no fees.
else if (!this.isTransactionFeeRecord(nextRecord)) {
else if (!this.isTransactionFeeRecord(nextRecord, true)) {
txFeeRecord = null;
}

Expand Down Expand Up @@ -295,12 +295,12 @@ export class DeGiroConverterV2 extends AbstractConverter {

// Determine which of the two records is the dividend record and which contains the transaction fees.
// Firstly, check if the current record is the TxFee record.
if (this.isTransactionFeeRecord(currentRecord)) {
if (this.isTransactionFeeRecord(currentRecord, false)) {
dividendRecord = nextRecord;
txFeeRecord = currentRecord;
}
// Next, check wether the next record is NOT a TxFee record. In this case, the dividend has no fees.
else if (!this.isTransactionFeeRecord(nextRecord)) {
else if (!this.isTransactionFeeRecord(nextRecord, false)) {
txFeeRecord = null;
}

Expand Down Expand Up @@ -338,9 +338,9 @@ export class DeGiroConverterV2 extends AbstractConverter {
// - TxFee + Buy/Sell records, or
// - Buy/Sell record without TxFee.
return (
(this.isBuyOrSellRecord(currentRecord) && this.isTransactionFeeRecord(nextRecord)) ||
(this.isTransactionFeeRecord(currentRecord) && this.isBuyOrSellRecord(nextRecord) ||
(this.isBuyOrSellRecord(currentRecord) && !this.isTransactionFeeRecord(nextRecord))));
(this.isBuyOrSellRecord(currentRecord) && this.isTransactionFeeRecord(nextRecord, true)) ||
(this.isTransactionFeeRecord(currentRecord, true) && this.isBuyOrSellRecord(nextRecord) ||
(this.isBuyOrSellRecord(currentRecord) && !this.isTransactionFeeRecord(nextRecord, true))));
}

private isDividendRecordSet(currentRecord: DeGiroRecord, nextRecord: DeGiroRecord): boolean {
Expand All @@ -350,9 +350,9 @@ export class DeGiroConverterV2 extends AbstractConverter {
// - TxFee + Dividend record, or
// - Dividend record without TxFee.
return (
(this.isDividendRecord(currentRecord) && this.isTransactionFeeRecord(nextRecord)) ||
(this.isTransactionFeeRecord(currentRecord) && this.isDividendRecord(nextRecord)) ||
(this.isDividendRecord(currentRecord) && !this.isTransactionFeeRecord(nextRecord)));
(this.isDividendRecord(currentRecord) && this.isTransactionFeeRecord(nextRecord, false)) ||
(this.isTransactionFeeRecord(currentRecord, false) && this.isDividendRecord(nextRecord)) ||
(this.isDividendRecord(currentRecord) && !this.isTransactionFeeRecord(nextRecord, false)));
}

private isBuyOrSellRecord(record: DeGiroRecord): boolean {
Expand All @@ -375,12 +375,17 @@ export class DeGiroConverterV2 extends AbstractConverter {
return record.description.toLocaleLowerCase().indexOf("dividend") > -1 || record.description.toLocaleLowerCase().indexOf("capital return") > -1;
}

private isTransactionFeeRecord(record: DeGiroRecord): boolean {
private isTransactionFeeRecord(record: DeGiroRecord, isBuyOrSellTransactionFeeRecord: boolean): boolean {

if (!record) {
return false;
}

// When a dividend transaction must be found, there should not be an orderid.
if (!isBuyOrSellTransactionFeeRecord && record.orderId) {
return false;
}

const transactionFeeRecordType = ["en\/of", "and\/or", "und\/oder", "e\/o", "adr\/gdr", "ritenuta", "belasting", "daň z dividendy", "taxe sur les", "comissões de transação", "courtage et/ou"];

return transactionFeeRecordType.some((t) => record.description.toLocaleLowerCase().indexOf(t) > -1);
Expand Down

0 comments on commit 83ee96e

Please sign in to comment.