jamsix / ib-edavki

Skripta, ki prevede XML poročilo trgovalnih poslov v platformi InteractiveBrokers v XML format primeren za uvoz v obrazce Doh-KDVP, D-IFI, Doh-Div in Doh-Obr v eDavkih Finančne uprave.
MIT License
173 stars 57 forks source link

Fixed a bug with comparison of transactionIDs #101

Closed ZigaSajovic closed 11 months ago

ZigaSajovic commented 11 months ago

This merge should fix https://github.com/jamsix/ib-edavki/issues/100. It also adds a few missing companies and conids.

Bug

transactionIDs were compared lexicographically, as strings, instead of by their numerical value.

Explanation:

The usual case is that the transactionIDs of the witholding tax and the dividend are close - meaning that they have the same number of digits. For example the symbol MSF:

dividend["transactionID"] == 412270322
ibCashTransaction["transactionID"] == 412270323

Hence the original code worked most of the time, because lexicograpical comparison is the same as numerical when the numbers have the same number of digits.

But this is not an invariant. Some transactions may be far away (measured in how many transactions transpired between them). For example the symbol APC:

dividend["transactionID"] == 9750589
ibCashTransaction["transactionID"] == 13534671

Where the lexicographic comparison

"9750589" < "13534671"

returns False.

This merge fixes this by casting the strings to integers before the comparison.

jamsix commented 11 months ago

Brilliant, thank you @ZigaSajovic !