@open-mercato/core 0.7.1-develop.7120.1.a0154ac412 → 0.7.1-develop.7122.1.421cefe668

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 (27) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/modules/sales/commands/documents.js +26 -62
  3. package/dist/modules/sales/commands/documents.js.map +2 -2
  4. package/dist/modules/sales/commands/returns.js +1 -30
  5. package/dist/modules/sales/commands/returns.js.map +2 -2
  6. package/dist/modules/sales/commands/shared.js +1 -4
  7. package/dist/modules/sales/commands/shared.js.map +2 -2
  8. package/dist/modules/sales/components/documents/SalesOrderDraftLines.js +2 -1
  9. package/dist/modules/sales/components/documents/SalesOrderDraftLines.js.map +2 -2
  10. package/dist/modules/sales/data/validators.js +3 -0
  11. package/dist/modules/sales/data/validators.js.map +2 -2
  12. package/dist/modules/sales/lib/calculations.js +14 -2
  13. package/dist/modules/sales/lib/calculations.js.map +2 -2
  14. package/dist/modules/sales/lib/json.js +8 -0
  15. package/dist/modules/sales/lib/json.js.map +7 -0
  16. package/dist/modules/sales/lib/lineSnapshots.js +66 -0
  17. package/dist/modules/sales/lib/lineSnapshots.js.map +7 -0
  18. package/package.json +7 -7
  19. package/src/modules/sales/commands/documents.ts +32 -66
  20. package/src/modules/sales/commands/returns.ts +1 -31
  21. package/src/modules/sales/commands/shared.ts +1 -4
  22. package/src/modules/sales/components/documents/SalesOrderDraftLines.tsx +12 -1
  23. package/src/modules/sales/data/validators.ts +3 -0
  24. package/src/modules/sales/lib/calculations.ts +33 -7
  25. package/src/modules/sales/lib/json.ts +4 -0
  26. package/src/modules/sales/lib/lineSnapshots.ts +98 -0
  27. package/src/modules/sales/lib/types.ts +20 -0
@@ -1,4 +1,4 @@
1
- [build:core] found 4366 entry points
1
+ [build:core] found 4369 entry points
2
2
  [build:core] built successfully
3
3
  [build:core:generated] found 218 entry points
4
4
  [build:core:generated] built successfully
@@ -96,6 +96,11 @@ import {
96
96
  loadPaymentSnapshot,
97
97
  restorePaymentSnapshot
98
98
  } from "./payments.js";
99
+ import {
100
+ mapOrderLineEntityToSnapshot,
101
+ mapQuoteLineEntityToSnapshot,
102
+ resolveUpsertDiscountFields
103
+ } from "../lib/lineSnapshots.js";
99
104
  import { loadShippedQuantityByLine } from "../lib/shipments/snapshots.js";
100
105
  import { resolveDictionaryEntryValue, resolveCachedDictionaryEntryValue } from "../lib/dictionaries.js";
101
106
  import { resolveStatusEntryIdByValue } from "../lib/statusHelpers.js";
@@ -1890,66 +1895,6 @@ function buildCalculationContext(params) {
1890
1895
  })
1891
1896
  };
1892
1897
  }
1893
- function mapOrderLineEntityToSnapshot(line) {
1894
- return {
1895
- id: line.id,
1896
- lineNumber: line.lineNumber,
1897
- kind: line.kind,
1898
- productId: line.productId ?? null,
1899
- productVariantId: line.productVariantId ?? null,
1900
- name: line.name ?? null,
1901
- description: line.description ?? null,
1902
- comment: line.comment ?? null,
1903
- quantity: toNumeric(line.quantity),
1904
- quantityUnit: line.quantityUnit ?? null,
1905
- normalizedQuantity: toNumeric(line.normalizedQuantity ?? line.quantity),
1906
- normalizedUnit: line.normalizedUnit ?? line.quantityUnit ?? null,
1907
- uomSnapshot: line.uomSnapshot ? cloneJson(line.uomSnapshot) : null,
1908
- currencyCode: line.currencyCode,
1909
- unitPriceNet: toNumeric(line.unitPriceNet),
1910
- unitPriceGross: toNumeric(line.unitPriceGross),
1911
- discountAmount: toNumeric(line.discountAmount),
1912
- discountPercent: toNumeric(line.discountPercent),
1913
- taxRate: toNumeric(line.taxRate),
1914
- taxAmount: toNumeric(line.taxAmount),
1915
- totalNetAmount: toNumeric(line.totalNetAmount),
1916
- totalGrossAmount: toNumeric(line.totalGrossAmount),
1917
- configuration: line.configuration ? cloneJson(line.configuration) : null,
1918
- promotionCode: line.promotionCode ?? null,
1919
- metadata: line.metadata ? cloneJson(line.metadata) : null,
1920
- customFieldSetId: line.customFieldSetId ?? null
1921
- };
1922
- }
1923
- function mapQuoteLineEntityToSnapshot(line) {
1924
- return {
1925
- id: line.id,
1926
- lineNumber: line.lineNumber,
1927
- kind: line.kind,
1928
- productId: line.productId ?? null,
1929
- productVariantId: line.productVariantId ?? null,
1930
- name: line.name ?? null,
1931
- description: line.description ?? null,
1932
- comment: line.comment ?? null,
1933
- quantity: toNumeric(line.quantity),
1934
- quantityUnit: line.quantityUnit ?? null,
1935
- normalizedQuantity: toNumeric(line.normalizedQuantity ?? line.quantity),
1936
- normalizedUnit: line.normalizedUnit ?? line.quantityUnit ?? null,
1937
- uomSnapshot: line.uomSnapshot ? cloneJson(line.uomSnapshot) : null,
1938
- currencyCode: line.currencyCode,
1939
- unitPriceNet: toNumeric(line.unitPriceNet),
1940
- unitPriceGross: toNumeric(line.unitPriceGross),
1941
- discountAmount: toNumeric(line.discountAmount),
1942
- discountPercent: toNumeric(line.discountPercent),
1943
- taxRate: toNumeric(line.taxRate),
1944
- taxAmount: toNumeric(line.taxAmount),
1945
- totalNetAmount: toNumeric(line.totalNetAmount),
1946
- totalGrossAmount: toNumeric(line.totalGrossAmount),
1947
- configuration: line.configuration ? cloneJson(line.configuration) : null,
1948
- promotionCode: line.promotionCode ?? null,
1949
- metadata: line.metadata ? cloneJson(line.metadata) : null,
1950
- customFieldSetId: line.customFieldSetId ?? null
1951
- };
1952
- }
1953
1898
  function mapOrderAdjustmentToDraft(adjustment) {
1954
1899
  return {
1955
1900
  id: adjustment.id,
@@ -1988,6 +1933,9 @@ async function emitTotalsCalculated(eventBus, payload) {
1988
1933
  if (!eventBus) return;
1989
1934
  await eventBus.emitEvent("sales.document.totals.calculated", payload);
1990
1935
  }
1936
+ function isStoredRowSourcedLine(line) {
1937
+ return line.discountAmountFromStoredRow === true;
1938
+ }
1991
1939
  function createLineSnapshotFromInput(line, lineNumber) {
1992
1940
  const quantity = Number(line.quantity ?? 0);
1993
1941
  const normalizedQuantity = toNumeric(
@@ -2010,6 +1958,14 @@ function createLineSnapshotFromInput(line, lineNumber) {
2010
1958
  unitPriceNet: line.unitPriceNet ?? null,
2011
1959
  unitPriceGross: line.unitPriceGross ?? null,
2012
1960
  discountAmount: line.discountAmount ?? null,
1961
+ // Several callers re-run an already-mapped snapshot through here — the line
1962
+ // upsert and delete paths rebuild every line of the document, not just the
1963
+ // one being edited. Those inputs already carry a line total from a stored
1964
+ // row, so their origin must survive rather than be overwritten with the
1965
+ // caller default, or the untouched lines get re-inflated by quantity on
1966
+ // every write. Exactly one of the two origin fields is ever set, which is
1967
+ // the invariant the calculation engine relies on.
1968
+ ...isStoredRowSourcedLine(line) ? { discountAmountFromStoredRow: true } : { discountAmountBasis: line.discountAmountBasis ?? "unit" },
2013
1969
  discountPercent: line.discountPercent ?? null,
2014
1970
  taxRate: line.taxRate ?? null,
2015
1971
  taxAmount: line.taxAmount ?? null,
@@ -5369,7 +5325,11 @@ const orderLineUpsertCommand = {
5369
5325
  currencyCode: parsed.currencyCode ?? existingSnapshot?.currencyCode ?? order.currencyCode,
5370
5326
  unitPriceNet: unitPriceNet ?? 0,
5371
5327
  unitPriceGross: unitPriceGross ?? unitPriceNet ?? 0,
5372
- discountAmount: parsed.discountAmount ?? existingSnapshot?.discountAmount ?? 0,
5328
+ ...resolveUpsertDiscountFields(
5329
+ parsed.discountAmount,
5330
+ parsed.discountAmountBasis,
5331
+ existingSnapshot
5332
+ ),
5373
5333
  discountPercent: parsed.discountPercent ?? existingSnapshot?.discountPercent ?? 0,
5374
5334
  taxRate: taxRate ?? 0,
5375
5335
  taxAmount: parsed.taxAmount ?? existingSnapshot?.taxAmount ?? null,
@@ -5790,7 +5750,11 @@ const quoteLineUpsertCommand = {
5790
5750
  currencyCode: parsed.currencyCode ?? existingSnapshot?.currencyCode ?? quote.currencyCode,
5791
5751
  unitPriceNet: unitPriceNet ?? 0,
5792
5752
  unitPriceGross: unitPriceGross ?? unitPriceNet ?? 0,
5793
- discountAmount: parsed.discountAmount ?? existingSnapshot?.discountAmount ?? 0,
5753
+ ...resolveUpsertDiscountFields(
5754
+ parsed.discountAmount,
5755
+ parsed.discountAmountBasis,
5756
+ existingSnapshot
5757
+ ),
5794
5758
  discountPercent: parsed.discountPercent ?? existingSnapshot?.discountPercent ?? 0,
5795
5759
  taxRate: taxRate ?? 0,
5796
5760
  taxAmount: parsed.taxAmount ?? existingSnapshot?.taxAmount ?? null,