0

Hi I am having a problem regarding a status. Sample: availBudget = 1000.00 and totBaseCost = 1000.01 it must be UNBUDGETED, but I think it only gets the whole number.

totBaseCost = mbo.getDouble("TOTALBASECOST")
totBaseCost1 = "%.2f" % float(totBaseCost)
#totBaseCost1 = "%.2f" % totBaseCost
budgetSet = mbo.getMboSet("BUDGET")
availBudget = 0
if budgetSet is not None:
    budgetMbo = budgetSet.getMbo(0)
    totBudgetAmount = budgetMbo.getFloat("C1BUDTOTCOST")
    estTotCost = budgetMbo.getMboSet("C1ESTTOTCOSE").sum("LINECOST")
    comTotCost = budgetMbo.getMboSet("C1COMMITTED").sum("LINECOST")
    actTotCost = budgetMbo.getMboSet("C1ACTTOTCOST").sum("LINECOST")

    #Available Budget
    availBudget = float(totBudgetAmount) - float(estTotCost) - float(comTotCost) - float(actTotCost)

    availBudget = "%.3f" % availBudget
    if availBudget < 0:
        availBudget = abs(availBudget)

    if (totBaseCost1) > availBudget and availBudget <> 0:
        mbo.setValue("C1BUDGETSTATUS","",11L)
        mbo.setValue("C1BUDGETSTATUS","UNBUDGETED",11L)
    elif (totBaseCost1) <= availBudget:
        mbo.setValue("C1BUDGETSTATUS","",11L)
        mbo.setValue("C1BUDGETSTATUS","BUDGETED",11L)
    elif str(totBaseCost1) == "0.00" and str(availBudget) <> "0.00":
        mbo.setValue("C1BUDGETSTATUS","",11L)
        mbo.setValue("C1BUDGETSTATUS","BUDGETED",11L)
  • 1
    By the way, I think "getMboSet" *always* returns a set. That set may have zero MBO records, but it will always exist. That would mean the "if budgetSet is not None:" is not doing anything, and you can still get a null pointer exception / NoneType exception on the "budgetMbo.getFloat("C1BUDTOTCOST")" line if the set was empty. That should probably be "if not budgetSet.isEmpty():" or "budgetMbo = budgetSet.getMbo(0)" and "if budgetMbo is not None:" – Dex Mar 14 '19 at 03:46

2 Answers2

0

Python does type coercion, and this might be your problem. Where you have comparisons or assignments of 0 (an integer), try using 0.0 (a float) instead.

Preacher
  • 2,127
  • 1
  • 11
  • 25
0

Use the psdi.util.MXMath class to perform cost calculations as it uses BigDecimal behind the scenes. Look at this entry for reasons for not using floats/doubles for money calculations.

Also, as Dex pointed out, you should use isEmpty() method on mboSet to determine if you obtain records, or not.

JPTremblay
  • 900
  • 5
  • 8