fix(est): distinguish repeated change items

This commit is contained in:
2026-11-07 10:31:12 +09:00
parent eb3dba0e9e
commit 0f635cef0f
2 changed files with 40 additions and 19 deletions
@@ -1,6 +1,22 @@
from test_est_rea_parity import run
def test_duplicate_codes_match_distinct_original_rows_and_track_deletions():
result = run(
"math",
"""(()=>{
const p=EstNative.empty();p.tables.EstMainDat=[{Code:'A',Name:'first',GN:2,TC:200},
{Code:'A',Name:'second',GN:4,TC:400}];
p.baseline={name:'old',tables:{EstMainDat:[{Code:'A',Name:'first',GN:1,TC:100},
{Code:'A',Name:'second',GN:3,TC:300},{Code:'A',Name:'removed',GN:5,TC:500}]}};
return EstBusiness.changes(p);
})()""",
)
assert [row["originalTC"] for row in result] == [100, 300, 500]
assert [row["difference"] for row in result] == [100, 100, -500]
assert result[-1]["status"] == "deleted"
def test_design_change_costs_include_duplicate_new_and_deleted_cost_rows():
result = run(
"math",
+24 -19
View File
@@ -54,10 +54,15 @@ const EstBusiness = (() => {
}
function changes(project) {
const old = project.baseline?.tables.EstMainDat || [];
const seen = new Set();
const groups = new Map();
old.forEach((row, index) => {
const key = rowKey(row, index),
group = groups.get(key) || [];
group.push({ row, index });
groups.set(key, group);
});
const changes = project.tables.EstMainDat.map((row, index) => {
seen.add(rowKey(row, index));
const saved = old.find((r, i) => rowKey(r, i) === rowKey(row, index));
const saved = groups.get(rowKey(row, index))?.shift()?.row;
const stored =
!project.baseline && ["Code_", "Name_", "GN_", "TC_"].some((key) => row[key] != null)
? Object.fromEntries(
@@ -87,22 +92,22 @@ const EstBusiness = (() => {
originalSource: saved ? "baseline" : stored ? "file" : null,
};
});
old.forEach((row, index) => {
if (seen.has(rowKey(row, index))) return;
changes.push({
key: rowKey(row, index),
Code: row.Code || "",
Name: row.Name || "",
originalGN: num(row.GN),
originalTC: num(row.TC),
GN: 0,
TC: 0,
difference: -num(row.TC),
NewItem: false,
status: "deleted",
originalSource: "baseline",
});
});
for (const group of groups.values())
for (const { row, index } of group) {
changes.push({
key: rowKey(row, index),
Code: row.Code || "",
Name: row.Name || "",
originalGN: num(row.GN),
originalTC: num(row.TC),
GN: 0,
TC: 0,
difference: -num(row.TC),
NewItem: false,
status: "deleted",
originalSource: "baseline",
});
}
return changes;
}
function costChanges(project) {