コード例 #1
0
class Receipt(db.Model):
    __tablename__ = "receipts"
    receipt_id = db.Column(db.Integer, primary_key=True, nullable=False, autoincrement=True, unique=True)
    stock_id = db.Column(db.Integer, db.ForeignKey("stock.stock_id"), nullable=False)
    datetime = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
    quantity = db.Column(db.Integer, nullable=False, default=1)
    member_uid = db.Column(db.VARCHAR(75), nullable=True)
    method = db.Column(db.Enum(PaymentMethod), nullable=True)

    purchased = db.relationship(Stock, backref=db.backref("Stock", uselist=False))

    @property
    def serialize(self):
        """Return object data in easily serializeable format"""
        return {
            'receipt_id': self.receipt_id,
            'datetime': self.datetime.strftime('%m/%d/%Y'),
            'purchased': self.purchased.serialize,
            'cost': self.quantity * float(self.purchased.item.product.price),
            'quantity': self.quantity,
            'member_uid': self.member_uid,
            'method': self.method.name,
        }

    def __init__(self, item_id, member_uid, method, quantity):
        self.stock_id = item_id
        self.member_uid = member_uid
        self.method = method
        self.quantity = quantity
コード例 #2
0
class Swag(db.Model):
    __tablename__ = "swag"
    swag_id = db.Column(db.Integer, primary_key=True, nullable=False, autoincrement=True, unique=True)
    name = db.Column(db.VARCHAR(45), nullable=False)
    description = db.Column(db.VARCHAR(255))
    category = db.Column(db.VARCHAR(45), nullable=False)
    price = db.Column(db.DECIMAL(25, 2), nullable=False)

    @property
    def serialize(self):
        """Return object data in easily serializeable format"""
        return {
            'swag_id': self.swag_id,
            'name': self.name,
            'description': self.description,
            'category': self.category,
            'price': str(self.price),
        }
コード例 #3
0
class Item(db.Model):
    __tablename__ = "items"
    item_id = db.Column(db.Integer, primary_key=True, nullable=False, autoincrement=True, unique=True)
    product_id = db.Column(db.Integer, db.ForeignKey("swag.swag_id"), nullable=False)
    color = db.Column(db.VARCHAR(45), nullable=False)
    image = db.Column(db.VARCHAR(255), nullable=True)

    product = db.relationship(Swag, backref=db.backref("swag", uselist=False))

    @property
    def stock(self):
        item_stock = Stock.query.filter_by(item_id=self.item_id)
        return sum(i.stock for i in item_stock)

    @property
    def serialize(self):
        """Return object data in easily serializeable format"""
        item_stock = Stock.query.filter_by(item_id=self.item_id)
        return {
            'item_id': self.item_id,
            'product': self.product.serialize,
            'color': self.color,
            'image': self.image,
            'stock': self.stock,
            'sizes': [i.serialize for i in item_stock]
        }

    @property
    def serialize_single(self):
        """Return object data in easily serializeable format"""
        item_stock = Stock.query.filter_by(item_id=self.item_id)
        stock = sum(i.stock for i in item_stock)
        return {
            'item_id': self.item_id,
            'product': self.product.serialize,
            'color': self.color,
            'image': self.image,
            'stock': stock,
        }
コード例 #4
0
class CashFlow(db.Model):
    __tablename__ = "cashflow"
    flow_id = db.Column(db.Integer, primary_key=True, nullable=False, autoincrement=True, unique=True)
    datetime = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
    reason = db.Column(db.VARCHAR(150), nullable=True)
    financial_uid = db.Column(db.VARCHAR(75), nullable=False)
    account_to = db.Column(db.Enum(PaymentMethod), nullable=True)
    account_from = db.Column(db.Enum(PaymentMethod), nullable=True)
    amount = db.Column(db.DECIMAL(25, 2), nullable=False)

    @property
    def serialize(self):
        """Return object data in easily serializeable format"""
        return {
            'flow_id': self.receipt_id,
            'datetime': self.datetime.strftime('%m/%d/%Y'),
            'reason': self.reason.serialize,
            'financial_uid': self.financial_uid,
            'account_to': self.account_to.name,
            'account_from': self.account_from.name,
            'amount': self.amount,
        }
コード例 #5
0
class Review(db.Model):
    __tablename__ = "reviews"
    review_id = db.Column(db.Integer, primary_key=True, nullable=False, autoincrement=True, unique=True)
    datetime = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
    member_uid = db.Column(db.VARCHAR(75), nullable=False)
    item_id = db.Column(db.Integer, db.ForeignKey("items.item_id"), nullable=False)
    review_score = db.Column(db.Float)
    review_text = db.Column(db.Text)

    def __init__(self, member_uid, item_id, review_score, review_text):
        self.member_uid = member_uid
        self.item_id = item_id
        self.review_score = review_score
        self.review_text = review_text