@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.
- package/dist/modules/sales/api/order-adjustments/route.js +5 -2
- package/dist/modules/sales/api/order-adjustments/route.js.map +2 -2
- package/dist/modules/sales/api/quote-adjustments/route.js +5 -2
- package/dist/modules/sales/api/quote-adjustments/route.js.map +2 -2
- package/dist/modules/sales/commands/documents.js +3 -2
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/sales/data/validators.js +22 -0
- package/dist/modules/sales/data/validators.js.map +2 -2
- package/dist/modules/sales/lib/calculations.js +4 -2
- package/dist/modules/sales/lib/calculations.js.map +2 -2
- package/package.json +5 -5
- package/src/modules/sales/api/order-adjustments/route.ts +7 -2
- package/src/modules/sales/api/quote-adjustments/route.ts +7 -2
- package/src/modules/sales/commands/documents.ts +11 -6
- package/src/modules/sales/data/validators.ts +35 -0
- package/src/modules/sales/lib/calculations.ts +7 -3
|
@@ -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
|
-
|
|
199
|
-
|
|
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)
|