Exemple #1
0
class Option(db.Model):
    __tablename__ = 'options'
    __table_args__ = (db.PrimaryKeyConstraint('id'), {
        'mysql_engine': 'InnoDB'
    })
    id = db.Column(db.String(36), default=_get_uuid)
    name = db.Column(db.String(64), nullable=False, unique=True)
    value = db.Column(db.String(512), nullable=False)
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    @classmethod
    def get(cls, name, value):
        opt = cls.query.filter_by(name=name).first()
        if opt is None:
            return value
        return opt.value

    @classmethod
    def set(cls, name, value):
        opt = cls.query.filter_by(name=name).first()
        if opt is None:
            opt = Option(name=name)
        opt.value = value
        db.session.add(opt)
Exemple #2
0
class Option(db.Model):
    __tablename__ = 'options'
    __table_args__ = (db.PrimaryKeyConstraint('id'), {
        'mysql_engine': 'InnoDB'
    })
    id = db.Column(db.String(36), default=_get_uuid)
    name = db.Column(db.String(64), nullable=False, unique=True)
    value = db.Column(db.String(512), nullable=False)
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    @classmethod
    def get(cls, name, value=None):
        opt = cls.query.filter(cls.name == name).first()
        return opt.value if bool(opt) else value

    @classmethod
    def set(cls, name, value):
        opt = cls.query.filter(cls.name == name).first()
        if opt is None:
            opt = Option(name=name)
        opt.value = value
        db.session.add(opt)

    def __repr__(self):
        return '<Option: id={0.id}, name={0.name}, value={0.value}>'.format(
            self)
Exemple #3
0
class AbsenceLog(db.Model):
    __tablename__ = 'absencelogs'
    __table_args__ = (db.PrimaryKeyConstraint('person_id', 'yymm', 'dd'),
                      db.ForeignKeyConstraint(['person_id', 'yymm', 'dd'], [
                          'performlogs.person_id', 'performlogs.yymm',
                          'performlogs.dd'
                      ],
                                              onupdate='CASCADE',
                                              ondelete='CASCADE'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id']),
                      db.ForeignKeyConstraint(['staff_id'], ['persons.id']),
                      db.Index('absencelogs_yymmdd', 'yymm', 'dd'), {
                          'mysql_engine': 'InnoDB'
                      })
    person_id = db.Column(db.String(36))  # 利用者ID
    yymm = db.Column(db.String(8))  # 年月
    dd = db.Column(db.Integer)  # 日
    enabled = db.Column(db.Boolean)  # 月に4回以上であればFalse
    deleted = db.Column(db.Boolean)  # 欠席加算のチェックオフになったらTrue
    contact = db.Column(db.Date)  # 連絡日
    staff_id = db.Column(db.String(36))  # 対応職員
    reason = db.Column(db.String(128))  # 欠席理由
    remarks = db.Column(db.String(128))  # 相談援助
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)
    performlog = db.relationship('PerformLog', back_populates="absencelog")

    def populate_form(self, form):
        form.populate_obj(self)

    @classmethod
    def get(cls, id, yymm, dd):
        return cls.query.filter(cls.person_id == id, cls.yymm == yymm,
                                cls.dd == dd).first()
Exemple #4
0
class WorkLog(db.Model, ModelMixInID, ModelMixInYYMMDD):
    __tablename__ = 'worklogs'
    __table_args__ = (db.PrimaryKeyConstraint('person_id', 'yymm', 'dd'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id']),
                      db.ForeignKeyConstraint(['company_id'],
                                              ['companies.id']),
                      db.Index('worklogs_yymmdd', 'yymm', 'person_id', 'dd'), {
                          'mysql_engine': 'InnoDB'
                      })
    person_id = db.Column(db.String(36))  # 利用者ID
    yymm = db.Column(db.String(8))  # 年月
    dd = db.Column(db.Integer)  # 日
    presented = db.Column(db.Boolean)  # 勤怠として有効ならtrue
    work_in = db.Column(db.String(8))  # 開始時間
    work_out = db.Column(db.String(8))  # 終了時間
    value = db.Column(db.Float)  # 勤務時間
    break_t = db.Column(db.Float)  # 休憩時間
    over_t = db.Column(db.Float)  # 残業時間
    absence = db.Column(db.Boolean)  # 欠勤
    late = db.Column(db.Boolean)  # 遅刻
    leave = db.Column(db.Boolean)  # 早退
    company_id = db.Column(db.String(36))  # 就労先企業
    remarks = db.Column(db.String(128))  # 備考
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    def __repr__(self):
        return '<WorkLog: id={0.person_id}, yymm={0.yymm}, dd={0.dd}, name={0.person.name}>'.format(
            self)

    @property
    def date(self):
        yy = int(self.yymm[:4])
        mm = int(self.yymm[4:])
        return date(yy, mm, int(self.dd))

    @property
    def person(self):
        if hasattr(self, '__person'):
            return self.__person
        self.__person = Person.query.get(self.person_id)
        return self.__person

    @property
    def url_edit(self):
        return url_for('worklogs.edit',
                       id=self.person_id,
                       yymm=self.yymm,
                       dd=self.dd)

    @property
    def url_delete(self):
        if self.presented is None:
            return url_for('worklogs.index', id=self.person_id, yymm=self.yymm)
        return url_for('worklogs.destory',
                       id=self.person_id,
                       yymm=self.yymm,
                       dd=self.dd)
Exemple #5
0
class Company(db.Model, ModelMixInID):
    __tablename__ = 'companies'
    __table_args__ = (db.PrimaryKeyConstraint('id'), {
        'mysql_engine': 'InnoDB'
    })
    id = db.Column(db.String(36), default=_get_uuid)
    enabled = db.Column(db.Boolean, nullable=False)  # 有効
    name = db.Column(db.String(64), nullable=False)  # 名前
    address = db.Column(db.String(128), nullable=False)  # 住所
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)
Exemple #6
0
class WorkLog(db.Model):
    __tablename__ = 'worklogs'
    __table_args__ = (db.PrimaryKeyConstraint('person_id', 'yymm', 'dd'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id']),
                      db.Index('worklogs_yymmdd', 'yymm', 'person_id', 'dd'), {
                          'mysql_engine': 'InnoDB'
                      })
    person_id = db.Column(db.String(36))  # 利用者ID
    yymm = db.Column(db.String(8))  # 年月
    dd = db.Column(db.Integer)  # 日
    presented = db.Column(db.Boolean)  # 勤怠として有効ならtrue
    work_in = db.Column(db.String(8))  # 開始時間
    work_out = db.Column(db.String(8))  # 終了時間
    value = db.Column(db.Float)  # 勤務時間
    break_t = db.Column(db.Float)  # 休憩時間
    over_t = db.Column(db.Float)  # 残業時間
    absence = db.Column(db.Boolean)  # 欠勤
    late = db.Column(db.Boolean)  # 遅刻
    leave = db.Column(db.Boolean)  # 早退
    remarks = db.Column(db.String(128))  # 備考
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    def populate_form(self, form):
        form.populate_obj(self)
        if (self.work_in is not None) and (len(self.work_in) == 0):
            self.work_in == None
        if (self.work_out is not None) and (len(self.work_out) == 0):
            self.work_out == None
        if (self.remarks is not None) and (len(self.remarks) == 0):
            self.remarks == None
        if bool(self.work_in) or bool(self.work_out) or (self.value
                                                         is not None):
            self.presented = True
        else:
            self.presented = False
        worklog = WorkLog.get(self.person_id, self.yymm, self.dd)
        if (worklog is not None) and (worklog.value is not None):
            self.presented = True

    @classmethod
    def get(cls, id, yymm, dd):
        return cls.query.filter(cls.person_id == id, cls.yymm == yymm,
                                cls.dd == dd).first()

    @classmethod
    def get_date(cls, id, yymmdd):
        yymm = yymmdd.strftime('%Y%m')
        return cls.query.filter(cls.person_id == id, cls.yymm == yymm,
                                cls.dd == yymmdd.day).first()

    @classmethod
    def get_yymm(cls, id, yymm):
        return cls.query.filter(cls.person_id == id, cls.yymm == yymm).all()
Exemple #7
0
class Recipient(db.Model):
    __tablename__ = 'recipients'
    __table_args__ = (db.PrimaryKeyConstraint('person_id'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id'],
                                              onupdate='CASCADE',
                                              ondelete='CASCADE'), {
                                                  'mysql_engine': 'InnoDB'
                                              })
    person_id = db.Column(db.String(36))  # 利用者ID
    number = db.Column(db.String(10), nullable=True)  # 受給者番号
    amount = db.Column(db.String(64), nullable=True)  # 契約支給量
    usestart = db.Column(db.Date, nullable=True)  # 利用開始日
    supply_in = db.Column(db.Date, nullable=True)  # 支給決定開始日
    supply_out = db.Column(db.Date, nullable=True)  # 支給決定終了日
    apply_in = db.Column(db.Date, nullable=True)  # 適用決定開始日
    apply_out = db.Column(db.Date, nullable=True)  # 適用決定終了日
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)
    person = db.relationship('Person', back_populates="recipient")

    def get_usestart(self):
        if self.usestart is None:
            return None, None
        return self.usestart, self.usestart + relativedelta(days=30)

    def is_usestart(self, d):
        usestart, usestart30d = self.get_usestart()
        if usestart is None:
            return False
        return (usestart <= d) and (d <= usestart30d)

    def is_apply_over(self, yymmdd=None):
        if (not bool(self.apply_in)) or (not bool(self.apply_out)):
            return False
        if yymmdd is None:
            yymmdd = date.today()
        yymmdd = yymmdd + relativedelta(months=1)
        return self.apply_out < yymmdd

    def is_supply_over(self, yymmdd=None):
        if (not bool(self.supply_in)) or (not bool(self.supply_out)):
            return False
        if yymmdd is None:
            yymmdd = date.today()
        yymmdd = yymmdd + relativedelta(months=1)
        return self.supply_out < yymmdd

    def populate_form(self, form):
        form.populate_obj(self)

    @classmethod
    def get(cls, id):
        return cls.query.filter(cls.person_id == id).first()
Exemple #8
0
class TimeRule(db.Model, ModelMixInID):
    __tablename__ = 'timerules'
    __table_args__ = (db.PrimaryKeyConstraint('id'), {
        'mysql_engine': 'InnoDB'
    })
    id = db.Column(db.String(36), default=_get_uuid)
    caption = db.Column(db.String(64), nullable=False)  # 名前
    rules = db.Column(db.Text)  # ルール(JSON)
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    def __repr__(self):
        return '<TimeRule: id={0.id}, caption={0.caption}>'.format(self)
Exemple #9
0
class AbsenceLog(db.Model, ModelMixInID):
    __tablename__ = 'absencelogs'
    __table_args__ = (db.PrimaryKeyConstraint('person_id', 'yymm', 'dd'),
                      db.ForeignKeyConstraint(['person_id', 'yymm', 'dd'], [
                          'performlogs.person_id', 'performlogs.yymm',
                          'performlogs.dd'
                      ],
                                              onupdate='CASCADE',
                                              ondelete='CASCADE'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id']),
                      db.ForeignKeyConstraint(['staff_id'], ['persons.id']),
                      db.Index('absencelogs_yymmdd', 'yymm', 'dd'), {
                          'mysql_engine': 'InnoDB'
                      })
    person_id = db.Column(db.String(36))  # 利用者ID
    yymm = db.Column(db.String(8))  # 年月
    dd = db.Column(db.Integer)  # 日
    contact = db.Column(db.Date)  # 連絡日
    staff_id = db.Column(db.String(36))  # 対応職員
    reason = db.Column(db.String(128))  # 欠席理由
    remarks = db.Column(db.String(128))  # 相談援助
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    @property
    def date(self):
        yy = int(self.yymm[:4])
        mm = int(self.yymm[4:])
        return date(yy, mm, self.dd)

    @property
    def person(self):
        if hasattr(self, '__person'):
            return self.__person
        self.__person = Person.query.get(self.person_id)
        return self.__person

    @property
    def staff(self):
        if hasattr(self, '__staff'):
            return self.__staff
        self.__staff = Person.query.filter(Person.id == self.staff_id).first()
        return self.__staff

    @property
    def date(self):
        yy = int(self.yymm[:4])
        mm = int(self.yymm[4:])
        return date(yy, mm, int(self.dd))
Exemple #10
0
class Recipient(db.Model, ModelMixInID):
    __tablename__ = 'recipients'
    __table_args__ = (db.PrimaryKeyConstraint('person_id'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id'],
                                              onupdate='CASCADE',
                                              ondelete='CASCADE'), {
                                                  'mysql_engine': 'InnoDB'
                                              })
    person_id = db.Column(db.String(36))  # 利用者ID
    number = db.Column(db.String(10), nullable=True)  # 受給者番号
    amount = db.Column(db.String(64), nullable=True)  # 契約支給量
    usestart = db.Column(db.Date, nullable=True)  # 利用開始日
    supply_in = db.Column(db.Date, nullable=True)  # 支給決定開始日
    supply_out = db.Column(db.Date, nullable=True)  # 支給決定終了日
    apply_in = db.Column(db.Date, nullable=True)  # 適用決定開始日
    apply_out = db.Column(db.Date, nullable=True)  # 適用決定終了日
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    def __repr__(self):
        return '<Recipient: id={id}, name="{name}">'.format(
            id=self.person_id, name=self.person.name)

    @property
    def person(self):
        if hasattr(self, '__person'):
            return self.__person
        self.__person = Person.query.get(self.person_id)
        return self.__person

    def is_supply_over(self):
        if not self.person.enabled:
            return False
        if not bool(self.supply_out):
            return False
        dead = date.today()
        dead += relativedelta(months=1)
        return self.supply_out < dead

    def is_apply_over(self):
        if not self.person.enabled:
            return False
        if not bool(self.apply_out):
            return False
        dead = date.today()
        dead += relativedelta(months=1)
        return self.apply_out < dead
Exemple #11
0
class TimeRule(db.Model):
    __tablename__ = 'timerules'
    __table_args__ = (db.PrimaryKeyConstraint('id'), {
        'mysql_engine': 'InnoDB'
    })
    id = db.Column(db.String(36), default=_get_uuid)
    caption = db.Column(db.String(64), nullable=False)  # 名前
    rules = db.Column(db.Text)  # ルール(JSON)
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    def populate_form(self, form):
        form.populate_obj(self)

    @classmethod
    def get(cls, id):
        return cls.query.filter(cls.id == id).first()
Exemple #12
0
class Person(db.Model):
    __tablename__ = 'persons'
    __table_args__ = (db.PrimaryKeyConstraint('id'), {
        'mysql_engine': 'InnoDB'
    })
    id = db.Column(db.String(36), default=_get_uuid)
    name = db.Column(db.String(64), nullable=False)  # 名前
    display = db.Column(db.String(64), nullable=True)  # 表示名
    idm = db.Column(db.String(16), unique=True)  # Ferica IDM
    enabled = db.Column(db.Boolean, nullable=False)  # 有効化
    staff = db.Column(db.Boolean, nullable=False)  # 職員
    timerule_id = db.Column(db.String(36),
                            db.ForeignKey('timerules.id'))  # タイムテーブル
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)
    recipient = db.relationship('Recipient',
                                uselist=False,
                                back_populates="person")

    def get_display(self):
        if self.display is None:
            return self.name
        return self.display

    def is_idm(self):
        if bool(self.idm):
            return self.id == cache.get('person.id')
        return True

    def populate_form(self, form):
        form.populate_obj(self)
        if not bool(self.id):
            self.id = None
        if not bool(self.display):
            self.display = None
        if not bool(self.idm):
            self.idm = None

    @classmethod
    def get(cls, id):
        return cls.query.filter(cls.id == id).first()

    @classmethod
    def get_idm(cls, idm):
        return cls.query.filter(cls.idm == idm).first()
Exemple #13
0
class Agree(db.Model, ModelMixInID):
    __tablename__ = 'agrees'
    __table_args__ = (db.PrimaryKeyConstraint('id'),
                      db.ForeignKeyConstraint(['company_id'],
                                              ['companies.id']), {
                                                  'mysql_engine': 'InnoDB'
                                              })
    id = db.Column(db.String(36), default=_get_uuid)
    company_id = db.Column(db.String(36))
    caption = db.Column(db.String(64), nullable=False)  # 表示名
    agree_in = db.Column(db.Date, nullable=False)  # 契約開始
    agree_out = db.Column(db.Date, nullable=False)  # 契約終了
    content = db.Column(db.String(128), nullable=False)  # 作業内容、作業場所
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    @property
    def company(self):
        if hasattr(self, '__company'):
            return self.__company
        self.__company = Company.query.get(self.company_id)
        return self.__company
Exemple #14
0
class Person(db.Model, ModelMixInID):
    __tablename__ = 'persons'
    __table_args__ = (db.PrimaryKeyConstraint('id'), {
        'mysql_engine': 'InnoDB'
    })
    id = db.Column(db.String(36), default=_get_uuid)
    name = db.Column(db.String(64), nullable=False)  # 名前
    display = db.Column(db.String(64), nullable=True)  # 表示名
    idm = db.Column(db.String(16), unique=True)  # Ferica IDM
    enabled = db.Column(db.Boolean, nullable=False)  # 有効化
    staff = db.Column(db.Boolean, nullable=False)  # 職員
    timerule_id = db.Column(db.String(36),
                            db.ForeignKey('timerules.id'))  # タイムテーブル
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    def __repr__(self):
        return '<Person: id={0.id}, name="{0.name}">'.format(self)

    @property
    def display_or_name(self):
        return self.display if bool(self.display) else self.name

    @property
    def recipient(self):
        if hasattr(self, '__recipient'):
            return self.__recipient
        self.__recipient = Recipient.query.filter(
            Recipient.person_id == self.id).first()
        return self.__recipient

    @property
    def timerule(self):
        if hasattr(self, '__timerule'):
            return self.__timerule
        self.__timerule = TimeRule.query.filter(
            TimeRule.id == self.timerule_id).first()
        return self.__timerule
Exemple #15
0
class PerformLog(db.Model, ModelMixInID, ModelMixInYYMMDD):
    __tablename__ = 'performlogs'
    __table_args__ = (db.PrimaryKeyConstraint('person_id', 'yymm', 'dd'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id']),
                      db.ForeignKeyConstraint(['company_id'],
                                              ['companies.id']),
                      db.Index('performlogs_yymmdd', 'yymm', 'person_id',
                               'dd'), {
                                   'mysql_engine': 'InnoDB'
                               })
    person_id = db.Column(db.String(36))  # 利用者ID
    yymm = db.Column(db.String(8))  # 年月
    dd = db.Column(db.Integer)  # 日
    enabled = db.Column(db.Boolean)  # 実績票出力対象はTrue
    presented = db.Column(db.Boolean)  # 月の日数-8を超えたらFalse
    absence = db.Column(db.Boolean, nullable=False)  # 欠席
    absence_add = db.Column(db.Boolean, nullable=False)  # 欠席加算対象
    work_in = db.Column(db.String(8))  # 開始時間
    work_out = db.Column(db.String(8))  # 終了時間
    pickup_in = db.Column(db.Boolean)  # 送迎加算(往路)
    pickup_out = db.Column(db.Boolean)  # 送迎加算(復路)
    visit = db.Column(db.Integer)  # 訪問支援特別加算(時間数)
    meal = db.Column(db.Boolean)  # 食事提供加算
    medical = db.Column(db.Integer)  # 医療連携体制加算
    experience = db.Column(db.Integer)  # 体験利用支援加算
    outside = db.Column(db.Boolean)  # 施設外支援
    company_id = db.Column(db.String(36))  # 就労先企業
    remarks = db.Column(db.String(128))  # 備考
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)

    def __repr__(self):
        return '<PerformLog: id={0.person_id}, yymm={0.yymm}, dd={0.dd}, name={0.person.name}>'.format(
            self)

    @property
    def date(self):
        yy = int(self.yymm[:4])
        mm = int(self.yymm[4:])
        return date(yy, mm, int(self.dd))

    @property
    def person(self):
        if hasattr(self, '__person'):
            return self.__person
        self.__person = Person.query.get(self.person_id)
        return self.__person

    @property
    def absencelog(self):
        if hasattr(self, '__absencelog'):
            return self.__absencelog
        self.__absencelog = AbsenceLog.query.get(
            (self.person.id, self.yymm, self.dd))

    @property
    def company(self):
        if hasattr(self, '__company'):
            return self.__company
        self.__company = Company.query.get(self.company_id) if bool(
            self.company_id) else None
        return self.__company

    @property
    def url_edit(self):
        return url_for('performlogs.edit',
                       id=self.person_id,
                       yymm=self.yymm,
                       dd=self.dd)

    @property
    def url_delete(self):
        if self.enabled is None:
            return url_for('performlogs.index',
                           id=self.person_id,
                           yymm=self.yymm)
        return url_for('performlogs.destroy',
                       id=self.person_id,
                       yymm=self.yymm,
                       dd=self.dd)
Exemple #16
0
class PerformLog(db.Model):
    __tablename__ = 'performlogs'
    __table_args__ = (db.PrimaryKeyConstraint('person_id', 'yymm', 'dd'),
                      db.ForeignKeyConstraint(['person_id'], ['persons.id']),
                      db.Index('performlogs_yymmdd', 'yymm', 'person_id',
                               'dd'), {
                                   'mysql_engine': 'InnoDB'
                               })
    person_id = db.Column(db.String(36))  # 利用者ID
    yymm = db.Column(db.String(8))  # 年月
    dd = db.Column(db.Integer)  # 日
    enabled = db.Column(db.Boolean)  # 実績票出力対象はTrue
    presented = db.Column(db.Boolean)  # 月の日数-8を超えたらFalse
    absence = db.Column(db.Boolean, nullable=False)  # 欠席
    absence_add = db.Column(db.Boolean, nullable=False)  # 欠席加算対象
    work_in = db.Column(db.String(8))  # 開始時間
    work_out = db.Column(db.String(8))  # 終了時間
    pickup_in = db.Column(db.Boolean)  # 送迎加算(往路)
    pickup_out = db.Column(db.Boolean)  # 送迎加算(復路)
    visit = db.Column(db.Integer)  # 訪問支援特別加算(時間数)
    meal = db.Column(db.Boolean)  # 食事提供加算
    medical = db.Column(db.Integer)  # 医療連携体制加算
    experience = db.Column(db.Integer)  # 体験利用支援加算
    outside = db.Column(db.Boolean)  # 施設外支援
    outemp = db.Column(db.Boolean)  # 施設外就労
    remarks = db.Column(db.String(128))  # 備考
    create_at = db.Column(db.DateTime, default=_get_now)
    update_at = db.Column(db.DateTime, onupdate=_get_now)
    absencelog = db.relationship('AbsenceLog',
                                 uselist=False,
                                 back_populates="performlog")

    def populate_form(self, form):
        form.populate_obj(self)
        if not bool(self.work_in):
            self.work_in == None
        if not bool(self.work_out):
            self.work_out == None
        if not bool(self.remarks):
            self.remarks == None

    def validate(self):
        if self.absence:
            if bool(self.work_in) or bool(self.work_out):
                raise ValidationError('開始・終了時刻が入っているため、欠席にはできません')
        if self.absence_add:
            if not self.absence:
                raise ValidationError('欠席にチェックしてください')

    def sync_to_worklog(self, worklog):
        if worklog is None:
            worklog = WorkLog(person_id=self.person_id,
                              yymm=self.yymm,
                              dd=self.dd)
        worklog.absence = self.absence
        worklog.work_in = self.work_in
        worklog.work_out = self.work_out
        if worklog.absence:
            worklog.presented = False
        elif bool(worklog.work_in) or bool(worklog.work_out) or (worklog.value
                                                                 is not None):
            worklog.presented = True
        else:
            worklog.presented = False
        db.session.add(worklog)

    def sync_from_worklog(self, workrec):
        # ICカードから入力なので欠席は取消す
        self.absence = False
        self.absence_add = False
        self.work_in = workrec.work_in
        self.work_out = workrec.work_out
        if bool(self.absencelog):
            self.absencelog.deleted = True

    @classmethod
    def get(cls, id, yymm, dd):
        return cls.query.filter(cls.person_id == id, cls.yymm == yymm,
                                cls.dd == dd).first()

    @classmethod
    def get_date(cls, id, yymmdd):
        yymm = yymmdd.strftime('%Y%m')
        return cls.query.filter(cls.person_id == id, cls.yymm == yymm,
                                cls.dd == yymmdd.day).first()

    @classmethod
    def get_yymm(cls, id, yymm):
        return cls.query.filter(cls.person_id == id, cls.yymm == yymm).all()