fix(est): apply selected estimate classification safely

This commit is contained in:
2026-11-07 16:30:44 +09:00
parent c530ac694c
commit 9eae77d8f2
8 changed files with 138 additions and 9 deletions
+1
View File
@@ -26,6 +26,7 @@ for (const file of [
"native-exchange.js",
"native-verify.js",
"native-extra.js",
"native-business-actions.js",
"native-forms.js",
]) {
vm.runInContext(fs.readFileSync(path.join(base, file), "utf8"), context, { filename: file });
+39
View File
@@ -3,6 +3,45 @@
from test_est_rea_parity import run
def test_estimate_classification_refreshes_only_selected_source_and_preserves_manual_mode():
result = run(
"math",
"""(()=>{
const p=EstNative.empty();p.options.SourceRefresh=false;p.options.AutoCalc=false;
p.tables.StuffcDat=[{Code:'M',Name:'material',Cost1:100,ValueIndex:0},{Code:'N',Name:'other',Cost1:800,ValueIndex:0}];
p.tables.EstMainDat=[{PkID:1,Code:'M',Name:'material',LinkIndex:5,GN:2,GU:100,GC:200,JC:0},
{PkID:2,Code:'N',Name:'other',LinkIndex:5,GN:1,GU:5,GC:5},{LinkIndex:54}];
const row=p.tables.EstMainDat[0],other=JSON.stringify(p.tables.EstMainDat[1]);
EstBusinessActions.setEstimateClassification(p,row,0,3);
const manual={JU:row.JU,GU:row.GU,GC:row.GC,JC:row.JC};
const auto=EstNative.calculate(p).tables.EstMainDat[0];
EstBusinessActions.setEstimateClassification(p,row,0,0);
const restored={GU:row.GU,JU:row.JU};
const missing={PkID:3,Code:'missing',LinkIndex:5,SCheck:0,GU:7};p.tables.EstMainDat.push(missing);
EstBusinessActions.setEstimateClassification(p,missing,3,3);
let rejected=0;try{EstBusinessActions.setEstimateClassification(p,missing,3,0)}catch{rejected++}
EstBusinessActions.setEstimateClassification(p,row,0,3);
p.tables.StuffcDat.push({...p.tables.StuffcDat[0]});try{EstBusinessActions.setEstimateClassification(p,row,0,0)}catch{rejected++}
const mismatch={PkID:4,Code:'N',LinkIndex:5,SCheck:0,GU:5};p.tables.EstMainDat.push(mismatch);
EstBusinessActions.setEstimateClassification(p,mismatch,4,3);
try{EstBusinessActions.setEstimateClassification(p,mismatch,4,0)}catch{rejected++}
p.tables.StuffcDat.push({Code:'L',Cost1:1000000000000,ValueIndex:0});
const large={PkID:5,Code:'L',LinkIndex:5,SCheck:0,GU:999999999900};p.tables.EstMainDat.push(large);
EstBusinessActions.setEstimateClassification(p,large,5,3);
try{EstBusinessActions.setEstimateClassification(p,large,5,0)}catch{rejected++}
return {manual,auto:{GC:auto.GC,JC:auto.JC},restored,rejected,missing,mismatch,large,other:JSON.stringify(p.tables.EstMainDat[1])===other,flag:p.options.SourceRefresh};
})()""",
)
assert result["manual"] == {"JU": 100, "GU": 0, "GC": 200, "JC": 0}
assert result["auto"] == {"GC": 0, "JC": 200}
assert result["restored"] == {"GU": 100, "JU": 0}
assert result["rejected"] == 4
assert result["missing"]["SCheck"] == 3 and result["missing"]["JU"] == 7
assert result["mismatch"]["SCheck"] == 3 and result["mismatch"]["JU"] == 5
assert result["large"]["SCheck"] == 3 and result["large"]["JU"] == 999999999900
assert result["other"] and not result["flag"]
def test_annual_formulas_split_component_amounts_and_preserve_remainder():
result = run(
"math",