@open-mercato/core 0.6.1-develop.3179.1.9ee0441adc → 0.6.1-develop.3187.1.4c96d17341

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.
@@ -190,13 +190,17 @@ function buildBaseDocumentResult(params: {
190
190
  }
191
191
  }
192
192
 
193
- // Line-scoped and any other return (credit) adjustments reduce grand total
193
+ // Line-scoped and any other return (credit) adjustments reduce grand total.
194
+ // Sign is normalized to negative regardless of the stored sign so a positive
195
+ // amountNet / amountGross can never inflate totals (issue #1705).
194
196
  for (const adj of resolvedAdjustments) {
195
197
  if (adj.kind !== 'return') continue
196
198
  const net = toNumber(adj.amountNet, toNumber(adj.amountGross))
197
199
  const gross = toNumber(adj.amountGross, net)
198
- subtotalNet = Math.max(subtotalNet + net, 0)
199
- subtotalGross = Math.max(subtotalGross + gross, 0)
200
+ const netDelta = -Math.abs(net)
201
+ const grossDelta = -Math.abs(gross)
202
+ subtotalNet = Math.max(subtotalNet + netDelta, 0)
203
+ subtotalGross = Math.max(subtotalGross + grossDelta, 0)
200
204
  }
201
205
 
202
206
  const grandTotalNet = round(subtotalNet)