2022-01-29 14:50:25 -06:00
|
|
|
# -*- coding: utf-8; -*-
|
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Rattail -- Retail Software Framework
|
2023-08-08 11:05:15 -05:00
|
|
|
# Copyright © 2010-2023 Lance Edgar
|
2022-01-29 14:50:25 -06:00
|
|
|
#
|
|
|
|
# This file is part of Rattail.
|
|
|
|
#
|
|
|
|
# Rattail is free software: you can redistribute it and/or modify it under the
|
|
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
# version.
|
|
|
|
#
|
|
|
|
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
"""
|
|
|
|
Harvest "cache" data models
|
|
|
|
"""
|
|
|
|
|
2023-10-04 15:54:52 -05:00
|
|
|
import warnings
|
|
|
|
|
2022-01-29 14:50:25 -06:00
|
|
|
import sqlalchemy as sa
|
|
|
|
from sqlalchemy import orm
|
|
|
|
|
|
|
|
from rattail.db import model
|
|
|
|
from rattail.db.util import normalize_full_name
|
|
|
|
|
|
|
|
|
2023-10-04 15:54:52 -05:00
|
|
|
class HarvestCacheUser(model.Base):
|
2022-01-29 14:50:25 -06:00
|
|
|
"""
|
|
|
|
Represents a user record in Harvest.
|
|
|
|
|
|
|
|
https://help.getharvest.com/api-v2/users-api/users/users/#the-user-object
|
|
|
|
"""
|
2023-10-04 15:54:52 -05:00
|
|
|
__tablename__ = 'harvest_cache_user'
|
2022-01-29 14:50:25 -06:00
|
|
|
__table_args__ = (
|
2023-10-04 15:54:52 -05:00
|
|
|
sa.ForeignKeyConstraint(['person_uuid'], ['person.uuid'],
|
|
|
|
name='harvest_cache_user_fk_person'),
|
|
|
|
sa.UniqueConstraint('id', name='harvest_cache_user_uq_id'),
|
2022-01-29 14:50:25 -06:00
|
|
|
)
|
|
|
|
__versioned__ = {}
|
|
|
|
|
|
|
|
uuid = model.uuid_column()
|
|
|
|
|
2023-08-08 11:05:15 -05:00
|
|
|
id = sa.Column(sa.BigInteger(), nullable=False)
|
2022-01-29 14:50:25 -06:00
|
|
|
|
|
|
|
first_name = sa.Column(sa.String(length=255), nullable=True)
|
|
|
|
|
|
|
|
last_name = sa.Column(sa.String(length=255), nullable=True)
|
|
|
|
|
|
|
|
name = sa.Column(sa.String(length=255), nullable=True)
|
|
|
|
|
|
|
|
email = sa.Column(sa.String(length=255), nullable=True)
|
|
|
|
|
|
|
|
telephone = sa.Column(sa.String(length=255), nullable=True)
|
|
|
|
|
|
|
|
timezone = sa.Column(sa.String(length=255), nullable=True)
|
|
|
|
|
|
|
|
has_access_to_all_future_projects = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
is_contractor = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
is_admin = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
is_project_manager = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
can_see_rates = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
can_create_projects = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
can_create_invoices = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
is_active = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
weekly_capacity = sa.Column(sa.Integer(), nullable=True)
|
|
|
|
|
|
|
|
default_hourly_rate = sa.Column(sa.Numeric(precision=6, scale=2), nullable=True)
|
|
|
|
|
|
|
|
cost_rate = sa.Column(sa.Numeric(precision=6, scale=2), nullable=True)
|
|
|
|
|
|
|
|
# TODO
|
|
|
|
# roles = sa.Column(sa.Text(), nullable=True)
|
|
|
|
|
|
|
|
avatar_url = sa.Column(sa.String(length=255), nullable=True)
|
|
|
|
|
|
|
|
created_at = sa.Column(sa.DateTime(), nullable=True)
|
|
|
|
|
|
|
|
updated_at = sa.Column(sa.DateTime(), nullable=True)
|
|
|
|
|
2022-01-30 17:40:19 -06:00
|
|
|
person_uuid = sa.Column(sa.String(length=32), nullable=True)
|
|
|
|
person = orm.relationship(
|
|
|
|
model.Person,
|
|
|
|
doc="""
|
|
|
|
Reference to the person associated with this Harvest user.
|
|
|
|
""",
|
|
|
|
backref=orm.backref(
|
|
|
|
'harvest_users',
|
|
|
|
doc="""
|
|
|
|
List of all Harvest user accounts for the person.
|
|
|
|
""")
|
|
|
|
)
|
|
|
|
|
2022-01-29 14:50:25 -06:00
|
|
|
def __str__(self):
|
|
|
|
return normalize_full_name(self.first_name, self.last_name)
|
|
|
|
|
|
|
|
|
2023-10-04 15:54:52 -05:00
|
|
|
class HarvestUser(HarvestCacheUser):
|
|
|
|
""" DEPRECATED """
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
warnings.warn("HarvestUser class is deprecated; "
|
|
|
|
"please use HarvestCacheUser instead",
|
|
|
|
DeprecationWarning, stacklevel=2)
|
|
|
|
|
|
|
|
|
|
|
|
class HarvestCacheClient(model.Base):
|
2022-01-29 14:50:25 -06:00
|
|
|
"""
|
|
|
|
Represents a client record in Harvest.
|
|
|
|
|
|
|
|
https://help.getharvest.com/api-v2/clients-api/clients/clients/#the-client-object
|
|
|
|
"""
|
2023-10-04 15:54:52 -05:00
|
|
|
__tablename__ = 'harvest_cache_client'
|
2022-01-29 14:50:25 -06:00
|
|
|
__table_args__ = (
|
2023-10-04 15:54:52 -05:00
|
|
|
sa.UniqueConstraint('id', name='harvest_cache_client_uq_id'),
|
2022-01-29 14:50:25 -06:00
|
|
|
)
|
|
|
|
__versioned__ = {}
|
|
|
|
|
|
|
|
uuid = model.uuid_column()
|
|
|
|
|
2023-08-08 11:05:15 -05:00
|
|
|
id = sa.Column(sa.BigInteger(), nullable=False)
|
2022-01-29 14:50:25 -06:00
|
|
|
|
|
|
|
name = sa.Column(sa.String(length=255), nullable=True)
|
|
|
|
|
|
|
|
is_active = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
address = sa.Column(sa.String(length=255), nullable=True)
|
|
|
|
|
|
|
|
currency = sa.Column(sa.String(length=100), nullable=True)
|
|
|
|
|
|
|
|
created_at = sa.Column(sa.DateTime(), nullable=True)
|
|
|
|
|
|
|
|
updated_at = sa.Column(sa.DateTime(), nullable=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name or ''
|
|
|
|
|
|
|
|
|
2023-10-04 15:54:52 -05:00
|
|
|
class HarvestClient(HarvestCacheClient):
|
|
|
|
""" DEPRECATED """
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
warnings.warn("HarvestClient class is deprecated; "
|
|
|
|
"please use HarvestCacheClient instead",
|
|
|
|
DeprecationWarning, stacklevel=2)
|
|
|
|
|
|
|
|
|
|
|
|
class HarvestCacheProject(model.Base):
|
2022-01-29 14:50:25 -06:00
|
|
|
"""
|
|
|
|
Represents a project record in Harvest.
|
|
|
|
|
|
|
|
https://help.getharvest.com/api-v2/projects-api/projects/projects/#the-project-object
|
|
|
|
"""
|
2023-10-04 15:54:52 -05:00
|
|
|
__tablename__ = 'harvest_cache_project'
|
2022-01-29 14:50:25 -06:00
|
|
|
__table_args__ = (
|
2023-10-04 15:54:52 -05:00
|
|
|
sa.UniqueConstraint('id', name='harvest_cache_project_uq_id'),
|
|
|
|
sa.ForeignKeyConstraint(['client_id'], ['harvest_cache_client.id'],
|
|
|
|
name='harvest_cache_project_fk_client'),
|
2022-01-29 14:50:25 -06:00
|
|
|
)
|
|
|
|
__versioned__ = {'exclude': ['over_budget_notification_date']}
|
|
|
|
|
|
|
|
uuid = model.uuid_column()
|
|
|
|
|
2023-08-08 11:05:15 -05:00
|
|
|
id = sa.Column(sa.BigInteger(), nullable=False)
|
2022-01-29 14:50:25 -06:00
|
|
|
|
2023-08-08 11:05:15 -05:00
|
|
|
client_id = sa.Column(sa.BigInteger(), nullable=True) # TODO: should not allow null?
|
2023-10-04 15:54:52 -05:00
|
|
|
client = orm.relationship(HarvestCacheClient, backref=orm.backref('projects'))
|
2022-01-29 14:50:25 -06:00
|
|
|
|
|
|
|
name = sa.Column(sa.String(length=255), nullable=True)
|
|
|
|
|
|
|
|
code = sa.Column(sa.String(length=100), nullable=True)
|
|
|
|
|
|
|
|
is_active = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
is_billable = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
is_fixed_fee = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
bill_by = sa.Column(sa.String(length=100), nullable=True)
|
|
|
|
|
|
|
|
hourly_rate = sa.Column(sa.Numeric(precision=6, scale=2), nullable=True)
|
|
|
|
|
|
|
|
budget = sa.Column(sa.Numeric(precision=6, scale=2), nullable=True)
|
|
|
|
|
|
|
|
budget_by = sa.Column(sa.String(length=100), nullable=True)
|
|
|
|
|
|
|
|
budget_is_monthly = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
notify_when_over_budget = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
over_budget_notification_percentage = sa.Column(sa.Numeric(precision=6, scale=2), nullable=True)
|
|
|
|
|
|
|
|
over_budget_notification_date = sa.Column(sa.Date(), nullable=True)
|
|
|
|
|
|
|
|
show_budget_to_all = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
cost_budget = sa.Column(sa.Numeric(precision=9, scale=2), nullable=True)
|
|
|
|
|
|
|
|
cost_budget_include_expenses = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
fee = sa.Column(sa.Numeric(precision=8, scale=2), nullable=True)
|
|
|
|
|
|
|
|
notes = sa.Column(sa.Text(), nullable=True)
|
|
|
|
|
|
|
|
starts_on = sa.Column(sa.Date(), nullable=True)
|
|
|
|
|
|
|
|
ends_on = sa.Column(sa.Date(), nullable=True)
|
|
|
|
|
|
|
|
created_at = sa.Column(sa.DateTime(), nullable=True)
|
|
|
|
|
|
|
|
updated_at = sa.Column(sa.DateTime(), nullable=True)
|
|
|
|
|
2022-01-30 12:14:42 -06:00
|
|
|
deleted = sa.Column(sa.Boolean(), nullable=True, doc="""
|
|
|
|
Flag indicating the record has been deleted in Harvest.
|
|
|
|
""")
|
|
|
|
|
2022-01-29 14:50:25 -06:00
|
|
|
def __str__(self):
|
|
|
|
return self.name or ''
|
|
|
|
|
|
|
|
|
2023-10-04 15:54:52 -05:00
|
|
|
class HarvestProject(HarvestCacheProject):
|
|
|
|
""" DEPRECATED """
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
warnings.warn("HarvestProject class is deprecated; "
|
|
|
|
"please use HarvestCacheProject instead",
|
|
|
|
DeprecationWarning, stacklevel=2)
|
|
|
|
|
|
|
|
|
|
|
|
class HarvestCacheTask(model.Base):
|
2022-01-29 14:50:25 -06:00
|
|
|
"""
|
|
|
|
Represents a task record in Harvest.
|
|
|
|
|
|
|
|
https://help.getharvest.com/api-v2/tasks-api/tasks/tasks/#the-task-object
|
|
|
|
"""
|
2023-10-04 15:54:52 -05:00
|
|
|
__tablename__ = 'harvest_cache_task'
|
2022-01-29 14:50:25 -06:00
|
|
|
__table_args__ = (
|
2023-10-04 15:54:52 -05:00
|
|
|
sa.UniqueConstraint('id', name='harvest_cache_task_uq_id'),
|
2022-01-29 14:50:25 -06:00
|
|
|
)
|
|
|
|
__versioned__ = {}
|
|
|
|
|
|
|
|
uuid = model.uuid_column()
|
|
|
|
|
2023-08-08 11:05:15 -05:00
|
|
|
id = sa.Column(sa.BigInteger(), nullable=False)
|
2022-01-29 14:50:25 -06:00
|
|
|
|
|
|
|
name = sa.Column(sa.String(length=255), nullable=True)
|
|
|
|
|
|
|
|
billable_by_default = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
default_hourly_rate = sa.Column(sa.Numeric(precision=6, scale=2), nullable=True)
|
|
|
|
|
|
|
|
is_default = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
is_active = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
created_at = sa.Column(sa.DateTime(), nullable=True)
|
|
|
|
|
|
|
|
updated_at = sa.Column(sa.DateTime(), nullable=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name or ''
|
|
|
|
|
|
|
|
|
2023-10-04 15:54:52 -05:00
|
|
|
class HarvestTask(HarvestCacheTask):
|
|
|
|
""" DEPRECATED """
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
warnings.warn("HarvestTask class is deprecated; "
|
|
|
|
"please use HarvestCacheTask instead",
|
|
|
|
DeprecationWarning, stacklevel=2)
|
|
|
|
|
|
|
|
|
|
|
|
class HarvestCacheTimeEntry(model.Base):
|
2022-01-29 14:50:25 -06:00
|
|
|
"""
|
|
|
|
Represents a time entry record in Harvest.
|
|
|
|
|
|
|
|
https://help.getharvest.com/api-v2/timesheets-api/timesheets/time-entries/#the-time-entry-object
|
|
|
|
"""
|
2023-10-04 15:54:52 -05:00
|
|
|
__tablename__ = 'harvest_cache_time_entry'
|
2022-01-29 14:50:25 -06:00
|
|
|
__table_args__ = (
|
2023-10-04 15:54:52 -05:00
|
|
|
sa.UniqueConstraint('id', name='harvest_cache_time_entry_uq_id'),
|
|
|
|
sa.ForeignKeyConstraint(['user_id'], ['harvest_cache_user.id'],
|
|
|
|
name='harvest_cache_time_entry_fk_user'),
|
|
|
|
sa.ForeignKeyConstraint(['client_id'], ['harvest_cache_client.id'],
|
|
|
|
name='harvest_cache_time_entry_fk_client'),
|
|
|
|
sa.ForeignKeyConstraint(['project_id'], ['harvest_cache_project.id'],
|
|
|
|
name='harvest_cache_time_entry_fk_project'),
|
|
|
|
sa.ForeignKeyConstraint(['task_id'], ['harvest_cache_task.id'],
|
|
|
|
name='harvest_cache_time_entry_fk_task'),
|
2022-01-29 14:50:25 -06:00
|
|
|
)
|
|
|
|
__versioned__ = {}
|
|
|
|
model_title_plural = "Harvest Time Entries"
|
|
|
|
|
|
|
|
uuid = model.uuid_column()
|
|
|
|
|
2023-08-08 11:05:15 -05:00
|
|
|
id = sa.Column(sa.BigInteger(), nullable=False)
|
2022-01-29 14:50:25 -06:00
|
|
|
|
|
|
|
spent_date = sa.Column(sa.Date(), nullable=True)
|
|
|
|
|
2023-08-08 11:05:15 -05:00
|
|
|
user_id = sa.Column(sa.BigInteger(), nullable=True)
|
2023-10-04 15:54:52 -05:00
|
|
|
user = orm.relationship(HarvestCacheUser, backref=orm.backref('time_entries'))
|
2022-01-29 14:50:25 -06:00
|
|
|
|
2023-08-08 11:05:15 -05:00
|
|
|
client_id = sa.Column(sa.BigInteger(), nullable=True)
|
2023-10-04 15:54:52 -05:00
|
|
|
client = orm.relationship(HarvestCacheClient, backref=orm.backref('time_entries'))
|
2022-01-29 14:50:25 -06:00
|
|
|
|
2023-08-08 11:05:15 -05:00
|
|
|
project_id = sa.Column(sa.BigInteger(), nullable=True)
|
2023-10-04 15:54:52 -05:00
|
|
|
project = orm.relationship(HarvestCacheProject, backref=orm.backref('time_entries'))
|
2022-01-29 14:50:25 -06:00
|
|
|
|
2023-08-08 11:05:15 -05:00
|
|
|
task_id = sa.Column(sa.BigInteger(), nullable=True)
|
2023-10-04 15:54:52 -05:00
|
|
|
task = orm.relationship(HarvestCacheTask, backref=orm.backref('time_entries'))
|
2022-01-29 14:50:25 -06:00
|
|
|
|
2023-08-08 11:05:15 -05:00
|
|
|
invoice_id = sa.Column(sa.BigInteger(), nullable=True)
|
2022-01-29 14:50:25 -06:00
|
|
|
|
|
|
|
hours = sa.Column(sa.Numeric(precision=6, scale=2), nullable=True)
|
|
|
|
|
|
|
|
notes = sa.Column(sa.Text(), nullable=True)
|
|
|
|
|
|
|
|
is_locked = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
locked_reason = sa.Column(sa.String(length=255), nullable=True)
|
|
|
|
|
|
|
|
is_closed = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
is_billed = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
timer_started_at = sa.Column(sa.DateTime(), nullable=True)
|
|
|
|
|
|
|
|
started_time = sa.Column(sa.DateTime(), nullable=True)
|
|
|
|
|
|
|
|
ended_time = sa.Column(sa.DateTime(), nullable=True)
|
|
|
|
|
|
|
|
is_running = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
billable = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
budgeted = sa.Column(sa.Boolean(), nullable=True)
|
|
|
|
|
|
|
|
billable_rate = sa.Column(sa.Numeric(precision=6, scale=2), nullable=True)
|
|
|
|
|
|
|
|
cost_rate = sa.Column(sa.Numeric(precision=6, scale=2), nullable=True)
|
|
|
|
|
|
|
|
created_at = sa.Column(sa.DateTime(), nullable=True)
|
|
|
|
|
|
|
|
updated_at = sa.Column(sa.DateTime(), nullable=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(self.spent_date or '')
|
2023-10-04 15:54:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
class HarvestTimeEntry(HarvestCacheTimeEntry):
|
|
|
|
""" DEPRECATED """
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
warnings.warn("HarvestTimeEntry class is deprecated; "
|
|
|
|
"please use HarvestCacheTimeEntry instead",
|
|
|
|
DeprecationWarning, stacklevel=2)
|