@fuzzle/opencode-accountant 0.10.2 → 0.10.4-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +22 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23078,19 +23078,12 @@ function findRulesForCsv(csvPath, mapping) {
|
|
|
23078
23078
|
|
|
23079
23079
|
// src/utils/hledgerExecutor.ts
|
|
23080
23080
|
var {$: $2 } = globalThis.Bun;
|
|
23081
|
-
var STDERR_TRUNCATE_LENGTH = 500;
|
|
23082
23081
|
var TX_HEADER_PATTERN = /^(\d{4})-(\d{2}-\d{2})(\s+(.+))?$/;
|
|
23083
23082
|
async function defaultHledgerExecutor(cmdArgs) {
|
|
23084
23083
|
try {
|
|
23085
23084
|
const result = await $2`hledger ${cmdArgs}`.quiet().nothrow();
|
|
23086
23085
|
const stdout = result.stdout.toString();
|
|
23087
23086
|
const stderr = result.stderr.toString();
|
|
23088
|
-
if (result.exitCode !== 0 && stderr) {
|
|
23089
|
-
process.stderr.write(`[hledger] command failed (exit ${result.exitCode}): hledger ${cmdArgs.join(" ")}
|
|
23090
|
-
`);
|
|
23091
|
-
process.stderr.write(`[hledger] stderr: ${stderr.slice(0, STDERR_TRUNCATE_LENGTH)}
|
|
23092
|
-
`);
|
|
23093
|
-
}
|
|
23094
23087
|
return {
|
|
23095
23088
|
stdout,
|
|
23096
23089
|
stderr,
|
|
@@ -23098,8 +23091,6 @@ async function defaultHledgerExecutor(cmdArgs) {
|
|
|
23098
23091
|
};
|
|
23099
23092
|
} catch (error45) {
|
|
23100
23093
|
const errorMessage = error45 instanceof Error ? error45.message : String(error45);
|
|
23101
|
-
process.stderr.write(`[hledger] exception: ${errorMessage}
|
|
23102
|
-
`);
|
|
23103
23094
|
return {
|
|
23104
23095
|
stdout: "",
|
|
23105
23096
|
stderr: errorMessage,
|
|
@@ -24814,6 +24805,11 @@ Got:
|
|
|
24814
24805
|
import * as fs18 from "fs";
|
|
24815
24806
|
import * as path13 from "path";
|
|
24816
24807
|
|
|
24808
|
+
// src/utils/symbolNormalizer.ts
|
|
24809
|
+
function normalizeSymbol(symbol2) {
|
|
24810
|
+
return symbol2.toLowerCase();
|
|
24811
|
+
}
|
|
24812
|
+
|
|
24817
24813
|
// src/utils/swissquoteLotTracker.ts
|
|
24818
24814
|
import * as fs17 from "fs";
|
|
24819
24815
|
import * as path12 from "path";
|
|
@@ -25023,7 +25019,7 @@ function generateBuyEntry(trade, logger) {
|
|
|
25023
25019
|
`;
|
|
25024
25020
|
entry += ` ; swissquote:order:${trade.orderNum} isin:${trade.isin}
|
|
25025
25021
|
`;
|
|
25026
|
-
entry += ` assets:investments:stocks:${trade.symbol} ${qty}
|
|
25022
|
+
entry += ` assets:investments:stocks:${trade.symbol} ${qty} @ ${price} ${trade.currency}
|
|
25027
25023
|
`;
|
|
25028
25024
|
if (fees > 0) {
|
|
25029
25025
|
entry += ` expenses:fees:trading:swissquote ${formatAmount2(fees, trade.currency)}
|
|
@@ -25053,7 +25049,7 @@ function generateSellEntry(trade, consumed, logger) {
|
|
|
25053
25049
|
for (const c of consumed) {
|
|
25054
25050
|
const lotQty = formatQuantity(c.quantity);
|
|
25055
25051
|
const lotPrice = c.lot.costBasis.toFixed(2);
|
|
25056
|
-
entry += ` assets:investments:stocks:${trade.symbol} -${lotQty}
|
|
25052
|
+
entry += ` assets:investments:stocks:${trade.symbol} -${lotQty} @ ${lotPrice} ${trade.currency}
|
|
25057
25053
|
`;
|
|
25058
25054
|
}
|
|
25059
25055
|
entry += ` assets:broker:swissquote:${trade.currency.toLowerCase()} ${formatAmount2(cashIn, trade.currency)}
|
|
@@ -25101,13 +25097,13 @@ function generateSplitEntry(action, oldQuantity, newQuantity, logger) {
|
|
|
25101
25097
|
`;
|
|
25102
25098
|
entry += ` ; Ratio: ${ratio.toFixed(4)} (${oldQuantity} -> ${newQuantity})
|
|
25103
25099
|
`;
|
|
25104
|
-
entry += ` assets:investments:stocks:${action.symbol} -${formatQuantity(oldQuantity)}
|
|
25100
|
+
entry += ` assets:investments:stocks:${action.symbol} -${formatQuantity(oldQuantity)}
|
|
25105
25101
|
`;
|
|
25106
|
-
entry += ` equity:conversion ${formatQuantity(oldQuantity)}
|
|
25102
|
+
entry += ` equity:conversion ${formatQuantity(oldQuantity)}
|
|
25107
25103
|
`;
|
|
25108
|
-
entry += ` equity:conversion -${formatQuantity(newQuantity)}
|
|
25104
|
+
entry += ` equity:conversion -${formatQuantity(newQuantity)}
|
|
25109
25105
|
`;
|
|
25110
|
-
entry += ` assets:investments:stocks:${action.symbol} ${formatQuantity(newQuantity)}
|
|
25106
|
+
entry += ` assets:investments:stocks:${action.symbol} ${formatQuantity(newQuantity)}
|
|
25111
25107
|
`;
|
|
25112
25108
|
return entry;
|
|
25113
25109
|
}
|
|
@@ -25127,7 +25123,7 @@ function generateWorthlessEntry(action, removedLots, logger) {
|
|
|
25127
25123
|
for (const lot of removedLots) {
|
|
25128
25124
|
const qty = formatQuantity(lot.quantity);
|
|
25129
25125
|
const price = lot.costBasis.toFixed(2);
|
|
25130
|
-
entry += ` assets:investments:stocks:${action.symbol} -${qty}
|
|
25126
|
+
entry += ` assets:investments:stocks:${action.symbol} -${qty} @ ${price} ${currency}
|
|
25131
25127
|
`;
|
|
25132
25128
|
}
|
|
25133
25129
|
entry += ` expenses:losses:capital ${formatAmount2(totalCost, currency)}
|
|
@@ -25152,16 +25148,16 @@ function generateMultiWayMergerEntry(group, crossCurrencyOutgoingSymbols, logger
|
|
|
25152
25148
|
}
|
|
25153
25149
|
for (const out of group.outgoing) {
|
|
25154
25150
|
const qty = formatQuantity(Math.abs(out.quantity));
|
|
25155
|
-
entry += ` assets:investments:stocks:${out.symbol} -${qty}
|
|
25151
|
+
entry += ` assets:investments:stocks:${out.symbol} -${qty}
|
|
25156
25152
|
`;
|
|
25157
|
-
entry += ` equity:conversion ${qty}
|
|
25153
|
+
entry += ` equity:conversion ${qty}
|
|
25158
25154
|
`;
|
|
25159
25155
|
}
|
|
25160
25156
|
for (const inc of group.incoming) {
|
|
25161
25157
|
const qty = formatQuantity(Math.abs(inc.quantity));
|
|
25162
|
-
entry += ` equity:conversion -${qty}
|
|
25158
|
+
entry += ` equity:conversion -${qty}
|
|
25163
25159
|
`;
|
|
25164
|
-
entry += ` assets:investments:stocks:${inc.symbol} ${qty}
|
|
25160
|
+
entry += ` assets:investments:stocks:${inc.symbol} ${qty}
|
|
25165
25161
|
`;
|
|
25166
25162
|
}
|
|
25167
25163
|
return entry;
|
|
@@ -25175,7 +25171,7 @@ function generateRightsDistributionEntry(action, logger) {
|
|
|
25175
25171
|
`;
|
|
25176
25172
|
entry += ` ; swissquote:order:${action.orderNum} isin:${action.isin}
|
|
25177
25173
|
`;
|
|
25178
|
-
entry += ` assets:investments:stocks:${action.symbol} ${qty}
|
|
25174
|
+
entry += ` assets:investments:stocks:${action.symbol} ${qty} @ 0.00 CAD
|
|
25179
25175
|
`;
|
|
25180
25176
|
entry += ` income:capital-gains:rights-distribution 0.00 CAD
|
|
25181
25177
|
`;
|
|
@@ -25338,7 +25334,7 @@ var MERGER_LIKE_TYPES = new Set([
|
|
|
25338
25334
|
]);
|
|
25339
25335
|
function processCorporateActions(actions, inventory, lotInventoryPath, projectDir, logger) {
|
|
25340
25336
|
const entries = [];
|
|
25341
|
-
actions.sort((a, b) => a.date.localeCompare(b.date));
|
|
25337
|
+
actions.sort((a, b) => formatDate(a.date).localeCompare(formatDate(b.date)));
|
|
25342
25338
|
const mergerActions = [];
|
|
25343
25339
|
const otherActions = [];
|
|
25344
25340
|
for (const action of actions) {
|
|
@@ -25588,6 +25584,9 @@ async function preprocessSwissquote(csvPath, projectDir, currency, year, lotInve
|
|
|
25588
25584
|
if (hasSymbolMap && txn.symbol) {
|
|
25589
25585
|
txn.symbol = symbolMap[txn.symbol] ?? txn.symbol;
|
|
25590
25586
|
}
|
|
25587
|
+
if (txn.symbol) {
|
|
25588
|
+
txn.symbol = normalizeSymbol(txn.symbol);
|
|
25589
|
+
}
|
|
25591
25590
|
transactions.push(txn);
|
|
25592
25591
|
}
|
|
25593
25592
|
}
|
|
@@ -25643,7 +25642,7 @@ async function preprocessSwissquote(csvPath, projectDir, currency, year, lotInve
|
|
|
25643
25642
|
const journalEntries = [];
|
|
25644
25643
|
if (trades.length > 0) {
|
|
25645
25644
|
logger?.startSection("Trade Processing", 2);
|
|
25646
|
-
trades.sort((a, b) => a.date.localeCompare(b.date));
|
|
25645
|
+
trades.sort((a, b) => formatDate(a.date).localeCompare(formatDate(b.date)));
|
|
25647
25646
|
for (const trade of trades) {
|
|
25648
25647
|
try {
|
|
25649
25648
|
if (trade.type === "Buy") {
|