Keep Revit and manual row quantities consistent
Editing "Anzahl" on a row with linked Revit objects set manualQuantity to the new total, so the row no longer matched its objects and detaching them failed with "row.manualQuantity must not exceed row.quantity". Such rows now lock "Anzahl" in the editor. The new optional columns "Anz. manuell" (editable) and "Anz. Revit" (read-only) show both shares; stored column layouts get them hidden next to "Anzahl". The device-row update derives the total from a manual-only edit and rejects any change that breaks quantity = manual + Revit, for every source. Two history fixtures inserted rows with quantity 1 and the column default manualQuantity 0, a state no runtime path creates; they now insert 1/1. Undoing "Revit-Objekte lösen" re-validated planning-value conflicts that the user had confirmed on the original assignment and was rejected. Undo/redo of row assignments now restores the accepted state without a new confirmation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
01312b89fe
commit
898be43ebc
12 changed files with 272 additions and 21 deletions
|
|
@ -1,4 +1,8 @@
|
|||
import { and, eq } from "drizzle-orm";
|
||||
import {
|
||||
assertCircuitDeviceRowQuantity,
|
||||
calculateCircuitDeviceRowQuantity,
|
||||
} from "../../domain/calculations/circuit-device-row-quantity.js";
|
||||
import {
|
||||
assertCircuitDeviceRowUpdateProjectCommand,
|
||||
createCircuitDeviceRowUpdateProjectCommand,
|
||||
|
|
@ -20,6 +24,7 @@ import type { AppDatabase } from "../database-context.js";
|
|||
import { circuitDeviceRows } from "../schema/circuit-device-rows.js";
|
||||
import { circuitLists } from "../schema/circuit-lists.js";
|
||||
import { circuits } from "../schema/circuits.js";
|
||||
import { externalModelObjects } from "../schema/external-model-objects.js";
|
||||
import { projectDevices } from "../schema/project-devices.js";
|
||||
import { rooms } from "../schema/rooms.js";
|
||||
import {
|
||||
|
|
@ -90,13 +95,8 @@ export class CircuitDeviceRowProjectCommandRepository
|
|||
change.value,
|
||||
])
|
||||
) as CircuitDeviceRowPatchInput;
|
||||
const targetQuantity = patch.quantity ?? current.quantity;
|
||||
const targetManualQuantity =
|
||||
patch.manualQuantity ?? current.manualQuantity;
|
||||
if (targetManualQuantity > targetQuantity) {
|
||||
throw new Error(
|
||||
"Device-row manual quantity must not exceed total quantity."
|
||||
);
|
||||
if (patch.quantity !== undefined || patch.manualQuantity !== undefined) {
|
||||
this.applyQuantityPatch(tx, current, patch);
|
||||
}
|
||||
if (
|
||||
input.source === "user" &&
|
||||
|
|
@ -166,6 +166,46 @@ export class CircuitDeviceRowProjectCommandRepository
|
|||
};
|
||||
}
|
||||
|
||||
// The row quantity is always the manual share plus every linked Revit
|
||||
// object. A manual-share edit derives the total; a total edit is only
|
||||
// valid while no Revit object contributes to the row.
|
||||
private applyQuantityPatch(
|
||||
database: AppDatabase,
|
||||
current: CircuitDeviceRow,
|
||||
patch: CircuitDeviceRowPatchInput
|
||||
) {
|
||||
const externalObjects = database
|
||||
.select({ planningValues: externalModelObjects.planningValues })
|
||||
.from(externalModelObjects)
|
||||
.where(eq(externalModelObjects.circuitDeviceRowId, current.id))
|
||||
.all()
|
||||
.map((object) => ({
|
||||
effectiveQuantity: object.planningValues.effectiveQuantity,
|
||||
}));
|
||||
const manualQuantity = patch.manualQuantity ?? current.manualQuantity;
|
||||
if (patch.quantity === undefined) {
|
||||
patch.quantity = calculateCircuitDeviceRowQuantity(
|
||||
manualQuantity,
|
||||
externalObjects
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
externalObjects.length > 0 &&
|
||||
patch.quantity !==
|
||||
calculateCircuitDeviceRowQuantity(manualQuantity, externalObjects)
|
||||
) {
|
||||
throw new Error(
|
||||
"Die Anzahl dieser Gerätezeile ist mit Revit-Objekten verknüpft. Bitte die manuelle Anzahl bearbeiten."
|
||||
);
|
||||
}
|
||||
assertCircuitDeviceRowQuantity({
|
||||
quantity: patch.quantity,
|
||||
manualQuantity,
|
||||
externalObjects,
|
||||
});
|
||||
}
|
||||
|
||||
private assertLinkedProjectDevice(
|
||||
database: AppDatabase,
|
||||
projectId: string,
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ export class ExternalObjectRowAssignmentProjectCommandRepository
|
|||
execute(input: Parameters<ExternalObjectRowAssignmentProjectCommandStore["execute"]>[0]) {
|
||||
assertExternalObjectRowAssignmentProjectCommand(input.command);
|
||||
return executeProjectCommandTransaction(this.database, input, (tx) => {
|
||||
this.apply(tx, input.projectId, input.command);
|
||||
this.apply(tx, input.projectId, input.command, input.source);
|
||||
return invertExternalObjectRowAssignmentProjectCommand(input.command);
|
||||
});
|
||||
}
|
||||
|
|
@ -39,7 +39,8 @@ export class ExternalObjectRowAssignmentProjectCommandRepository
|
|||
private apply(
|
||||
database: AppDatabase,
|
||||
projectId: string,
|
||||
command: Parameters<ExternalObjectRowAssignmentProjectCommandStore["execute"]>[0]["command"]
|
||||
command: Parameters<ExternalObjectRowAssignmentProjectCommandStore["execute"]>[0]["command"],
|
||||
source: Parameters<ExternalObjectRowAssignmentProjectCommandStore["execute"]>[0]["source"]
|
||||
) {
|
||||
const rowTransitions = new Map(
|
||||
command.payload.rows.map((transition) => [transition.expected.id, transition])
|
||||
|
|
@ -95,7 +96,14 @@ export class ExternalObjectRowAssignmentProjectCommandRepository
|
|||
const targetObjects = allProjectObjects.map((object) =>
|
||||
objectTransitions.get(object.id)?.target ?? object
|
||||
);
|
||||
const confirmedConflicts = new Set(command.payload.confirmedConflictObjectIds);
|
||||
// Undo/redo restores an exact state the user already accepted, for example
|
||||
// re-linking objects after "Revit-Objekte lösen". Only a new user
|
||||
// assignment needs explicit confirmation of planning-value conflicts.
|
||||
const confirmedConflicts = new Set(
|
||||
source === "user"
|
||||
? command.payload.confirmedConflictObjectIds
|
||||
: command.payload.objects.map(({ target }) => target.id)
|
||||
);
|
||||
|
||||
for (const transition of command.payload.rows) {
|
||||
const linkedObjects = targetObjects.filter(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue