diff --git a/corepos/db/model.py b/corepos/db/model.py index dee6ad6565f662f810a8b7e4875fce1c195387bc..005efed29dd3d18ea0fc38766e26896a190b8f5a 100644 --- a/corepos/db/model.py +++ b/corepos/db/model.py @@ -378,6 +378,7 @@ class MemberType(Base): return self.description or "" +@six.python_2_unicode_compatible class Customer(Base): """ Represents a customer of the organization. @@ -386,68 +387,70 @@ class Customer(Base): id = sa.Column(sa.Integer(), primary_key=True, autoincrement=True, nullable=False) - CardNo = sa.Column(sa.Integer(), nullable=True) + card_number = sa.Column('CardNo', sa.Integer(), nullable=True) - personNum = sa.Column(sa.SmallInteger(), nullable=False, default=1) + person_number = sa.Column('personNum', sa.SmallInteger(), nullable=False, default=1) - FirstName = sa.Column(sa.String(length=30), nullable=True) + first_name = sa.Column('FirstName', sa.String(length=30), nullable=True) - LastName = sa.Column(sa.String(length=30), nullable=True) + last_name = sa.Column('LastName', sa.String(length=30), nullable=True) - CashBack = sa.Column(sa.Float(), nullable=False, default=60) + cash_back = sa.Column('CashBack', sa.Float(), nullable=False, default=60) - Balance = sa.Column(sa.Float(), nullable=False, default=0) + balance = sa.Column('Balance', sa.Float(), nullable=False, default=0) - Discount = sa.Column(sa.SmallInteger(), nullable=True) + discount = sa.Column('Discount', sa.SmallInteger(), nullable=True) - MemDiscountLimit = sa.Column(sa.Float(), nullable=False, default=0) + member_discount_limit = sa.Column('MemDiscountLimit', sa.Float(), nullable=False, default=0) - ChargeLimit = sa.Column(sa.Float(), nullable=False, default=0) + charge_limit = sa.Column('ChargeLimit', sa.Float(), nullable=False, default=0) - ChargeOk = sa.Column(sa.Boolean(), nullable=False, default=False) + charge_ok = sa.Column('ChargeOk', sa.Boolean(), nullable=False, default=False) - WriteChecks = sa.Column(sa.Boolean(), nullable=False, default=True) + write_checks = sa.Column('WriteChecks', sa.Boolean(), nullable=False, default=True) - StoreCoupons = sa.Column(sa.Boolean(), nullable=False, default=True) + store_coupons = sa.Column('StoreCoupons', sa.Boolean(), nullable=False, default=True) - Type = sa.Column(sa.String(length=10), nullable=False, default='pc') + type = sa.Column('Type', sa.String(length=10), nullable=False, default='pc') - memType = sa.Column(sa.SmallInteger(), nullable=True) + member_type_id = sa.Column('memType', sa.SmallInteger(), nullable=True) + member_type = orm.relationship( + MemberType, + primaryjoin=MemberType.id == member_type_id, + foreign_keys=[member_type_id], + doc=""" + Reference to the :class:`MemberType` to which this member belongs. + """) staff = sa.Column(sa.Boolean(), nullable=False, default=False) - SSI = sa.Column(sa.Boolean(), nullable=False, default=False) - - Purchases = sa.Column(sa.Float(), nullable=False, default=0) + ssi = sa.Column('SSI', sa.Boolean(), nullable=False, default=False) - NumberOfChecks = sa.Column(sa.SmallInteger(), nullable=False, default=0) + purchases = sa.Column('Purchases', sa.Float(), nullable=False, default=0) - memCoupons = sa.Column(sa.Integer(), nullable=False, default=1) + number_of_checks = sa.Column('NumberOfChecks', sa.SmallInteger(), nullable=False, default=0) - blueLine = sa.Column(sa.String(length=50), nullable=True) + member_coupons = sa.Column('memCoupons', sa.Integer(), nullable=False, default=1) - Shown = sa.Column(sa.Boolean(), nullable=False, default=True) + blue_line = sa.Column('blueLine', sa.String(length=50), nullable=True) - LastChange = sa.Column(sa.DateTime(), nullable=False) + shown = sa.Column('Shown', sa.Boolean(), nullable=False, default=True) - member_type = orm.relationship( - MemberType, - primaryjoin=MemberType.id == memType, - foreign_keys=[memType], - doc=""" - Reference to the :class:`MemberType` to which this member belongs. - """) + last_change = sa.Column('LastChange', sa.DateTime(), nullable=False) member_info = orm.relationship( 'MemberInfo', - primaryjoin='MemberInfo.card_no == Customer.CardNo', - foreign_keys=[CardNo], + primaryjoin='MemberInfo.card_no == Customer.card_number', + foreign_keys=[card_number], uselist=False, back_populates='customers', doc=""" Reference to the :class:`MemberInfo` instance for this customer. """) + def __str__(self): + return "{} {}".format(self.first_name or '', self.last_name or '').strip() + class MemberInfo(Base): """ @@ -483,10 +486,10 @@ class MemberInfo(Base): customers = orm.relationship( Customer, - primaryjoin=Customer.CardNo == card_no, - foreign_keys=[Customer.CardNo], + primaryjoin=Customer.card_number == card_no, + foreign_keys=[Customer.card_number], back_populates='member_info', - remote_side=Customer.CardNo, + remote_side=Customer.card_number, doc=""" List of :class:`Customer` instances which are associated with this member info. """)