@fuzzle/opencode-accountant 0.10.4-next.1 → 0.10.5-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.
Files changed (2) hide show
  1. package/dist/index.js +9 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -25006,11 +25006,16 @@ function escapeDescription(desc) {
25006
25006
  function formatQuantity(qty) {
25007
25007
  return qty.toFixed(6).replace(/\.?0+$/, "");
25008
25008
  }
25009
+ function formatPrice(price) {
25010
+ const full = price.toFixed(6).replace(/0+$/, "");
25011
+ const [integer2, decimal = ""] = full.split(".");
25012
+ return `${integer2}.${decimal.padEnd(2, "0")}`;
25013
+ }
25009
25014
  function generateBuyEntry(trade, logger) {
25010
25015
  const date5 = formatDate(trade.date);
25011
25016
  const description = escapeDescription(`Buy ${trade.symbol} - ${trade.name}`);
25012
25017
  const qty = formatQuantity(trade.quantity);
25013
- const price = trade.unitPrice.toFixed(2);
25018
+ const price = formatPrice(trade.unitPrice);
25014
25019
  const totalCost = trade.quantity * trade.unitPrice;
25015
25020
  const fees = trade.costs;
25016
25021
  const cashOut = totalCost + fees;
@@ -25043,12 +25048,12 @@ function generateSellEntry(trade, consumed, logger) {
25043
25048
  `;
25044
25049
  entry += ` ; swissquote:order:${trade.orderNum} isin:${trade.isin}
25045
25050
  `;
25046
- const lotDetails = consumed.map((c) => `${c.lot.date}: ${formatQuantity(c.quantity)}@${c.lot.costBasis.toFixed(2)}`).join(", ");
25051
+ const lotDetails = consumed.map((c) => `${c.lot.date}: ${formatQuantity(c.quantity)}@${formatPrice(c.lot.costBasis)}`).join(", ");
25047
25052
  entry += ` ; FIFO lots: ${lotDetails}
25048
25053
  `;
25049
25054
  for (const c of consumed) {
25050
25055
  const lotQty = formatQuantity(c.quantity);
25051
- const lotPrice = c.lot.costBasis.toFixed(2);
25056
+ const lotPrice = formatPrice(c.lot.costBasis);
25052
25057
  entry += ` assets:investments:stocks:${trade.symbol} -${lotQty} @ ${lotPrice} ${trade.currency}
25053
25058
  `;
25054
25059
  }
@@ -25122,7 +25127,7 @@ function generateWorthlessEntry(action, removedLots, logger) {
25122
25127
  `;
25123
25128
  for (const lot of removedLots) {
25124
25129
  const qty = formatQuantity(lot.quantity);
25125
- const price = lot.costBasis.toFixed(2);
25130
+ const price = formatPrice(lot.costBasis);
25126
25131
  entry += ` assets:investments:stocks:${action.symbol} -${qty} @ ${price} ${currency}
25127
25132
  `;
25128
25133
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fuzzle/opencode-accountant",
3
- "version": "0.10.4-next.1",
3
+ "version": "0.10.5-next.1",
4
4
  "description": "An OpenCode accounting agent, specialized in double-entry-bookkepping with hledger",
5
5
  "author": {
6
6
  "name": "ali bengali",