fix(est): avoid reused quantity references
This commit is contained in:
@@ -127,3 +127,12 @@ def test_manual_and_selected_sheet_totals_validate_before_application():
|
||||
assert result["b"]["GN"] == 9
|
||||
assert result["b"]["MulCode"] == {"binary": "YWJj"}
|
||||
assert result["invalid"]
|
||||
|
||||
|
||||
def test_new_quantity_code_does_not_reuse_existing_or_referenced_codes():
|
||||
result = run(
|
||||
"math",
|
||||
"""[EstQuantity.newCode([{Code:'Q2',formula:'[Q1]*3'}]),
|
||||
EstQuantity.newCode([{Code:'Q2',formula:'1'}]), EstQuantity.newCode([])]""",
|
||||
)
|
||||
assert result == ["Q3", "Q1", "Q1"]
|
||||
|
||||
@@ -398,17 +398,15 @@ const EstActions = (() => {
|
||||
},
|
||||
);
|
||||
else if (name === "add-quantity")
|
||||
EstApp.change(
|
||||
() =>
|
||||
project.quantities.push({
|
||||
Code: `Q${project.quantities.length + 1}`,
|
||||
Name: "새 수량",
|
||||
TargetCode: "",
|
||||
formula: "1",
|
||||
digits: 2,
|
||||
}),
|
||||
false,
|
||||
);
|
||||
EstApp.change(() => {
|
||||
project.quantities.push({
|
||||
Code: EstQuantity.newCode(project.quantities),
|
||||
Name: "새 수량",
|
||||
TargetCode: "",
|
||||
formula: "1",
|
||||
digits: 2,
|
||||
});
|
||||
}, false);
|
||||
else if (name === "apply-quantity") {
|
||||
const totals = EstQuantity.totals(project, state.quantitySheet);
|
||||
if (confirm("연결된 내역 수량을 산출 결과로 바꾸시겠습니까?"))
|
||||
|
||||
@@ -151,6 +151,14 @@ const EstQuantity = (() => {
|
||||
for (const row of project.tables.EstMainDat)
|
||||
if (quantities.has(row.Code) && !Number(row.Level)) row.GN = quantities.get(row.Code);
|
||||
}
|
||||
function newCode(items) {
|
||||
const codes = new Set(items.map((row) => row.Code));
|
||||
for (const row of items)
|
||||
for (const match of String(row.formula || "").matchAll(/\[([^\]]+)\]/g)) codes.add(match[1]);
|
||||
let index = 1;
|
||||
while (codes.has(`Q${index}`)) index++;
|
||||
return `Q${index}`;
|
||||
}
|
||||
function selector(state) {
|
||||
const { esc } = EstApp;
|
||||
return `<div class="business-tools"><label>수량산출서 <select id="quantity-sheet-choice"><option value="manual">수식표 직접 작성</option>${(state.project.quantitySheets || []).map((sheet) => `<option value="${esc(sheet.Code)}" ${state.quantitySheet === sheet.Code ? "selected" : ""}>${esc(sheet.Name || sheet.Code)}</option>`).join("")}</select></label><button data-quantity-new>새 산출서</button></div>`;
|
||||
@@ -270,6 +278,6 @@ const EstQuantity = (() => {
|
||||
}
|
||||
});
|
||||
}
|
||||
return { entities, fromWpt, calculate, totals, applyTotals, selector, render, install };
|
||||
return { entities, fromWpt, calculate, totals, applyTotals, newCode, selector, render, install };
|
||||
})();
|
||||
if (typeof module !== "undefined" && module.exports) module.exports = EstQuantity;
|
||||
|
||||
Reference in New Issue
Block a user