Beispiel #1
0
class Fee(common.ConfigurationModel):
    fractional_pct = db.Column(db.DECIMAL(precision=5, scale=4),
                               nullable=False,
                               default=0)
    flat = db.Column(db.DECIMAL(precision=8, scale=4),
                     nullable=False,
                     default=0)

    @property
    def percentage(self):
        return self.fractional_pct * Decimal('100.0000')
Beispiel #2
0
class CampaignGoalAssociation(db.Model, common.TrackIPMixin,
                              common.TrackTimeMixin, common.EnabledMixin,
                              common.FieldUpdateMixin):
    __tablename__ = 'campaign_goal_association'

    user = db.relationship('User', backref='goals', lazy='select')
    user_id = db.Column(db.BigInteger(unsigned=True),
                        db.ForeignKey('user.id'),
                        nullable=False,
                        primary_key=True)
    campaign = db.relationship('Campaign',
                               backref='goal_associations',
                               lazy='select')
    campaign_id = db.Column(db.BigInteger(unsigned=True),
                            db.ForeignKey('campaign.id'),
                            nullable=False,
                            primary_key=True)
    campaign_goal = db.relationship('CampaignGoal',
                                    backref='participants',
                                    lazy='select')
    campaign_goal_id = db.Column(db.BigInteger(unsigned=True),
                                 db.ForeignKey('campaign_goal.id'),
                                 nullable=False,
                                 primary_key=True)
    participation = db.Column(
        db.Enum('opted-in',
                'opted-out',
                'participating',
                'nonparticipating',
                name='participation_enum'))
    pledge = db.Column(db.DECIMAL(precision=24, scale=4), nullable=True)

    __table_args__ = (db.UniqueConstraint(user_id, campaign_id,
                                          campaign_goal_id), {})
Beispiel #3
0
class Exchange(common.LedgerModel):
    debit_currency_id = db.Column(db.BigInteger(unsigned=True),
                                  db.ForeignKey('currency.id'),
                                  nullable=False)
    debit_currency = db.relationship('Currency',
                                     backref='debit_exchanges',
                                     lazy='select',
                                     primaryjoin="Exchange.debit_currency_id==Currency.id")
    credit_currency_id = db.Column(db.BigInteger(unsigned=True),
                                   db.ForeignKey('currency.id'),
                                   nullable=False)
    credit_currency = db.relationship('Currency',
                                      backref='credit_exchanges',
                                      lazy='select',
                                      primaryjoin="Exchange.credit_currency_id==Currency.id")
    exchange_rate = db.Column(db.DECIMAL(precision=24, scale=4), nullable=False)
    balance = db.relationship('Balance', backref='exchanges', lazy='select')
    balance_id = db.Column(db.BigInteger(unsigned=True),
                           db.ForeignKey('balance.id'),
                           nullable=False)
Beispiel #4
0
class Balance(common.Model, common.EnabledMixin):

    currency_id = db.Column(db.BigInteger(unsigned=True),
                            db.ForeignKey('currency.id'),
                            nullable=False)
    currency = db.relationship('Currency', backref='balances')
    amount = db.Column(db.DECIMAL(precision=24, scale=4),
                       nullable=False,
                       default=0)
    user_id = db.Column(db.BigInteger(unsigned=True),
                        db.ForeignKey('user.id'),
                        nullable=True)
    user = db.relationship('User', backref='balances', lazy='select')
    campaign_id = db.Column(db.BigInteger(unsigned=True),
                            db.ForeignKey('campaign.id'),
                            nullable=True)
    campaign = db.relationship('Campaign', backref='balances', lazy='select')
    type = db.Column(db.Enum('user', 'campaign', name='balance_type_enum'))

    @classmethod
    def filter_by(cls, currency=None, query=None):
        from pooldlib.postgresql import Currency
        if hasattr(currency, 'id'):
            currency = currency.id

        if not query:
            query = cls.query

        if currency and isinstance(currency, basestring):
            query = query.join(Currency)
            return query.filter(Currency.code == currency)

        if currency:
            return query.filter(cls.currency_id == currency)

        return query

    @classmethod
    def first(cls, *args, **kw):
        return cls.filter_by(*args, **kw).first()

    @classmethod
    def filter_by_user(cls, user=None, currency=None):
        if hasattr(user, 'id'):
            user = user.id

        if not user:
            return

        query = cls.query.filter(cls.user_id == user)
        return super(Balance, cls).filter_by(currency=currency,
                                             query=query)

    @classmethod
    def filter_by_campaign(cls, campaign=None, currency=None):
        if hasattr(campaign, 'id'):
            campaign = campaign.id

        if not campaign:
            return

        query = cls.query.filter(cls.campaign_id == campaign)
        return super(Balance, cls).filter_by(currency=currency,
                                             query=query)
Beispiel #5
0
class LedgerMixin(object):
    created = db.Column(DateTimeTZ, default=datetime.utcnow)
    debit = db.Column(db.DECIMAL(precision=24, scale=4), nullable=True)
    credit = db.Column(db.DECIMAL(precision=24, scale=4), nullable=True)