Esempio n. 1
0
class User(BaseModel, db.Model):
    """
        Etablishment Table
    """
    __tablename__ = 'user'

    first_name = db.Column(db.String(60), nullable=False)
    last_name = db.Column(db.String(60), nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(120), nullable=False)


    # Foreing key to Entity table
    etablishment_id = db.Column(db.Integer, db.ForeignKey('etablishment.id'), nullable=False)


    def __repr__(self):
        return '<Etablishment: ID : {} - Name : {}>'.format(self.id, self.name)
Esempio n. 2
0
class Recipe(BaseModel, db.Model):
    """
        Product Table
    """
    __tablename__ = 'recipe'

    name = db.Column(db.String(120), nullable=False)

    # Foreing key to Entity table
    etablishment_id = db.Column(db.Integer, db.ForeignKey('etablishment.id'), nullable=False)

    def __repr__(self):
        return '<Recipe: ID : {} - Name : {}>'.format(self.id, self.name)

    @classmethod
    def find_by(cls, *args, order_by='name', **kwargs):
        return cls.query.filter_by(deleted_at=None, **kwargs).order_by(order_by).all()

    @classmethod
    def list_recipe_with_volume_and_nb_product(cls, etablishment_id, order_by):
        return db.session.query(
            Recipe.id.label('id'),
            Recipe.name.label('name'),
            db.func.sum(RecipeProduct.quantity).label('quantity'),
            db.func.count(RecipeProduct.product_id).label('nb_product')
        ).filter_by(
            etablishment_id=etablishment_id,
            deleted_at=None
        ).join(
            RecipeProduct, RecipeProduct.recipe_id == Recipe.id
        ).group_by(
            Recipe.id
        ).order_by(
            Recipe.name
        ).all()

    @classmethod
    def search(cls, *args, etablishment_id, name, **kwargs):
        return db.session.query(
            Recipe.id.label('id'),
            Recipe.name.label('name'),
            db.func.sum(RecipeProduct.quantity).label('quantity'),
            db.func.count(RecipeProduct.product_id).label('nb_product')
        ).filter(
            cls.etablishment_id==etablishment_id,
            cls.name.like('%{}%'.format(name)),
            cls.deleted_at==None
        ).join(
            RecipeProduct, RecipeProduct.recipe_id == Recipe.id
        ).group_by(
            Recipe.id
        ).order_by(
            Recipe.name
        ).all()
Esempio n. 3
0
class Entity(BaseModel, db.Model):
    """
        Entity Table
    """

    __tablename__ = 'entity'

    name = db.Column(db.String(60), nullable=False)

    def __repr__(self):
        return '<Entity: ID : {} - Name : {}>'.format(self.id, self.name)
Esempio n. 4
0
class Etablishment(BaseModel, db.Model):
    """
        Etablishment Table
    """
    __tablename__ = 'etablishment'

    name = db.Column(db.String(60), nullable=False)

    # Foreing key to Entity table
    entity_id = db.Column(db.Integer,
                          db.ForeignKey('entity.id'),
                          nullable=False)

    def __repr__(self):
        return '<Etablishment: ID : {} - Name : {}>'.format(self.id, self.name)
Esempio n. 5
0
class StockEntry(BaseModel, db.Model):
    """
        Etablishment Table
    """
    __tablename__ = 'stock_entry'

    provider = db.Column(db.String(120), nullable=False)
    amount_ht = db.Column(db.Float(), nullable=False)
    amount_ttc = db.Column(db.Float(), nullable=False)
    bill_status = db.Column(db.Enum(BillStatus))
    path_to_bill = db.Column(db.Text(), nullable=True)
    pay_date = db.Column(db.DateTime())

    # Foreing key to Entity table
    etablishment_id = db.Column(db.Integer, db.ForeignKey('etablishment.id'), nullable=False)


    def __repr__(self):
        return '<Stock Entry: ID : {} - Name : {}>'.format(self.id, self.name)

    @classmethod
    def find_by(cls, *args, order_by='name', **kwargs):
        return StockEntry.query.filter_by(**kwargs).order_by(order_by).all()
Esempio n. 6
0
class Product(BaseModel, db.Model):
    """
        Product Table
    """
    __tablename__ = 'product'


    name = db.Column(db.String(120), nullable=False)
    type = db.Column(db.Enum(ProductType))
    liquid = db.Column(db.Boolean(), default=True)
    volume = db.Column(db.Integer())

    # Foreing key to Entity table
    etablishment_id = db.Column(db.Integer, db.ForeignKey('etablishment.id'), nullable=False)


    def __repr__(self):
        return '<Product: ID : {} - Name : {}>'.format(self.id, self.name)

    @classmethod
    def find_by(cls, *args, order_by='name', **kwargs):
        return Product.query.filter_by(**kwargs).order_by(order_by).all()

    @classmethod
    def search(cls, *args, etablishment_id, name='', type=[ProductType.type_1, ProductType.type_2], liquid=None):
        if len(type) == 0:
            type=[ProductType.type_1, ProductType.type_2]
        q_set = db.session.query(
            Product
        ).filter(
            cls.etablishment_id==etablishment_id,
            cls.name.like('%{}%'.format(name)),
            cls.type.in_((type)),
            # cls.liquid==liquid if liquid != None else cls.liquid == True or cls.liquid = False,
            cls.deleted_at==None
        ).order_by('name')
        return q_set.all()