2 Define special types used in BlueChips
5 import sqlalchemy as sa
6 from bluechips.lib.helpers import round_currency
7 from decimal import Decimal
9 class Currency(sa.types.TypeDecorator):
11 A type which represents monetary amounts internally as integers.
13 This avoids binary/decimal float conversion issues
16 impl = sa.types.Integer
18 def process_bind_param(self, value, engine):
19 return int(value * 100)
21 def convert_result_value(self, value, engine):
22 return round_currency(Decimal(value) / 100)