Esempio n. 1
0
class Stock(db.Model):
    db.__tablename__ = 'stock'
    id = db.Column(db.Integer, primary_key=True)
    product_id = db.Column(db.Integer, db.ForeignKey('product.id'))
    product = relationship('Product', back_populates="stocks")
    loc_id = db.Column(db.Integer, db.ForeignKey('location.id'))
    location = relationship('Location', back_populates="stocks")
    prod_qty = db.Column(db.Integer, nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)

    def __repr__(self):
        return f"Product('{self.id}')"
Esempio n. 2
0
class Margin(db.Model):
    db.__tablename__ = 'kit'
    id = db.Column(db.Integer, primary_key=True)
    value = db.Column(db.Integer, nullable=False)
    product_id = db.Column(db.Integer, db.ForeignKey('product.id'))
    product = db.relationship("Product", back_populates="margin")
    loc_id = db.Column(db.Integer, db.ForeignKey('location.id'))
    location = relationship('Location', back_populates="margin")

    __table_args__ = (db.UniqueConstraint('product_id', 'loc_id'), )

    def __repr__(self):
        return f"Location('{self.id}','{self.loc_name}')"
Esempio n. 3
0
class Sell(db.Model):
    db.__tablename__ = 'sell'
    id = db.Column(db.Integer, primary_key=True, nullable=False)
    qty = db.Column(db.Integer, nullable=False)
    price = db.Column(db.Integer, nullable=False)
    person_id = db.Column(db.Integer, db.ForeignKey('person.id'))
    person = relationship('Person', back_populates="sells")
    product_id = db.Column(db.Integer, db.ForeignKey('product.id'))
    product = relationship('Product')
    location_id = db.Column(db.Integer, db.ForeignKey('location.id'))
    location = relationship('Location', back_populates="sells")
    credit = db.Column(db.Boolean, nullable=False)
    date = db.Column(db.DateTime, default=datetime.utcnow)

    def __repr__(self):
        return f"Sell('{self.id}','{self.stocks.product.prod_name}','{self.stocks.location.loc_name}','{self.qty}')"
Esempio n. 4
0
class Product(db.Model):
    db.__tablename__ = 'product'
    id = db.Column(db.Integer, primary_key=True)
    price = db.Column(db.Integer)
    prod_name = db.Column(db.String(20), unique=True, nullable=False)
    loc_id = db.Column(db.Integer, db.ForeignKey('location.id'))
    location = relationship("Location", back_populates="products")
    margin = db.relationship("Margin", back_populates="product")
    kits = db.relationship("Kit", secondary=products_kits)
    stocks = db.relationship("Stock", back_populates="product")

    def __repr__(self):
        return f"Product('{self.id}','{self.prod_name}','{self.stocks[0].prod_qty}')"
Esempio n. 5
0
from flaskinventory import db
from datetime import datetime
from sqlalchemy.orm import relationship

products_kits = db.Table(
    'products_kits', db.Model.metadata,
    db.Column('product_id', db.Integer, db.ForeignKey('product.id')),
    db.Column('kit_id', db.Integer, db.ForeignKey('kit.id')))


class User(db.Model):
    """An admin user capable of viewing reports.

    :param str email: email address of user
    :param str password: encrypted password for the user

    """
    __tablename__ = 'user'
    email = db.Column(db.String, primary_key=True)
    username = db.Column(db.String)
    password = db.Column(db.String)
    authenticated = db.Column(db.Boolean, default=False)
    admin = db.Column(db.Boolean, default=False)

    def is_active(self):
        """True, as all users are active."""
        return True

    def get_id(self):
        """Return the email address to satisfy Flask-Login's requirements."""
        return self.email