Login

Widget for Money values on Geraldo Reports

Author:
marinho
Posted:
April 18, 2009
Language:
Python
Version:
1.0
Tags:
geraldo
Score:
0 (after 0 ratings)

This is a widget for decimal/money/currency fields on Geraldo Reports.

When you use Geraldo to write reports, decimal fields must be formatted using get_value lambda attribute, because ObjectValue doesn't know what mask you want to use.

With this widget, you just copy it into a common use Python file, import into your reports file and use it replacing ObjectValue on elements for fields you must be formatted as money format.

Example:

from geraldo import Report, ReportBand, ObjectValue
from utils.reports import DecimalObjectValue

class ReportCustomers(Report):
    title = u'Customers List'
    page_size = A4

    class band_detail(ReportBand):
        height = 0.5*cm
        elements = [
            ObjectValue(attribute_name='id', top=0.1*cm),
            DecimalObjectValue(attribute_name='salary',
                left=26.2*cm, top=0.1*cm, format='%0.03f'),
            ]
1
2
3
4
5
6
7
8
9
class DecimalObjectValue(ObjectValue):
    format = '%0.02f'
    def get_object_value(self, instance=None):
        value = super(DecimalObjectValue, self).get_object_value(instance)

        if not value:
            value = 0

        return self.format%value

More like this

  1. Widget for DateTime values on Geraldo Reports by marinho 5 years, 11 months ago
  2. Integer based MoneyField by Jay 5 years, 6 months ago
  3. CSV to JSON Fixture by briangershon 5 years, 7 months ago
  4. django-pyodbc MoneyField by Tarken 6 years, 5 months ago
  5. GeoDjango maps in admin TabularInlines by alanB 4 years, 5 months ago

Comments

Please login first before commenting.