]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/model/types.py
Define the model
[bluechips.git] / bluechips / model / types.py
1 """
2 Define special types used in BlueChips
3 """
4
5 import sqlalchemy as sa
6 from decimal import Decimal
7 import locale
8
9 class Currency(sa.types.TypeDecorator):
10     """
11     A type which represents monetary amounts internally as integers.
12     
13     This avoids binary/decimal float conversion issues
14     """
15     
16     impl = sa.types.Integer
17     
18     def process_bind_param(self, value, engine):
19         return int(value * 100)
20     
21     def convert_result_value(self, value, engine):
22         return Decimal(Decimal(value) / 100).quantize(Decimal("0.01"))