'Virtual Field to show the percentage used of the Budget'

@staticmethod
def budget_monitoring_percentage(row):

    if hasattr(row, 'budget_monitoring'):
        row = row.budget_monitoring
    if hasattr(row, 'planned'):
        planned = row.planned
        if (planned == 0.0):
            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'):
        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):
                return current.messages['NONE']
            percentage = ((r.value / planned) * 100)
            return ('%s    %%' % percentage)
    return current.messages['NONE']
