@open-mercato/core 0.7.1-develop.7113.1.9d83dca10c → 0.7.1-develop.7121.1.734c263bda
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/.turbo/turbo-build.log +1 -1
- package/dist/helpers/integration/crmFixtures.js.map +1 -1
- package/dist/modules/communication_channels/api/post/channels/[id]/test-send/route.js +9 -2
- package/dist/modules/communication_channels/api/post/channels/[id]/test-send/route.js.map +2 -2
- package/dist/modules/communication_channels/lib/outbound-recipient.js +5 -1
- package/dist/modules/communication_channels/lib/outbound-recipient.js.map +2 -2
- package/dist/modules/communication_channels/lib/test-seed.js +5 -0
- package/dist/modules/communication_channels/lib/test-seed.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/[id]/hooks/useDealClosure.js +1 -1
- package/dist/modules/customers/backend/customers/deals/[id]/hooks/useDealClosure.js.map +1 -1
- package/dist/modules/customers/backend/customers/deals/page.js +4 -3
- package/dist/modules/customers/backend/customers/deals/page.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/pipeline/components/QuickDealDialog.js +2 -2
- package/dist/modules/customers/backend/customers/deals/pipeline/components/QuickDealDialog.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/pipeline/components/StatusFilterPopover.js +1 -1
- package/dist/modules/customers/backend/customers/deals/pipeline/components/StatusFilterPopover.js.map +1 -1
- package/dist/modules/customers/backend/customers/deals/pipeline/page.js +1 -1
- package/dist/modules/customers/backend/customers/deals/pipeline/page.js.map +2 -2
- package/dist/modules/customers/cli.js +5 -5
- package/dist/modules/customers/cli.js.map +2 -2
- package/dist/modules/customers/commands/deals.js.map +2 -2
- package/dist/modules/customers/components/detail/pipelineStageUtils.js +1 -0
- package/dist/modules/customers/components/detail/pipelineStageUtils.js.map +2 -2
- package/dist/modules/customers/components/linking/adapters/dealAdapter.js +2 -2
- package/dist/modules/customers/components/linking/adapters/dealAdapter.js.map +2 -2
- package/dist/modules/customers/lib/closureStage.js.map +2 -2
- package/dist/modules/customers/lib/dealStatus.js +6 -4
- package/dist/modules/customers/lib/dealStatus.js.map +2 -2
- package/dist/modules/customers/lib/dealsSummaryQueries.js +3 -3
- package/dist/modules/customers/lib/dealsSummaryQueries.js.map +1 -1
- package/dist/modules/customers/migrations/Migration20260824180000_deal_status_lost.js +30 -0
- package/dist/modules/customers/migrations/Migration20260824180000_deal_status_lost.js.map +7 -0
- package/dist/modules/dashboards/widgets/dashboard/pipeline-summary/config.js.map +1 -1
- package/dist/modules/eudr/notifications.js +5 -0
- package/dist/modules/eudr/notifications.js.map +2 -2
- package/dist/modules/query_index/lib/search-tokens.js +59 -28
- package/dist/modules/query_index/lib/search-tokens.js.map +2 -2
- package/dist/modules/sales/commands/documents.js +146 -99
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/sales/commands/returns.js +1 -30
- package/dist/modules/sales/commands/returns.js.map +2 -2
- package/dist/modules/sales/commands/shared.js +1 -4
- package/dist/modules/sales/commands/shared.js.map +2 -2
- package/dist/modules/sales/components/documents/SalesOrderDraftLines.js +2 -1
- package/dist/modules/sales/components/documents/SalesOrderDraftLines.js.map +2 -2
- package/dist/modules/sales/data/validators.js +3 -0
- package/dist/modules/sales/data/validators.js.map +2 -2
- package/dist/modules/sales/lib/calculations.js +14 -2
- package/dist/modules/sales/lib/calculations.js.map +2 -2
- package/dist/modules/sales/lib/json.js +8 -0
- package/dist/modules/sales/lib/json.js.map +7 -0
- package/dist/modules/sales/lib/lineSnapshots.js +66 -0
- package/dist/modules/sales/lib/lineSnapshots.js.map +7 -0
- package/dist/modules/warranty_claims/notifications.js +5 -0
- package/dist/modules/warranty_claims/notifications.js.map +2 -2
- package/dist/modules/wms/notifications.js +2 -0
- package/dist/modules/wms/notifications.js.map +2 -2
- package/package.json +7 -7
- package/src/helpers/integration/crmFixtures.ts +1 -1
- package/src/modules/communication_channels/api/post/channels/[id]/test-send/route.ts +21 -9
- package/src/modules/communication_channels/lib/adapter.ts +11 -0
- package/src/modules/communication_channels/lib/outbound-recipient.ts +14 -1
- package/src/modules/communication_channels/lib/test-seed.ts +19 -0
- package/src/modules/customers/backend/customers/deals/[id]/hooks/useDealClosure.ts +1 -1
- package/src/modules/customers/backend/customers/deals/page.tsx +4 -3
- package/src/modules/customers/backend/customers/deals/pipeline/components/QuickDealDialog.tsx +5 -5
- package/src/modules/customers/backend/customers/deals/pipeline/components/StatusFilterPopover.tsx +3 -3
- package/src/modules/customers/backend/customers/deals/pipeline/page.tsx +2 -2
- package/src/modules/customers/cli.ts +5 -5
- package/src/modules/customers/commands/deals.ts +4 -3
- package/src/modules/customers/components/detail/pipelineStageUtils.ts +1 -0
- package/src/modules/customers/components/linking/adapters/dealAdapter.tsx +2 -2
- package/src/modules/customers/i18n/de.json +1 -1
- package/src/modules/customers/i18n/en.json +1 -1
- package/src/modules/customers/i18n/es.json +1 -1
- package/src/modules/customers/i18n/ko.json +1 -1
- package/src/modules/customers/i18n/pl.json +1 -1
- package/src/modules/customers/lib/closureStage.ts +2 -1
- package/src/modules/customers/lib/dealStatus.ts +23 -12
- package/src/modules/customers/lib/dealsSummaryQueries.ts +3 -3
- package/src/modules/customers/migrations/Migration20260824180000_deal_status_lost.ts +55 -0
- package/src/modules/dashboards/widgets/dashboard/pipeline-summary/config.ts +1 -1
- package/src/modules/eudr/notifications.ts +5 -0
- package/src/modules/query_index/lib/search-tokens.ts +100 -43
- package/src/modules/sales/commands/documents.ts +185 -105
- package/src/modules/sales/commands/returns.ts +1 -31
- package/src/modules/sales/commands/shared.ts +1 -4
- package/src/modules/sales/components/documents/SalesOrderDraftLines.tsx +12 -1
- package/src/modules/sales/data/validators.ts +3 -0
- package/src/modules/sales/lib/calculations.ts +33 -7
- package/src/modules/sales/lib/json.ts +4 -0
- package/src/modules/sales/lib/lineSnapshots.ts +98 -0
- package/src/modules/sales/lib/types.ts +20 -0
- package/src/modules/warranty_claims/notifications.ts +5 -0
- package/src/modules/wms/notifications.ts +2 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { registerCommand } from "@open-mercato/shared/lib/commands";
|
|
4
5
|
import { withAtomicFlush } from "@open-mercato/shared/lib/commands/flush";
|
|
@@ -95,6 +96,11 @@ import {
|
|
|
95
96
|
loadPaymentSnapshot,
|
|
96
97
|
restorePaymentSnapshot
|
|
97
98
|
} from "./payments.js";
|
|
99
|
+
import {
|
|
100
|
+
mapOrderLineEntityToSnapshot,
|
|
101
|
+
mapQuoteLineEntityToSnapshot,
|
|
102
|
+
resolveUpsertDiscountFields
|
|
103
|
+
} from "../lib/lineSnapshots.js";
|
|
98
104
|
import { loadShippedQuantityByLine } from "../lib/shipments/snapshots.js";
|
|
99
105
|
import { resolveDictionaryEntryValue, resolveCachedDictionaryEntryValue } from "../lib/dictionaries.js";
|
|
100
106
|
import { resolveStatusEntryIdByValue } from "../lib/statusHelpers.js";
|
|
@@ -1889,66 +1895,6 @@ function buildCalculationContext(params) {
|
|
|
1889
1895
|
})
|
|
1890
1896
|
};
|
|
1891
1897
|
}
|
|
1892
|
-
function mapOrderLineEntityToSnapshot(line) {
|
|
1893
|
-
return {
|
|
1894
|
-
id: line.id,
|
|
1895
|
-
lineNumber: line.lineNumber,
|
|
1896
|
-
kind: line.kind,
|
|
1897
|
-
productId: line.productId ?? null,
|
|
1898
|
-
productVariantId: line.productVariantId ?? null,
|
|
1899
|
-
name: line.name ?? null,
|
|
1900
|
-
description: line.description ?? null,
|
|
1901
|
-
comment: line.comment ?? null,
|
|
1902
|
-
quantity: toNumeric(line.quantity),
|
|
1903
|
-
quantityUnit: line.quantityUnit ?? null,
|
|
1904
|
-
normalizedQuantity: toNumeric(line.normalizedQuantity ?? line.quantity),
|
|
1905
|
-
normalizedUnit: line.normalizedUnit ?? line.quantityUnit ?? null,
|
|
1906
|
-
uomSnapshot: line.uomSnapshot ? cloneJson(line.uomSnapshot) : null,
|
|
1907
|
-
currencyCode: line.currencyCode,
|
|
1908
|
-
unitPriceNet: toNumeric(line.unitPriceNet),
|
|
1909
|
-
unitPriceGross: toNumeric(line.unitPriceGross),
|
|
1910
|
-
discountAmount: toNumeric(line.discountAmount),
|
|
1911
|
-
discountPercent: toNumeric(line.discountPercent),
|
|
1912
|
-
taxRate: toNumeric(line.taxRate),
|
|
1913
|
-
taxAmount: toNumeric(line.taxAmount),
|
|
1914
|
-
totalNetAmount: toNumeric(line.totalNetAmount),
|
|
1915
|
-
totalGrossAmount: toNumeric(line.totalGrossAmount),
|
|
1916
|
-
configuration: line.configuration ? cloneJson(line.configuration) : null,
|
|
1917
|
-
promotionCode: line.promotionCode ?? null,
|
|
1918
|
-
metadata: line.metadata ? cloneJson(line.metadata) : null,
|
|
1919
|
-
customFieldSetId: line.customFieldSetId ?? null
|
|
1920
|
-
};
|
|
1921
|
-
}
|
|
1922
|
-
function mapQuoteLineEntityToSnapshot(line) {
|
|
1923
|
-
return {
|
|
1924
|
-
id: line.id,
|
|
1925
|
-
lineNumber: line.lineNumber,
|
|
1926
|
-
kind: line.kind,
|
|
1927
|
-
productId: line.productId ?? null,
|
|
1928
|
-
productVariantId: line.productVariantId ?? null,
|
|
1929
|
-
name: line.name ?? null,
|
|
1930
|
-
description: line.description ?? null,
|
|
1931
|
-
comment: line.comment ?? null,
|
|
1932
|
-
quantity: toNumeric(line.quantity),
|
|
1933
|
-
quantityUnit: line.quantityUnit ?? null,
|
|
1934
|
-
normalizedQuantity: toNumeric(line.normalizedQuantity ?? line.quantity),
|
|
1935
|
-
normalizedUnit: line.normalizedUnit ?? line.quantityUnit ?? null,
|
|
1936
|
-
uomSnapshot: line.uomSnapshot ? cloneJson(line.uomSnapshot) : null,
|
|
1937
|
-
currencyCode: line.currencyCode,
|
|
1938
|
-
unitPriceNet: toNumeric(line.unitPriceNet),
|
|
1939
|
-
unitPriceGross: toNumeric(line.unitPriceGross),
|
|
1940
|
-
discountAmount: toNumeric(line.discountAmount),
|
|
1941
|
-
discountPercent: toNumeric(line.discountPercent),
|
|
1942
|
-
taxRate: toNumeric(line.taxRate),
|
|
1943
|
-
taxAmount: toNumeric(line.taxAmount),
|
|
1944
|
-
totalNetAmount: toNumeric(line.totalNetAmount),
|
|
1945
|
-
totalGrossAmount: toNumeric(line.totalGrossAmount),
|
|
1946
|
-
configuration: line.configuration ? cloneJson(line.configuration) : null,
|
|
1947
|
-
promotionCode: line.promotionCode ?? null,
|
|
1948
|
-
metadata: line.metadata ? cloneJson(line.metadata) : null,
|
|
1949
|
-
customFieldSetId: line.customFieldSetId ?? null
|
|
1950
|
-
};
|
|
1951
|
-
}
|
|
1952
1898
|
function mapOrderAdjustmentToDraft(adjustment) {
|
|
1953
1899
|
return {
|
|
1954
1900
|
id: adjustment.id,
|
|
@@ -1987,6 +1933,9 @@ async function emitTotalsCalculated(eventBus, payload) {
|
|
|
1987
1933
|
if (!eventBus) return;
|
|
1988
1934
|
await eventBus.emitEvent("sales.document.totals.calculated", payload);
|
|
1989
1935
|
}
|
|
1936
|
+
function isStoredRowSourcedLine(line) {
|
|
1937
|
+
return line.discountAmountFromStoredRow === true;
|
|
1938
|
+
}
|
|
1990
1939
|
function createLineSnapshotFromInput(line, lineNumber) {
|
|
1991
1940
|
const quantity = Number(line.quantity ?? 0);
|
|
1992
1941
|
const normalizedQuantity = toNumeric(
|
|
@@ -2009,6 +1958,14 @@ function createLineSnapshotFromInput(line, lineNumber) {
|
|
|
2009
1958
|
unitPriceNet: line.unitPriceNet ?? null,
|
|
2010
1959
|
unitPriceGross: line.unitPriceGross ?? null,
|
|
2011
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" },
|
|
2012
1969
|
discountPercent: line.discountPercent ?? null,
|
|
2013
1970
|
taxRate: line.taxRate ?? null,
|
|
2014
1971
|
taxAmount: line.taxAmount ?? null,
|
|
@@ -5368,7 +5325,11 @@ const orderLineUpsertCommand = {
|
|
|
5368
5325
|
currencyCode: parsed.currencyCode ?? existingSnapshot?.currencyCode ?? order.currencyCode,
|
|
5369
5326
|
unitPriceNet: unitPriceNet ?? 0,
|
|
5370
5327
|
unitPriceGross: unitPriceGross ?? unitPriceNet ?? 0,
|
|
5371
|
-
|
|
5328
|
+
...resolveUpsertDiscountFields(
|
|
5329
|
+
parsed.discountAmount,
|
|
5330
|
+
parsed.discountAmountBasis,
|
|
5331
|
+
existingSnapshot
|
|
5332
|
+
),
|
|
5372
5333
|
discountPercent: parsed.discountPercent ?? existingSnapshot?.discountPercent ?? 0,
|
|
5373
5334
|
taxRate: taxRate ?? 0,
|
|
5374
5335
|
taxAmount: parsed.taxAmount ?? existingSnapshot?.taxAmount ?? null,
|
|
@@ -5789,7 +5750,11 @@ const quoteLineUpsertCommand = {
|
|
|
5789
5750
|
currencyCode: parsed.currencyCode ?? existingSnapshot?.currencyCode ?? quote.currencyCode,
|
|
5790
5751
|
unitPriceNet: unitPriceNet ?? 0,
|
|
5791
5752
|
unitPriceGross: unitPriceGross ?? unitPriceNet ?? 0,
|
|
5792
|
-
|
|
5753
|
+
...resolveUpsertDiscountFields(
|
|
5754
|
+
parsed.discountAmount,
|
|
5755
|
+
parsed.discountAmountBasis,
|
|
5756
|
+
existingSnapshot
|
|
5757
|
+
),
|
|
5793
5758
|
discountPercent: parsed.discountPercent ?? existingSnapshot?.discountPercent ?? 0,
|
|
5794
5759
|
taxRate: taxRate ?? 0,
|
|
5795
5760
|
taxAmount: parsed.taxAmount ?? existingSnapshot?.taxAmount ?? null,
|
|
@@ -7064,6 +7029,70 @@ const createInvoiceCommand = {
|
|
|
7064
7029
|
await em.flush();
|
|
7065
7030
|
}
|
|
7066
7031
|
};
|
|
7032
|
+
const invoiceUpdateChangeKeys = [
|
|
7033
|
+
"invoiceNumber",
|
|
7034
|
+
"statusEntryId",
|
|
7035
|
+
"status",
|
|
7036
|
+
"issueDate",
|
|
7037
|
+
"dueDate",
|
|
7038
|
+
"currencyCode",
|
|
7039
|
+
"subtotalNetAmount",
|
|
7040
|
+
"subtotalGrossAmount",
|
|
7041
|
+
"discountTotalAmount",
|
|
7042
|
+
"taxTotalAmount",
|
|
7043
|
+
"grandTotalNetAmount",
|
|
7044
|
+
"grandTotalGrossAmount",
|
|
7045
|
+
"paidTotalAmount",
|
|
7046
|
+
"outstandingAmount",
|
|
7047
|
+
"metadata"
|
|
7048
|
+
];
|
|
7049
|
+
function toAuditISOString(value) {
|
|
7050
|
+
if (value instanceof Date) {
|
|
7051
|
+
return Number.isNaN(value.getTime()) ? null : value.toISOString();
|
|
7052
|
+
}
|
|
7053
|
+
if (typeof value === "string") {
|
|
7054
|
+
const parsed = new Date(value);
|
|
7055
|
+
return Number.isNaN(parsed.getTime()) ? null : parsed.toISOString();
|
|
7056
|
+
}
|
|
7057
|
+
return null;
|
|
7058
|
+
}
|
|
7059
|
+
function auditValuesEqual(left, right) {
|
|
7060
|
+
if (Object.is(left, right)) return true;
|
|
7061
|
+
if (left instanceof Date || right instanceof Date) {
|
|
7062
|
+
const leftIso = toAuditISOString(left);
|
|
7063
|
+
const rightIso = toAuditISOString(right);
|
|
7064
|
+
return leftIso !== null && rightIso !== null && leftIso === rightIso;
|
|
7065
|
+
}
|
|
7066
|
+
return isDeepStrictEqual(left, right);
|
|
7067
|
+
}
|
|
7068
|
+
function buildAuditChanges(before, after, keys) {
|
|
7069
|
+
const changedKeys = keys.filter((key) => !auditValuesEqual(before[key], after[key]));
|
|
7070
|
+
return buildChanges(before, after, changedKeys);
|
|
7071
|
+
}
|
|
7072
|
+
function selectInvoiceUpdateChangeKeys(input) {
|
|
7073
|
+
return invoiceUpdateChangeKeys.filter(
|
|
7074
|
+
(key) => key === "status" ? input.statusEntryId !== void 0 : input[key] !== void 0
|
|
7075
|
+
);
|
|
7076
|
+
}
|
|
7077
|
+
function applyInvoiceHeaderUpdate(invoice, input, resolvedStatus) {
|
|
7078
|
+
if (input.invoiceNumber !== void 0) invoice.invoiceNumber = input.invoiceNumber;
|
|
7079
|
+
if (input.statusEntryId !== void 0) {
|
|
7080
|
+
invoice.statusEntryId = input.statusEntryId;
|
|
7081
|
+
invoice.status = resolvedStatus ?? null;
|
|
7082
|
+
}
|
|
7083
|
+
if (input.issueDate !== void 0) invoice.issueDate = input.issueDate;
|
|
7084
|
+
if (input.dueDate !== void 0) invoice.dueDate = input.dueDate;
|
|
7085
|
+
if (input.currencyCode !== void 0) invoice.currencyCode = input.currencyCode;
|
|
7086
|
+
if (input.subtotalNetAmount !== void 0) invoice.subtotalNetAmount = toNumericString(input.subtotalNetAmount);
|
|
7087
|
+
if (input.subtotalGrossAmount !== void 0) invoice.subtotalGrossAmount = toNumericString(input.subtotalGrossAmount);
|
|
7088
|
+
if (input.discountTotalAmount !== void 0) invoice.discountTotalAmount = toNumericString(input.discountTotalAmount);
|
|
7089
|
+
if (input.taxTotalAmount !== void 0) invoice.taxTotalAmount = toNumericString(input.taxTotalAmount);
|
|
7090
|
+
if (input.grandTotalNetAmount !== void 0) invoice.grandTotalNetAmount = toNumericString(input.grandTotalNetAmount);
|
|
7091
|
+
if (input.grandTotalGrossAmount !== void 0) invoice.grandTotalGrossAmount = toNumericString(input.grandTotalGrossAmount);
|
|
7092
|
+
if (input.paidTotalAmount !== void 0) invoice.paidTotalAmount = toNumericString(input.paidTotalAmount);
|
|
7093
|
+
if (input.outstandingAmount !== void 0) invoice.outstandingAmount = toNumericString(input.outstandingAmount);
|
|
7094
|
+
if (input.metadata !== void 0) invoice.metadata = input.metadata;
|
|
7095
|
+
}
|
|
7067
7096
|
const updateInvoiceCommand = {
|
|
7068
7097
|
id: "sales.invoices.update",
|
|
7069
7098
|
async prepare(input, ctx) {
|
|
@@ -7088,27 +7117,11 @@ const updateInvoiceCommand = {
|
|
|
7088
7117
|
tenantId: parsed.tenantId,
|
|
7089
7118
|
deletedAt: null
|
|
7090
7119
|
});
|
|
7091
|
-
|
|
7092
|
-
"invoiceNumber",
|
|
7093
|
-
"statusEntryId",
|
|
7094
|
-
"status",
|
|
7095
|
-
"issueDate",
|
|
7096
|
-
"dueDate",
|
|
7097
|
-
"currencyCode",
|
|
7098
|
-
"subtotalNetAmount",
|
|
7099
|
-
"subtotalGrossAmount",
|
|
7100
|
-
"discountTotalAmount",
|
|
7101
|
-
"taxTotalAmount",
|
|
7102
|
-
"grandTotalNetAmount",
|
|
7103
|
-
"grandTotalGrossAmount",
|
|
7104
|
-
"paidTotalAmount",
|
|
7105
|
-
"outstandingAmount",
|
|
7106
|
-
"metadata"
|
|
7107
|
-
]);
|
|
7120
|
+
let resolvedStatus;
|
|
7108
7121
|
if (parsed.statusEntryId !== void 0) {
|
|
7109
|
-
|
|
7122
|
+
resolvedStatus = await resolveDictionaryEntryValue(em, parsed.statusEntryId ?? null, { tenantId: invoice.tenantId });
|
|
7110
7123
|
}
|
|
7111
|
-
|
|
7124
|
+
applyInvoiceHeaderUpdate(invoice, parsed, resolvedStatus);
|
|
7112
7125
|
invoice.updatedAt = /* @__PURE__ */ new Date();
|
|
7113
7126
|
await em.flush();
|
|
7114
7127
|
const dataEngine = ctx.container.resolve("dataEngine");
|
|
@@ -7141,11 +7154,16 @@ const updateInvoiceCommand = {
|
|
|
7141
7154
|
const em = ctx.container.resolve("em").fork();
|
|
7142
7155
|
return loadInvoiceSnapshot(em, result.invoiceId);
|
|
7143
7156
|
},
|
|
7144
|
-
buildLog: async ({ result, snapshots }) => {
|
|
7157
|
+
buildLog: async ({ input, result, snapshots }) => {
|
|
7145
7158
|
const before = snapshots.before;
|
|
7146
7159
|
const after = snapshots.after;
|
|
7147
7160
|
if (!after) return null;
|
|
7148
7161
|
const { translate } = await resolveTranslations();
|
|
7162
|
+
const changes = before ? buildAuditChanges(
|
|
7163
|
+
before.invoice,
|
|
7164
|
+
after.invoice,
|
|
7165
|
+
selectInvoiceUpdateChangeKeys(input)
|
|
7166
|
+
) : {};
|
|
7149
7167
|
return {
|
|
7150
7168
|
actionLabel: translate("sales.audit.invoices.update", "Update invoice"),
|
|
7151
7169
|
resourceKind: "sales.invoice",
|
|
@@ -7154,6 +7172,7 @@ const updateInvoiceCommand = {
|
|
|
7154
7172
|
organizationId: after.invoice.organizationId,
|
|
7155
7173
|
snapshotBefore: before,
|
|
7156
7174
|
snapshotAfter: after,
|
|
7175
|
+
changes: Object.keys(changes).length ? changes : null,
|
|
7157
7176
|
payload: {
|
|
7158
7177
|
undo: { before, after }
|
|
7159
7178
|
}
|
|
@@ -7525,6 +7544,41 @@ const createCreditMemoCommand = {
|
|
|
7525
7544
|
await em.flush();
|
|
7526
7545
|
}
|
|
7527
7546
|
};
|
|
7547
|
+
const creditMemoUpdateChangeKeys = [
|
|
7548
|
+
"creditMemoNumber",
|
|
7549
|
+
"statusEntryId",
|
|
7550
|
+
"status",
|
|
7551
|
+
"reason",
|
|
7552
|
+
"issueDate",
|
|
7553
|
+
"currencyCode",
|
|
7554
|
+
"subtotalNetAmount",
|
|
7555
|
+
"subtotalGrossAmount",
|
|
7556
|
+
"taxTotalAmount",
|
|
7557
|
+
"grandTotalNetAmount",
|
|
7558
|
+
"grandTotalGrossAmount",
|
|
7559
|
+
"metadata"
|
|
7560
|
+
];
|
|
7561
|
+
function selectCreditMemoUpdateChangeKeys(input) {
|
|
7562
|
+
return creditMemoUpdateChangeKeys.filter(
|
|
7563
|
+
(key) => key === "status" ? input.statusEntryId !== void 0 : input[key] !== void 0
|
|
7564
|
+
);
|
|
7565
|
+
}
|
|
7566
|
+
function applyCreditMemoHeaderUpdate(creditMemo, input, resolvedStatus) {
|
|
7567
|
+
if (input.creditMemoNumber !== void 0) creditMemo.creditMemoNumber = input.creditMemoNumber;
|
|
7568
|
+
if (input.statusEntryId !== void 0) {
|
|
7569
|
+
creditMemo.statusEntryId = input.statusEntryId;
|
|
7570
|
+
creditMemo.status = resolvedStatus ?? null;
|
|
7571
|
+
}
|
|
7572
|
+
if (input.reason !== void 0) creditMemo.reason = input.reason;
|
|
7573
|
+
if (input.issueDate !== void 0) creditMemo.issueDate = input.issueDate;
|
|
7574
|
+
if (input.currencyCode !== void 0) creditMemo.currencyCode = input.currencyCode;
|
|
7575
|
+
if (input.subtotalNetAmount !== void 0) creditMemo.subtotalNetAmount = toNumericString(input.subtotalNetAmount);
|
|
7576
|
+
if (input.subtotalGrossAmount !== void 0) creditMemo.subtotalGrossAmount = toNumericString(input.subtotalGrossAmount);
|
|
7577
|
+
if (input.taxTotalAmount !== void 0) creditMemo.taxTotalAmount = toNumericString(input.taxTotalAmount);
|
|
7578
|
+
if (input.grandTotalNetAmount !== void 0) creditMemo.grandTotalNetAmount = toNumericString(input.grandTotalNetAmount);
|
|
7579
|
+
if (input.grandTotalGrossAmount !== void 0) creditMemo.grandTotalGrossAmount = toNumericString(input.grandTotalGrossAmount);
|
|
7580
|
+
if (input.metadata !== void 0) creditMemo.metadata = input.metadata;
|
|
7581
|
+
}
|
|
7528
7582
|
const updateCreditMemoCommand = {
|
|
7529
7583
|
id: "sales.credit_memos.update",
|
|
7530
7584
|
async prepare(input, ctx) {
|
|
@@ -7549,24 +7603,11 @@ const updateCreditMemoCommand = {
|
|
|
7549
7603
|
tenantId: parsed.tenantId,
|
|
7550
7604
|
deletedAt: null
|
|
7551
7605
|
});
|
|
7552
|
-
|
|
7553
|
-
"creditMemoNumber",
|
|
7554
|
-
"statusEntryId",
|
|
7555
|
-
"status",
|
|
7556
|
-
"reason",
|
|
7557
|
-
"issueDate",
|
|
7558
|
-
"currencyCode",
|
|
7559
|
-
"subtotalNetAmount",
|
|
7560
|
-
"subtotalGrossAmount",
|
|
7561
|
-
"taxTotalAmount",
|
|
7562
|
-
"grandTotalNetAmount",
|
|
7563
|
-
"grandTotalGrossAmount",
|
|
7564
|
-
"metadata"
|
|
7565
|
-
]);
|
|
7606
|
+
let resolvedStatus;
|
|
7566
7607
|
if (parsed.statusEntryId !== void 0) {
|
|
7567
|
-
|
|
7608
|
+
resolvedStatus = await resolveDictionaryEntryValue(em, parsed.statusEntryId ?? null, { tenantId: creditMemo.tenantId });
|
|
7568
7609
|
}
|
|
7569
|
-
|
|
7610
|
+
applyCreditMemoHeaderUpdate(creditMemo, parsed, resolvedStatus);
|
|
7570
7611
|
creditMemo.updatedAt = /* @__PURE__ */ new Date();
|
|
7571
7612
|
await em.flush();
|
|
7572
7613
|
const dataEngine = ctx.container.resolve("dataEngine");
|
|
@@ -7599,11 +7640,16 @@ const updateCreditMemoCommand = {
|
|
|
7599
7640
|
const em = ctx.container.resolve("em").fork();
|
|
7600
7641
|
return loadCreditMemoSnapshot(em, result.creditMemoId);
|
|
7601
7642
|
},
|
|
7602
|
-
buildLog: async ({ result, snapshots }) => {
|
|
7643
|
+
buildLog: async ({ input, result, snapshots }) => {
|
|
7603
7644
|
const before = snapshots.before;
|
|
7604
7645
|
const after = snapshots.after;
|
|
7605
7646
|
if (!after) return null;
|
|
7606
7647
|
const { translate } = await resolveTranslations();
|
|
7648
|
+
const changes = before ? buildAuditChanges(
|
|
7649
|
+
before.creditMemo,
|
|
7650
|
+
after.creditMemo,
|
|
7651
|
+
selectCreditMemoUpdateChangeKeys(input)
|
|
7652
|
+
) : {};
|
|
7607
7653
|
return {
|
|
7608
7654
|
actionLabel: translate("sales.audit.credit_memos.update", "Update credit memo"),
|
|
7609
7655
|
resourceKind: "sales.credit_memo",
|
|
@@ -7612,6 +7658,7 @@ const updateCreditMemoCommand = {
|
|
|
7612
7658
|
organizationId: after.creditMemo.organizationId,
|
|
7613
7659
|
snapshotBefore: before,
|
|
7614
7660
|
snapshotAfter: after,
|
|
7661
|
+
changes: Object.keys(changes).length ? changes : null,
|
|
7615
7662
|
payload: {
|
|
7616
7663
|
undo: { before, after }
|
|
7617
7664
|
}
|