Exemplo n.º 1
0
class Item(DB.Model):
    """Model for item entity
    @todo #15:30min Continue the implementation. Items must have their own
     management pages to list, create, edit, and delete them. On the index
     page, you should be able to sort and filter for each column.
    """
    __tablename__ = "items"

    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    name = DB.Column(DB.String, nullable=False)
    stock_date = DB.Column(DB.DateTime, nullable=False)
    comment = DB.Column(DB.String, nullable=True)
    company_id = DB.Column(DB.Integer, DB.ForeignKey("companies.id"))
    created_on = DB.Column(DB.DateTime,
                           default=datetime.utcnow,
                           nullable=False)
    updated_on = DB.Column(DB.DateTime, onupdate=datetime.utcnow)
    company = DB.relationship("Company", back_populates="items")
    employee_id = DB.Column(DB.Integer, DB.ForeignKey("employees.id"))
    empolyee = DB.relationship("Employee", back_populates="items")
    history = DB.relationship("ItemHistory", back_populates="item")

    def assign(self, employee):
        """ Assing the item to an employee
        @todo #142:30min Continue implememntation of assining.
         Update the old ItemHistory record if current employee_id in not null.
         ItemHistory should have the needed functions to continue this.
        """
        self.employee_id = employee.id
        item_history = ItemHistory(employee_id=self.employee_id,
                                   item_id=self.id)

    def __repr__(self):
        """Return object information - String"""
        return "<Item %r>" % self.name
Exemplo n.º 2
0
class Comment(TimestampsMixin, DB.Model):
    """Model for comment business entity"""
    __tablename__ = "comments"

    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)

    employee_id = DB.Column(DB.Integer, DB.ForeignKey("employees.id"))
    body = DB.Column(DB.String, nullable=False)
    date = DB.Column(DB.DateTime, nullable=False)
    employee = DB.Column(DB.Integer, DB.ForeignKey("employees.id"))

    def __repr__(self):
        return "<Comment %r>" % self.description
Exemplo n.º 3
0
class SchemeCondition(DB.Model):
    """
    @todo #43:30min Continue implementation as in #18. The possibility to
     create, edit, delete the conditions shall be made inside SchemeType page
     for consistency.
    """
    __tablename__ = "scheme_conditions"

    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    scheme_type_id = DB.Column(DB.Integer, DB.ForeignKey("scheme_types.id"))

    value = DB.Column(DB.String, unique=True, nullable=False)
    priority = DB.Column(DB.Integer, nullable=False)
    start_time = DB.Column(DB.DateTime,
                           default=datetime.utcnow,
                           nullable=False)
    end_time = DB.Column(DB.DateTime, nullable=False)
    weekdays = DB.relationship("WeekDay",
                               order_by=WeekDay.id,
                               back_populates="scheme_condition")
    monthdays = DB.relationship("MonthDay",
                                order_by=MonthDay.id,
                                back_populates="scheme_condition")
    dates = DB.relationship("Date",
                            order_by=Date.id,
                            back_populates="scheme_condition")

    scheme_type = DB.relationship("SchemeType", back_populates="conditions")

    @validate_required("value", "priority", "start_time", "end_time")
    def __init__(self, **kwargs):
        super(SchemeCondition, self).__init__(**kwargs)

    def __repr__(self):
        return "<SchemeCondition %r>" % self.id
Exemplo n.º 4
0
class Role(DB.Model):
    """Settings model for Role."""

    __tablename__ = "roles"

    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    """
        @todo #397:30m After adding role type, name may make confusion.
         It should be deleted and all code using it should use type instead.
         Also, Alter the views of the roles to match the changes.
    """
    name = DB.Column(DB.String, unique=True)
    works_on_shifts = DB.Column(DB.Boolean)
    company_id = DB.Column(DB.Integer, DB.ForeignKey("companies.id"))
    role_type = DB.Column(ChoiceType(RoleType, impl=DB.String()), unique=True)

    company = DB.relationship("Company", back_populates="roles")
    employees = DB.relationship("Employee", back_populates="role")

    def __repr__(self):
        return "<Role %r>" % self.role_type

    def is_master_or_intern(self):
        """ check if the type is master or intern """
        return self.role_type in (
            RoleType.Master,
            RoleType.Intern,
        )

    def is_director(self):
        """ check if type is director """
        return self.role_type == RoleType.Director
Exemplo n.º 5
0
class Role(DB.Model):
    """Settings model for Role."""

    __tablename__ = "roles"

    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    name = DB.Column(DB.String, unique=True)
    works_on_shifts = DB.Column(DB.Boolean)
    company_id = DB.Column(DB.Integer, DB.ForeignKey("companies.id"))

    company = DB.relationship("Company", back_populates="roles")
    employees = DB.relationship("Employee", back_populates="role")

    def __repr__(self):
        return "<Role %r>" % self.name

    def is_master_or_intern(self):
        """
        @todo #341:30m Need to find nice way to understand what is role of this
         instance. May be it's better to introduce `type` field with choices.
        """
        return self.name in (
            "Master",
            "Intern",
        )

    def is_director(self):
        return self.name == "Director"
Exemplo n.º 6
0
class SchemeCondition(DB.Model):
    __tablename__ = "scheme_conditions"

    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    scheme_type_id = DB.Column(DB.Integer, DB.ForeignKey("scheme_types.id"))

    value = DB.Column(DB.String, unique=True, nullable=False)
    priority = DB.Column(DB.Integer, nullable=False)
    start_time = DB.Column(DB.DateTime,
                           default=datetime.utcnow,
                           nullable=False)
    end_time = DB.Column(DB.DateTime, nullable=False)
    weekdays = DB.relationship("WeekDay",
                               order_by=WeekDay.id,
                               back_populates="scheme_condition")
    monthdays = DB.relationship("MonthDay",
                                order_by=MonthDay.id,
                                back_populates="scheme_condition")
    dates = DB.relationship("Date",
                            order_by=Date.id,
                            back_populates="scheme_condition")

    scheme_type = DB.relationship("SchemeType", back_populates="conditions")

    def __repr__(self):
        return "<SchemeCondition %r>" % self.id
Exemplo n.º 7
0
class Item(DB.Model):
    """Model for item entity
    """
    __tablename__ = "items"

    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    name = DB.Column(DB.String, nullable=False)
    stock_date = DB.Column(DB.DateTime, nullable=False)
    comment = DB.Column(DB.String, nullable=True)
    company_id = DB.Column(DB.Integer, DB.ForeignKey("companies.id"))
    created_on = DB.Column(DB.DateTime, default=datetime.utcnow, nullable=False)
    updated_on = DB.Column(DB.DateTime, onupdate=datetime.utcnow)
    company = DB.relationship("Company", back_populates="items")
    employee_id = DB.Column(DB.Integer, DB.ForeignKey("employees.id"))
    empolyee = DB.relationship("Employee", back_populates="items")
    history = DB.relationship("ItemHistory", back_populates="item")

    @validate_required("name", "stock_date", "comment", "created_on")
    def __init__(self, **kwargs):
        super(Item, self).__init__(**kwargs)

    def assign(self, employee):
        """ Assigning the item to an employee """
        self.employee_id = employee.id
        for hist_item in self.history:
            if not hist_item.end_time:
                hist_item.end_time = datetime.utcnow
                break
        self.history.append(
            ItemHistory(
                employee_id=self.employee_id,
                item_id=self.id,
                start_time=datetime.utcnow
            )
        )

    def item_history(self):
        """ Returns item history

        """
        return self.history

    def __repr__(self):
        """Return object information - String"""
        return "<Item %r>" % self.name
Exemplo n.º 8
0
class ItemHistory(DB.Model):
    """Model for item assigning history
    """
    __tablename__ = "itemsHistory"

    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    start_time = DB.Column(DB.DateTime,
                           default=datetime.utcnow,
                           nullable=False)
    end_time = DB.Column(DB.DateTime)
    employee_id = DB.Column(DB.Integer, DB.ForeignKey("employees.id"))
    employee = DB.relationship("Employee", back_populates="history")
    item_id = DB.Column(DB.Integer, DB.ForeignKey("items.id"))
    item = DB.relationship("Item", back_populates="history")

    def __repr__(self):
        """Return object information - String"""
        return f"<Item {self.id}>"
Exemplo n.º 9
0
class Item(DB.Model):
    """Model for item entity
    """
    __tablename__ = "items"

    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    name = DB.Column(DB.String, nullable=False)
    stock_date = DB.Column(DB.DateTime, nullable=False)
    comment = DB.Column(DB.String, nullable=True)
    company_id = DB.Column(DB.Integer, DB.ForeignKey("companies.id"))
    created_on = DB.Column(DB.DateTime,
                           default=datetime.utcnow,
                           nullable=False)
    updated_on = DB.Column(DB.DateTime, onupdate=datetime.utcnow)
    company = DB.relationship("Company", back_populates="items")
    employee_id = DB.Column(DB.Integer, DB.ForeignKey("employees.id"))
    empolyee = DB.relationship("Employee", back_populates="items")
    history = DB.relationship("ItemHistory", back_populates="item")

    @validate_required("name", "stock_date", "comment", "created_on")
    def __init__(self, **kwargs):
        super(Item, self).__init__(**kwargs)

    def assign(self, employee):
        """ Assigning the item to an employee """
        self.employee_id = employee.id
        item_history = ItemHistory(employee_id=self.employee_id,
                                   item_id=self.id)

    def item_history(self):
        """ Returns item history
        @todo #217:30min Implement function to return item history.
         history() function must return item assignement history, a list of
         ItemHistory with all the items assignment history. Then remove skip
         annotation from test_items.test_item_assign
        """
        pass

    def __repr__(self):
        """Return object information - String"""
        return "<Item %r>" % self.name
Exemplo n.º 10
0
class WeekDay(DB.Model):
    __tablename__ = "weekdays"
    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    weekday = DB.Column(DB.Integer, unique=True, nullable=False)
    scheme_condition_id = DB.Column(DB.Integer,
                                    DB.ForeignKey("scheme_conditions.id"))

    scheme_condition = DB.relationship("SchemeCondition",
                                       back_populates="weekdays")

    def __repr__(self):
        return "<Weekday %r>" % self.id
Exemplo n.º 11
0
class Role(DB.Model):
    """Settings model for Role."""

    __tablename__ = "roles"

    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    name = DB.Column(DB.String, unique=True)
    works_on_shifts = DB.Column(DB.Boolean)
    company_id = DB.Column(DB.Integer, DB.ForeignKey("companies.id"))

    company = DB.relationship("Company", back_populates="roles")

    def __repr__(self):
        return "<Role %r>" % self.name
Exemplo n.º 12
0
class Item(DB.Model):
    """Model for item entity
    """
    __tablename__ = "items"

    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    name = DB.Column(DB.String, nullable=False)
    stock_date = DB.Column(DB.DateTime, nullable=False)
    comment = DB.Column(DB.String, nullable=True)
    company_id = DB.Column(DB.Integer, DB.ForeignKey("companies.id"))
    created_on = DB.Column(DB.DateTime,
                           default=datetime.utcnow,
                           nullable=False)
    updated_on = DB.Column(DB.DateTime, onupdate=datetime.utcnow)
    company = DB.relationship("Company", back_populates="items")
    employee_id = DB.Column(DB.Integer, DB.ForeignKey("employees.id"))
    empolyee = DB.relationship("Employee", back_populates="items")
    history = DB.relationship("ItemHistory", back_populates="item")

    @validate_required("name", "stock_date", "comment", "created_on")
    def __init__(self, **kwargs):
        super(Item, self).__init__(**kwargs)

    def assign(self, employee):
        """ Assing the item to an employee
        @todo #142:30min Continue implememntation of assining.
         Update the old ItemHistory record if current employee_id in not null.
         ItemHistory should have the needed functions to continue this.
        """
        self.employee_id = employee.id
        item_history = ItemHistory(employee_id=self.employee_id,
                                   item_id=self.id)

    def __repr__(self):
        """Return object information - String"""
        return "<Item %r>" % self.name
Exemplo n.º 13
0
class Date(DB.Model):
    __tablename__ = "dates"
    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    date = DB.Column(DB.DateTime, unique=True, nullable=False)
    scheme_condition_id = DB.Column(DB.Integer,
                                    DB.ForeignKey("scheme_conditions.id"))

    scheme_condition = DB.relationship("SchemeCondition",
                                       back_populates="dates")

    @validate_required("date")
    def __init__(self, **kwargs):
        super(Date, self).__init__(**kwargs)

    def __repr__(self):
        return "<Date %r>" % self.id
Exemplo n.º 14
0
class WeekDay(DB.Model):
    """ WeekDay model"""
    __tablename__ = "weekdays"
    id = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
    weekday = DB.Column(DB.Integer, unique=True, nullable=False)
    scheme_condition_id = DB.Column(DB.Integer,
                                    DB.ForeignKey("scheme_conditions.id"))

    scheme_condition = DB.relationship("SchemeCondition",
                                       back_populates="weekdays")

    @validate_required("weekday")
    def __init__(self, **kwargs):
        super(WeekDay, self).__init__(**kwargs)

    def __repr__(self):
        return "<Weekday %r>" % self.id