@staticmethod
    def budget_monitoring_percentage(row):
        """
            Virtual Field to show the percentage used of the Budget
        """

        if hasattr(row, "budget_monitoring"):
            row = row.budget_monitoring
        if hasattr(row, "planned"):
            planned = row.planned
            if planned == 0.0:
                # Can't divide by Zero
                return current.messages["NONE"]
        else:
            planned = None
        if hasattr(row, "value"):
            actual = row.value
        else:
            actual = None

        if planned is not None and actual is not None:
            percentage = actual / planned * 100
            return "%s %%" % "{0:.2f}".format(percentage)

        if hasattr(row, "id"):
            # Reload the record
            #s3_debug("Reloading budget_monitoring record")
            table = current.s3db.budget_monitoring
            r = current.db(table.id == row.id).select(table.planned,
                                                      table.value,
                                                      limitby=(0, 1)
                                                      ).first()
            if r:
                planned = r.planned
                if planned == 0.0:
                    # Can't divide by Zero
                    return current.messages["NONE"]
                percentage = r.value / planned * 100
                return "%s %%" % percentage

        return current.messages["NONE"]

# =============================================================================
dataset/ETHPy150Open sahana/eden/modules/s3db/budget.py/S3BudgetMonitoringModel.budget_monitoring_percentage/original