コード例 #1
0
class InvoiceItem(db.Model):
    __name__ = 'invoice_item'
    id = db.Column(db.Integer, primary_key=True)
    units = db.Column(db.Integer, nullable=False)
    description = db.Column(db.String(60), nullable=False)
    amount = db.Column(db.Numeric(10, 2), nullable=False)
    invoice_id = db.Column(db.Integer, db.ForeignKey('invoice.id'))
コード例 #2
0
class Sample(db.Model):
    __tablename__ = "sample"
    grain_id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.DateTime,
                     default=datetime.utcnow,
                     onupdate=datetime.utcnow)
    l_value = db.Column(db.Numeric())
    harmful = db.Column(db.Boolean())
    photo = db.Column(db.String(32))
コード例 #3
0
ファイル: payments.py プロジェクト: Kiriwill/Payment
class Payment(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    count_items = db.Column(db.Integer, nullable=False)
    total_value = db.Column(db.Numeric(precision=8, scale=2), nullable=False)
    items = db.relationship('Item',
                            secondary=payment_items,
                            lazy='subquery',
                            backref=db.backref('payments', lazy=True))
コード例 #4
0
class Product(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    sku = db.Column(db.String(12), unique=True)
    name = db.Column(db.String(64))
    discription = db.Column(db.Text, nullable=True)
    price = db.Column(db.Numeric(10, 2))
    image = db.Column(db.Text, nullable=True)
    created = db.Column(db.DateTime(timezone=True), server_default=func.now())
    updated = db.Column(db.DateTime(timezone=True), onupdate=func.now())

    def __str__(self):
        return f"{self.id}-{self.name}"
コード例 #5
0
class Orders(db.Model):
    order_id = db.Column(db.Integer, primary_key=True)
    date_ordered = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    total_quantity = db.Column(db.Integer, nullable=False, default=0)
    total_price = db.Column(db.Numeric())
    customer_id = db.Column(db.Integer,
                            db.ForeignKey('customers.customer_id'),
                            nullable=False)
    orderdetails = db.relationship('OrderDetails',
                                   backref=db.backref('order', lazy=True),
                                   cascade="all, delete-orphan")
    status = db.Column(db.String(25), nullable=False, default='progress')

    def __str__(self):
        return "{} {}".format(self.total_quantity, self.total_price)
コード例 #6
0
class Products(db.Model):
    product_id = db.Column(db.Integer, primary_key=True)
    product_name = db.Column(db.String(200), nullable=False)
    product_image = db.Column(db.String(150), nullable=False)
    category_id = db.Column(db.Integer,
                            db.ForeignKey('categories.category_id'),
                            nullable=False)
    # description = db.Column(db.Text, nullable=False)
    orderdetails = db.relationship('OrderDetails',
                                   backref=db.backref('product', lazy=True))
    stock_quantity = db.Column(db.Integer, nullable=False)
    price = db.Column(db.Numeric())
    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)

    def __str__(self):
        return "{} {}".format(self.product_name)
コード例 #7
0
class OrderDetails(db.Model):
    order_detail_id = db.Column(db.Integer, primary_key=True)
    order_id = db.Column(db.Integer, db.ForeignKey('orders.order_id'))
    product_id = db.Column(db.Integer, db.ForeignKey('products.product_id'))
    quantity = db.Column(db.Integer, nullable=False)
    cost = db.Column(db.Numeric())
コード例 #8
0
ファイル: items.py プロジェクト: Kiriwill/Payment
class Item(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(24), nullable=False)
    value_unit = db.Column(db.Numeric(precision=5, scale=2), nullable=False)
コード例 #9
0
class Pictures(db.Model):
    __tablename__ = "pictures"
    id = db.Column(db.Integer, primary_key=True)
    picPath = db.Column(db.String(128))
    timestamp = db.Column(db.DateTime,
                          default=datetime.now,
                          onupdate=datetime.now)
    eyeglasses = db.Column(db.Numeric(1, 10))
    sunglasses = db.Column(db.Numeric(1, 10))
    gender = db.Column(db.Numeric(1, 10))
    beard = db.Column(db.Numeric(1, 10))
    mustache = db.Column(db.Numeric(1, 10))
    ageMin = db.Column(db.Integer)
    ageMax = db.Column(db.Integer)
    calm = db.Column(db.Numeric(1, 10))
    sad = db.Column(db.Numeric(1, 10))
    surprised = db.Column(db.Numeric(1, 10))
    angry = db.Column(db.Numeric(1, 10))
    happy = db.Column(db.Numeric(1, 10))
    confused = db.Column(db.Numeric(1, 10))
    fear = db.Column(db.Numeric(1, 10))
    disgusted = db.Column(db.Numeric(1, 10))
    brightness = db.Column(db.Numeric(1, 10))
    sharpness = db.Column(db.Numeric(1, 10))
    face_id = db.Column(db.String(36), unique=False)

    fk_place = db.Column(db.Integer, db.ForeignKey('places.id'))
    Represents = db.relationship('Represents', backref='picture')
コード例 #10
0
class Liquor(db.Model):
    __tablename__ = "liquors"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255))
    brand = db.Column(db.String(255))
    price = db.Column(db.Numeric(5, 2))
    liquor_type = db.Column(db.Text)
    proof = db.Column(db.Integer)
    created_by = db.Column(db.Integer,
                           db.ForeignKey('admins.id'),
                           nullable=False)
    is_active = db.Column(db.Boolean, default=True)
    date_created = db.Column(db.DateTime, server_default=func.now())
    date_updated = db.Column(db.DateTime,
                             server_default=func.now(),
                             onupdate=func.now())

    # Class Methods
    @classmethod
    def validate_liquor_item(cls, liq_data):
        MONEY_REGEX = re.compile(r'^([0-9]{1,5}\.[0-9]{1,2})?$')
        PROOF_REGEX = re.compile(r'^([0-9]{1,3})?$')
        is_valid = True

        if len(liq_data["liq_name"]) < 2:
            flash("Please enter the name of the liquor.", 'err_liq')
            is_valid = False
        if len(liq_data["liq_brand"]) < 2:
            flash("Please enter the brand of the liquor.", 'err_liq')
            is_valid = False
        if len(liq_data["liq_type"]) < 2:
            flash("Please enter the type of liquor.", 'err_liq')
            is_valid = False
        if len(liq_data["liq_price"]) > 1:
            if MONEY_REGEX.match(liq_data["liq_price"]) is None:
                flash("The item's price is not in dollar format.", 'err_liq')
                is_valid = False
        else:
            flash("Please enter a price for the liquor.", 'err_liq')
            is_valid = False
        if len(liq_data["liq_proof"]) > 1:
            if PROOF_REGEX.match(liq_data["liq_proof"]) is None:
                flash("The liquor's proof is not in the proper format.",
                      'err_liq')
                is_valid = False
        else:
            flash("Please enter a proof for the liquor (0 to disregard).",
                  'err_liq')
            is_valid = False

        return is_valid

    @classmethod
    def add_liquor_item(cls, liq_data):
        # set nitro flag in calling function and add to request.form before call
        new_instance_of_liq = cls(name=liq_data["liq_name"],
                                  brand=liq_data["liq_brand"],
                                  price=liq_data["liq_price"],
                                  liquor_type=liq_data["liq_type"],
                                  proof=liq_data["liq_proof"],
                                  created_by=session["userid"])
        db.session.add(new_instance_of_liq)
        db.session.commit()
        return new_instance_of_liq

    @classmethod
    def update_liquor_status(cls, active_liq_list):
        active_list = cls.query.filter(cls.id.in_(active_liq_list)).all()
        not_active_list = cls.query.filter(not_(
            cls.id.in_(active_liq_list))).all()

        for item in active_list:
            item.is_active = True

        for item in not_active_list:
            item.is_active = False

        db.session.commit()

    @classmethod
    def update_liquor_item(cls, food_id):
        pass

    @classmethod
    def delete_liquor_item(cls, liq_id):
        item = cls.query.get(liq_id)
        db.session.delete(item)
        db.session.commit()
コード例 #11
0
class Beer(db.Model):
    __tablename__ = "beers"
    id = db.Column(db.Integer, primary_key=True)
    brewery_name = db.Column(db.String(255))
    beer_name = db.Column(db.String(255))
    beer_type = db.Column(db.String(255))  # Ale, Lager, IPA, etc.
    price = db.Column(db.Numeric(5, 2))
    description = db.Column(db.Text)
    abv = db.Column(db.Numeric(2, 1))
    ibu = db.Column(db.Integer)
    nitro_flag = db.Column(db.Boolean, default=False)
    created_by = db.Column(db.Integer,
                           db.ForeignKey('admins.id'),
                           nullable=False)
    is_active = db.Column(db.Boolean, default=True)
    date_created = db.Column(db.DateTime, server_default=func.now())
    date_updated = db.Column(db.DateTime,
                             server_default=func.now(),
                             onupdate=func.now())

    # Class Methods
    @classmethod
    def validate_beer_item(cls, beer_data):
        MONEY_REGEX = re.compile(r'^([0-9]{1,5}\.[0-9]{1,2})?$')
        ABV_REGEX = re.compile(r'^([0-9]{1,2}\.[0-9]{1,1})?$')
        is_valid = True

        if len(beer_data["brewery_name"]) < 2:
            flash("Please enter the name of the brewery.", 'err_beer')
            is_valid = False
        if len(beer_data["beer_name"]) < 2:
            flash("Please enter the name of the beer.", 'err_beer')
            is_valid = False
        if len(beer_data["beer_type"]) < 2:
            flash("Please enter the style of beer.", 'err_beer')
            is_valid = False
        if len(beer_data["beer_price"]) > 1:
            if MONEY_REGEX.match(beer_data["beer_price"]) is None:
                flash("The item's price is not in dollar format.", 'err_beer')
                is_valid = False
        else:
            flash("Please enter a price for the beer.", 'err_beer')
            is_valid = False
        if len(beer_data["beer_abv"]) > 1:
            if ABV_REGEX.match(beer_data["beer_abv"]) is None:
                flash("The beer's ABV is not in the proper format.",
                      'err_beer')
                is_valid = False
        else:
            flash("Please enter the ABV of the beer.", 'err_beer')
            is_valid = False
        if len(beer_data["beer_type"]) < 2:
            flash("Please enter the style of beer.", 'err_beer')
            is_valid = False

        return is_valid

    @classmethod
    def add_beer_item(cls, beer_data):
        if "nitro_beer" not in beer_data:
            nitro_beer = False
        if len(beer_data["beer_ibu"]) < 1:
            beer_data["beer_ibu"] = 0

        new_instance_of_beer = cls(brewery_name=beer_data["brewery_name"],
                                   beer_name=beer_data["beer_name"],
                                   beer_type=beer_data["beer_type"],
                                   price=beer_data["beer_price"],
                                   description=beer_data["beer_desc"],
                                   abv=beer_data["beer_abv"],
                                   ibu=beer_data["beer_ibu"],
                                   nitro_flag=nitro_beer,
                                   created_by=session["userid"])
        db.session.add(new_instance_of_beer)
        db.session.commit()
        return new_instance_of_beer

    @classmethod
    def update_beer_status(cls, active_beer_list):
        active_list = cls.query.filter(cls.id.in_(active_beer_list)).all()
        not_active_list = cls.query.filter(not_(
            cls.id.in_(active_beer_list))).all()

        for item in active_list:
            item.is_active = True

        for item in not_active_list:
            item.is_active = False

        db.session.commit()

    @classmethod
    def update_beer_item(cls, food_id):
        pass

    @classmethod
    def delete_beer_item(cls, beer_id):
        item = cls.query.get(beer_id)
        db.session.delete(item)
        db.session.commit()
コード例 #12
0
class Food(db.Model):
    __tablename__ = "foods"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255))
    price = db.Column(db.Numeric(5, 2))
    description = db.Column(db.Text)
    category = db.Column(
        db.Integer
    )  # 1 = app, 2 = soup/salad, 3 = burgers, 4 = steak, 5 = sandwiches, 6 = specials
    created_by = db.Column(db.Integer,
                           db.ForeignKey('admins.id'),
                           nullable=False)
    is_active = db.Column(db.Boolean, default=True)
    date_created = db.Column(db.DateTime, server_default=func.now())
    date_updated = db.Column(db.DateTime,
                             server_default=func.now(),
                             onupdate=func.now())

    # Class Methods
    @classmethod
    def validate_food_item(cls, food_data):
        MONEY_REGEX = re.compile(r'^([0-9]{1,5}\.[0-9]{1,2})?$')
        is_valid = True

        if len(food_data["food_name"]) < 2:
            flash(
                "The name of the food item must be at least 2 characters long.",
                'err_food')
            is_valid = False
        if len(food_data["food_price"]) > 1:
            if MONEY_REGEX.match(food_data["food_price"]) is None:
                flash("The item's price is not in dollar format.", 'err_food')
                is_valid = False
        else:
            flash("Please enter a price for the menu item.", 'err_food')
            is_valid = False
        if int(food_data["food_category"]) < 1 or int(
                food_data["food_category"]) > 6:
            flash("Please select a valid menu category.", 'err_food')
            is_valid = False

        return is_valid

    @classmethod
    def add_food_item(cls, food_data):
        # print(food_data)
        new_instance_of_food = cls(name=food_data["food_name"],
                                   price=food_data["food_price"],
                                   description=food_data["food_description"],
                                   category=food_data["food_category"],
                                   created_by=session["userid"])
        db.session.add(new_instance_of_food)
        db.session.commit()
        return new_instance_of_food

    @classmethod
    def update_food_status(cls, active_food_list):
        active_list = cls.query.filter(cls.id.in_(active_food_list)).all()
        not_active_list = cls.query.filter(not_(
            cls.id.in_(active_food_list))).all()

        for item in active_list:
            item.is_active = True

        for item in not_active_list:
            item.is_active = False

        db.session.commit()

    @classmethod
    def update_food_item(cls, food_id):
        pass

    @classmethod
    def delete_food_item(cls, food_id):
        item = cls.query.get(food_id)
        db.session.delete(item)
        db.session.commit()