Initial commit, w/ cache tables and importers
This commit is contained in:
commit
66864e6f67
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
rattail_harvest.egg-info/
|
10
CHANGELOG.md
Normal file
10
CHANGELOG.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
# Changelog
|
||||
All notable changes to rattail-harvest will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [0.1.0] - ??
|
||||
### Added
|
||||
- Initial version.
|
3
MANIFEST.in
Normal file
3
MANIFEST.in
Normal file
|
@ -0,0 +1,3 @@
|
|||
include *.md
|
||||
include *.rst
|
||||
recursive-include rattail_harvest/db/alembic *.mako
|
14
README.rst
Normal file
14
README.rst
Normal file
|
@ -0,0 +1,14 @@
|
|||
|
||||
rattail-harvest
|
||||
===============
|
||||
|
||||
Rattail is a retail software framework, released under the GNU General
|
||||
Public License.
|
||||
|
||||
This package contains software interfaces for `Harvest`_.
|
||||
|
||||
.. _`Harvest`: https://www.getharvest.com/
|
||||
|
||||
Please see the `Rattail Project`_ for more information.
|
||||
|
||||
.. _`Rattail Project`: https://rattailproject.org/
|
27
rattail_harvest/__init__.py
Normal file
27
rattail_harvest/__init__.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
rattail-harvest package root
|
||||
"""
|
||||
|
||||
from ._version import __version__
|
3
rattail_harvest/_version.py
Normal file
3
rattail_harvest/_version.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
|
||||
__version__ = '0.1.0'
|
36
rattail_harvest/commands.py
Normal file
36
rattail_harvest/commands.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
rattail-harvest commands
|
||||
"""
|
||||
|
||||
from rattail import commands
|
||||
|
||||
|
||||
class ImportHarvest(commands.ImportSubcommand):
|
||||
"""
|
||||
Import data to Rattail, from Harvest API
|
||||
"""
|
||||
name = 'import-harvest'
|
||||
description = __doc__.strip()
|
||||
handler_key = 'to_rattail.from_harvest.import'
|
0
rattail_harvest/db/__init__.py
Normal file
0
rattail_harvest/db/__init__.py
Normal file
0
rattail_harvest/db/alembic/versions/.keepme
Normal file
0
rattail_harvest/db/alembic/versions/.keepme
Normal file
|
@ -0,0 +1,315 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
"""initial Harvest tables
|
||||
|
||||
Revision ID: d59ce24c2f9f
|
||||
Revises: d8b0ba4fa795
|
||||
Create Date: 2022-01-29 11:54:34.940773
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'd59ce24c2f9f'
|
||||
down_revision = None
|
||||
branch_labels = ('rattail_harvest',)
|
||||
depends_on = None
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
import rattail.db.types
|
||||
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
||||
# harvest_user
|
||||
op.create_table('harvest_user',
|
||||
sa.Column('uuid', sa.String(length=32), nullable=False),
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('first_name', sa.String(length=255), nullable=True),
|
||||
sa.Column('last_name', sa.String(length=255), nullable=True),
|
||||
sa.Column('name', sa.String(length=255), nullable=True),
|
||||
sa.Column('email', sa.String(length=255), nullable=True),
|
||||
sa.Column('telephone', sa.String(length=255), nullable=True),
|
||||
sa.Column('timezone', sa.String(length=255), nullable=True),
|
||||
sa.Column('has_access_to_all_future_projects', sa.Boolean(), nullable=True),
|
||||
sa.Column('is_contractor', sa.Boolean(), nullable=True),
|
||||
sa.Column('is_admin', sa.Boolean(), nullable=True),
|
||||
sa.Column('is_project_manager', sa.Boolean(), nullable=True),
|
||||
sa.Column('can_see_rates', sa.Boolean(), nullable=True),
|
||||
sa.Column('can_create_projects', sa.Boolean(), nullable=True),
|
||||
sa.Column('can_create_invoices', sa.Boolean(), nullable=True),
|
||||
sa.Column('is_active', sa.Boolean(), nullable=True),
|
||||
sa.Column('weekly_capacity', sa.Integer(), nullable=True),
|
||||
sa.Column('default_hourly_rate', sa.Numeric(precision=6, scale=2), nullable=True),
|
||||
sa.Column('cost_rate', sa.Numeric(precision=6, scale=2), nullable=True),
|
||||
sa.Column('avatar_url', sa.String(length=255), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('uuid'),
|
||||
sa.UniqueConstraint('id', name='harvest_user_uq_id')
|
||||
)
|
||||
op.create_table('harvest_user_version',
|
||||
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
|
||||
sa.Column('id', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('first_name', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('last_name', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('name', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('email', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('telephone', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('timezone', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('has_access_to_all_future_projects', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('is_contractor', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('is_admin', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('is_project_manager', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('can_see_rates', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('can_create_projects', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('can_create_invoices', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('is_active', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('weekly_capacity', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('default_hourly_rate', sa.Numeric(precision=6, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('cost_rate', sa.Numeric(precision=6, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('avatar_url', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
|
||||
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
|
||||
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('uuid', 'transaction_id')
|
||||
)
|
||||
op.create_index(op.f('ix_harvest_user_version_end_transaction_id'), 'harvest_user_version', ['end_transaction_id'], unique=False)
|
||||
op.create_index(op.f('ix_harvest_user_version_operation_type'), 'harvest_user_version', ['operation_type'], unique=False)
|
||||
op.create_index(op.f('ix_harvest_user_version_transaction_id'), 'harvest_user_version', ['transaction_id'], unique=False)
|
||||
|
||||
# harvest_client
|
||||
op.create_table('harvest_client',
|
||||
sa.Column('uuid', sa.String(length=32), nullable=False),
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('name', sa.String(length=255), nullable=True),
|
||||
sa.Column('is_active', sa.Boolean(), nullable=True),
|
||||
sa.Column('address', sa.String(length=255), nullable=True),
|
||||
sa.Column('currency', sa.String(length=100), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('uuid'),
|
||||
sa.UniqueConstraint('id', name='harvest_client_uq_id')
|
||||
)
|
||||
op.create_table('harvest_client_version',
|
||||
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
|
||||
sa.Column('id', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('name', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('is_active', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('address', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('currency', sa.String(length=100), autoincrement=False, nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
|
||||
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
|
||||
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('uuid', 'transaction_id')
|
||||
)
|
||||
op.create_index(op.f('ix_harvest_client_version_end_transaction_id'), 'harvest_client_version', ['end_transaction_id'], unique=False)
|
||||
op.create_index(op.f('ix_harvest_client_version_operation_type'), 'harvest_client_version', ['operation_type'], unique=False)
|
||||
op.create_index(op.f('ix_harvest_client_version_transaction_id'), 'harvest_client_version', ['transaction_id'], unique=False)
|
||||
|
||||
# harvest_project
|
||||
op.create_table('harvest_project',
|
||||
sa.Column('uuid', sa.String(length=32), nullable=False),
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('client_id', sa.Integer(), nullable=True),
|
||||
sa.Column('name', sa.String(length=255), nullable=True),
|
||||
sa.Column('code', sa.String(length=100), nullable=True),
|
||||
sa.Column('is_active', sa.Boolean(), nullable=True),
|
||||
sa.Column('is_billable', sa.Boolean(), nullable=True),
|
||||
sa.Column('is_fixed_fee', sa.Boolean(), nullable=True),
|
||||
sa.Column('bill_by', sa.String(length=100), nullable=True),
|
||||
sa.Column('hourly_rate', sa.Numeric(precision=6, scale=2), nullable=True),
|
||||
sa.Column('budget', sa.Numeric(precision=6, scale=2), nullable=True),
|
||||
sa.Column('budget_by', sa.String(length=100), nullable=True),
|
||||
sa.Column('budget_is_monthly', sa.Boolean(), nullable=True),
|
||||
sa.Column('notify_when_over_budget', sa.Boolean(), nullable=True),
|
||||
sa.Column('over_budget_notification_percentage', sa.Numeric(precision=6, scale=2), nullable=True),
|
||||
sa.Column('over_budget_notification_date', sa.Date(), nullable=True),
|
||||
sa.Column('show_budget_to_all', sa.Boolean(), nullable=True),
|
||||
sa.Column('cost_budget', sa.Numeric(precision=9, scale=2), nullable=True),
|
||||
sa.Column('cost_budget_include_expenses', sa.Boolean(), nullable=True),
|
||||
sa.Column('fee', sa.Numeric(precision=8, scale=2), nullable=True),
|
||||
sa.Column('notes', sa.Text(), nullable=True),
|
||||
sa.Column('starts_on', sa.Date(), nullable=True),
|
||||
sa.Column('ends_on', sa.Date(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['client_id'], ['harvest_client.id'], name='harvest_project_fk_client'),
|
||||
sa.PrimaryKeyConstraint('uuid'),
|
||||
sa.UniqueConstraint('id', name='harvest_project_uq_id')
|
||||
)
|
||||
op.create_table('harvest_project_version',
|
||||
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
|
||||
sa.Column('id', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('client_id', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('name', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('code', sa.String(length=100), autoincrement=False, nullable=True),
|
||||
sa.Column('is_active', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('is_billable', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('is_fixed_fee', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('bill_by', sa.String(length=100), autoincrement=False, nullable=True),
|
||||
sa.Column('hourly_rate', sa.Numeric(precision=6, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('budget', sa.Numeric(precision=6, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('budget_by', sa.String(length=100), autoincrement=False, nullable=True),
|
||||
sa.Column('budget_is_monthly', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('notify_when_over_budget', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('over_budget_notification_percentage', sa.Numeric(precision=6, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('show_budget_to_all', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('cost_budget', sa.Numeric(precision=9, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('cost_budget_include_expenses', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('fee', sa.Numeric(precision=8, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('notes', sa.Text(), autoincrement=False, nullable=True),
|
||||
sa.Column('starts_on', sa.Date(), autoincrement=False, nullable=True),
|
||||
sa.Column('ends_on', sa.Date(), autoincrement=False, nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
|
||||
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
|
||||
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('uuid', 'transaction_id')
|
||||
)
|
||||
op.create_index(op.f('ix_harvest_project_version_end_transaction_id'), 'harvest_project_version', ['end_transaction_id'], unique=False)
|
||||
op.create_index(op.f('ix_harvest_project_version_operation_type'), 'harvest_project_version', ['operation_type'], unique=False)
|
||||
op.create_index(op.f('ix_harvest_project_version_transaction_id'), 'harvest_project_version', ['transaction_id'], unique=False)
|
||||
|
||||
# harvest_task
|
||||
op.create_table('harvest_task',
|
||||
sa.Column('uuid', sa.String(length=32), nullable=False),
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('name', sa.String(length=255), nullable=True),
|
||||
sa.Column('billable_by_default', sa.Boolean(), nullable=True),
|
||||
sa.Column('default_hourly_rate', sa.Numeric(precision=6, scale=2), nullable=True),
|
||||
sa.Column('is_default', sa.Boolean(), nullable=True),
|
||||
sa.Column('is_active', sa.Boolean(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('uuid'),
|
||||
sa.UniqueConstraint('id', name='harvest_task_uq_id')
|
||||
)
|
||||
op.create_table('harvest_task_version',
|
||||
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
|
||||
sa.Column('id', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('name', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('billable_by_default', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('default_hourly_rate', sa.Numeric(precision=6, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('is_default', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('is_active', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
|
||||
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
|
||||
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('uuid', 'transaction_id')
|
||||
)
|
||||
op.create_index(op.f('ix_harvest_task_version_end_transaction_id'), 'harvest_task_version', ['end_transaction_id'], unique=False)
|
||||
op.create_index(op.f('ix_harvest_task_version_operation_type'), 'harvest_task_version', ['operation_type'], unique=False)
|
||||
op.create_index(op.f('ix_harvest_task_version_transaction_id'), 'harvest_task_version', ['transaction_id'], unique=False)
|
||||
|
||||
# harvest_time_entry
|
||||
op.create_table('harvest_time_entry',
|
||||
sa.Column('uuid', sa.String(length=32), nullable=False),
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('spent_date', sa.Date(), nullable=True),
|
||||
sa.Column('user_id', sa.Integer(), nullable=True),
|
||||
sa.Column('client_id', sa.Integer(), nullable=True),
|
||||
sa.Column('project_id', sa.Integer(), nullable=True),
|
||||
sa.Column('task_id', sa.Integer(), nullable=True),
|
||||
sa.Column('invoice_id', sa.Integer(), nullable=True),
|
||||
sa.Column('hours', sa.Numeric(precision=6, scale=2), nullable=True),
|
||||
sa.Column('notes', sa.Text(), nullable=True),
|
||||
sa.Column('is_locked', sa.Boolean(), nullable=True),
|
||||
sa.Column('locked_reason', sa.String(length=255), nullable=True),
|
||||
sa.Column('is_closed', sa.Boolean(), nullable=True),
|
||||
sa.Column('is_billed', sa.Boolean(), nullable=True),
|
||||
sa.Column('timer_started_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('started_time', sa.DateTime(), nullable=True),
|
||||
sa.Column('ended_time', sa.DateTime(), nullable=True),
|
||||
sa.Column('is_running', sa.Boolean(), nullable=True),
|
||||
sa.Column('billable', sa.Boolean(), nullable=True),
|
||||
sa.Column('budgeted', sa.Boolean(), nullable=True),
|
||||
sa.Column('billable_rate', sa.Numeric(precision=6, scale=2), nullable=True),
|
||||
sa.Column('cost_rate', sa.Numeric(precision=6, scale=2), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['client_id'], ['harvest_client.id'], name='harvest_time_entry_fk_client'),
|
||||
sa.ForeignKeyConstraint(['project_id'], ['harvest_project.id'], name='harvest_time_entry_fk_project'),
|
||||
sa.ForeignKeyConstraint(['task_id'], ['harvest_task.id'], name='harvest_time_entry_fk_task'),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['harvest_user.id'], name='harvest_time_entry_fk_user'),
|
||||
sa.PrimaryKeyConstraint('uuid'),
|
||||
sa.UniqueConstraint('id', name='harvest_time_entry_uq_id')
|
||||
)
|
||||
op.create_table('harvest_time_entry_version',
|
||||
sa.Column('uuid', sa.String(length=32), autoincrement=False, nullable=False),
|
||||
sa.Column('id', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('spent_date', sa.Date(), autoincrement=False, nullable=True),
|
||||
sa.Column('user_id', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('client_id', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('project_id', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('task_id', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('invoice_id', sa.Integer(), autoincrement=False, nullable=True),
|
||||
sa.Column('hours', sa.Numeric(precision=6, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('notes', sa.Text(), autoincrement=False, nullable=True),
|
||||
sa.Column('is_locked', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('locked_reason', sa.String(length=255), autoincrement=False, nullable=True),
|
||||
sa.Column('is_closed', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('is_billed', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('timer_started_at', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('started_time', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('ended_time', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('is_running', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('billable', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('budgeted', sa.Boolean(), autoincrement=False, nullable=True),
|
||||
sa.Column('billable_rate', sa.Numeric(precision=6, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('cost_rate', sa.Numeric(precision=6, scale=2), autoincrement=False, nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), autoincrement=False, nullable=True),
|
||||
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
|
||||
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
|
||||
sa.Column('operation_type', sa.SmallInteger(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('uuid', 'transaction_id')
|
||||
)
|
||||
op.create_index(op.f('ix_harvest_time_entry_version_end_transaction_id'), 'harvest_time_entry_version', ['end_transaction_id'], unique=False)
|
||||
op.create_index(op.f('ix_harvest_time_entry_version_operation_type'), 'harvest_time_entry_version', ['operation_type'], unique=False)
|
||||
op.create_index(op.f('ix_harvest_time_entry_version_transaction_id'), 'harvest_time_entry_version', ['transaction_id'], unique=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
# harvest_time_entry
|
||||
op.drop_index(op.f('ix_harvest_time_entry_version_transaction_id'), table_name='harvest_time_entry_version')
|
||||
op.drop_index(op.f('ix_harvest_time_entry_version_operation_type'), table_name='harvest_time_entry_version')
|
||||
op.drop_index(op.f('ix_harvest_time_entry_version_end_transaction_id'), table_name='harvest_time_entry_version')
|
||||
op.drop_table('harvest_time_entry_version')
|
||||
op.drop_table('harvest_time_entry')
|
||||
|
||||
# harvest_task
|
||||
op.drop_index(op.f('ix_harvest_task_version_transaction_id'), table_name='harvest_task_version')
|
||||
op.drop_index(op.f('ix_harvest_task_version_operation_type'), table_name='harvest_task_version')
|
||||
op.drop_index(op.f('ix_harvest_task_version_end_transaction_id'), table_name='harvest_task_version')
|
||||
op.drop_table('harvest_task_version')
|
||||
op.drop_table('harvest_task')
|
||||
|
||||
# harvest_project
|
||||
op.drop_index(op.f('ix_harvest_project_version_transaction_id'), table_name='harvest_project_version')
|
||||
op.drop_index(op.f('ix_harvest_project_version_operation_type'), table_name='harvest_project_version')
|
||||
op.drop_index(op.f('ix_harvest_project_version_end_transaction_id'), table_name='harvest_project_version')
|
||||
op.drop_table('harvest_project_version')
|
||||
op.drop_table('harvest_project')
|
||||
|
||||
# harvest_client
|
||||
op.drop_index(op.f('ix_harvest_client_version_transaction_id'), table_name='harvest_client_version')
|
||||
op.drop_index(op.f('ix_harvest_client_version_operation_type'), table_name='harvest_client_version')
|
||||
op.drop_index(op.f('ix_harvest_client_version_end_transaction_id'), table_name='harvest_client_version')
|
||||
op.drop_table('harvest_client_version')
|
||||
op.drop_table('harvest_client')
|
||||
|
||||
# harvest_user
|
||||
op.drop_index(op.f('ix_harvest_user_version_transaction_id'), table_name='harvest_user_version')
|
||||
op.drop_index(op.f('ix_harvest_user_version_operation_type'), table_name='harvest_user_version')
|
||||
op.drop_index(op.f('ix_harvest_user_version_end_transaction_id'), table_name='harvest_user_version')
|
||||
op.drop_table('harvest_user_version')
|
||||
op.drop_table('harvest_user')
|
28
rattail_harvest/db/model/__init__.py
Normal file
28
rattail_harvest/db/model/__init__.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
#
|
||||
# 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 integration data models
|
||||
"""
|
||||
|
||||
from .harvest import (HarvestUser, HarvestClient, HarvestProject,
|
||||
HarvestTask, HarvestTimeEntry)
|
301
rattail_harvest/db/model/harvest.py
Normal file
301
rattail_harvest/db/model/harvest.py
Normal file
|
@ -0,0 +1,301 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
#
|
||||
# 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
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
from rattail.db import model
|
||||
from rattail.db.util import normalize_full_name
|
||||
|
||||
|
||||
class HarvestUser(model.Base):
|
||||
"""
|
||||
Represents a user record in Harvest.
|
||||
|
||||
https://help.getharvest.com/api-v2/users-api/users/users/#the-user-object
|
||||
"""
|
||||
__tablename__ = 'harvest_user'
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('id', name='harvest_user_uq_id'),
|
||||
)
|
||||
__versioned__ = {}
|
||||
|
||||
uuid = model.uuid_column()
|
||||
|
||||
id = sa.Column(sa.Integer(), nullable=False)
|
||||
|
||||
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)
|
||||
|
||||
def __str__(self):
|
||||
return normalize_full_name(self.first_name, self.last_name)
|
||||
|
||||
|
||||
class HarvestClient(model.Base):
|
||||
"""
|
||||
Represents a client record in Harvest.
|
||||
|
||||
https://help.getharvest.com/api-v2/clients-api/clients/clients/#the-client-object
|
||||
"""
|
||||
__tablename__ = 'harvest_client'
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('id', name='harvest_client_uq_id'),
|
||||
)
|
||||
__versioned__ = {}
|
||||
|
||||
uuid = model.uuid_column()
|
||||
|
||||
id = sa.Column(sa.Integer(), nullable=False)
|
||||
|
||||
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 ''
|
||||
|
||||
|
||||
class HarvestProject(model.Base):
|
||||
"""
|
||||
Represents a project record in Harvest.
|
||||
|
||||
https://help.getharvest.com/api-v2/projects-api/projects/projects/#the-project-object
|
||||
"""
|
||||
__tablename__ = 'harvest_project'
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('id', name='harvest_project_uq_id'),
|
||||
sa.ForeignKeyConstraint(['client_id'], ['harvest_client.id'], name='harvest_project_fk_client'),
|
||||
)
|
||||
__versioned__ = {'exclude': ['over_budget_notification_date']}
|
||||
|
||||
uuid = model.uuid_column()
|
||||
|
||||
id = sa.Column(sa.Integer(), nullable=False)
|
||||
|
||||
client_id = sa.Column(sa.Integer(), nullable=True) # TODO: should not allow null?
|
||||
client = orm.relationship(HarvestClient, backref=orm.backref('projects'))
|
||||
|
||||
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)
|
||||
|
||||
def __str__(self):
|
||||
return self.name or ''
|
||||
|
||||
|
||||
class HarvestTask(model.Base):
|
||||
"""
|
||||
Represents a task record in Harvest.
|
||||
|
||||
https://help.getharvest.com/api-v2/tasks-api/tasks/tasks/#the-task-object
|
||||
"""
|
||||
__tablename__ = 'harvest_task'
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('id', name='harvest_task_uq_id'),
|
||||
)
|
||||
__versioned__ = {}
|
||||
|
||||
uuid = model.uuid_column()
|
||||
|
||||
id = sa.Column(sa.Integer(), nullable=False)
|
||||
|
||||
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 ''
|
||||
|
||||
|
||||
class HarvestTimeEntry(model.Base):
|
||||
"""
|
||||
Represents a time entry record in Harvest.
|
||||
|
||||
https://help.getharvest.com/api-v2/timesheets-api/timesheets/time-entries/#the-time-entry-object
|
||||
"""
|
||||
__tablename__ = 'harvest_time_entry'
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('id', name='harvest_time_entry_uq_id'),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['harvest_user.id'], name='harvest_time_entry_fk_user'),
|
||||
sa.ForeignKeyConstraint(['client_id'], ['harvest_client.id'], name='harvest_time_entry_fk_client'),
|
||||
sa.ForeignKeyConstraint(['project_id'], ['harvest_project.id'], name='harvest_time_entry_fk_project'),
|
||||
sa.ForeignKeyConstraint(['task_id'], ['harvest_task.id'], name='harvest_time_entry_fk_task'),
|
||||
)
|
||||
__versioned__ = {}
|
||||
model_title_plural = "Harvest Time Entries"
|
||||
|
||||
uuid = model.uuid_column()
|
||||
|
||||
id = sa.Column(sa.Integer(), nullable=False)
|
||||
|
||||
spent_date = sa.Column(sa.Date(), nullable=True)
|
||||
|
||||
user_id = sa.Column(sa.Integer(), nullable=True)
|
||||
user = orm.relationship(HarvestUser, backref=orm.backref('time_entries'))
|
||||
|
||||
client_id = sa.Column(sa.Integer(), nullable=True)
|
||||
client = orm.relationship(HarvestClient, backref=orm.backref('time_entries'))
|
||||
|
||||
project_id = sa.Column(sa.Integer(), nullable=True)
|
||||
project = orm.relationship(HarvestProject, backref=orm.backref('time_entries'))
|
||||
|
||||
task_id = sa.Column(sa.Integer(), nullable=True)
|
||||
task = orm.relationship(HarvestTask, backref=orm.backref('time_entries'))
|
||||
|
||||
invoice_id = sa.Column(sa.Integer(), nullable=True)
|
||||
|
||||
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 '')
|
0
rattail_harvest/harvest/__init__.py
Normal file
0
rattail_harvest/harvest/__init__.py
Normal file
169
rattail_harvest/harvest/webapi.py
Normal file
169
rattail_harvest/harvest/webapi.py
Normal file
|
@ -0,0 +1,169 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
#
|
||||
# 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 Web API
|
||||
"""
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
class HarvestWebAPI(object):
|
||||
"""
|
||||
Generic web API object.
|
||||
"""
|
||||
|
||||
def __init__(self, base_url=None, access_token=None, account_id=None,
|
||||
user_agent=None):
|
||||
self.base_url = base_url or 'https://api.harvestapp.com/v2/'
|
||||
self.base_url = self.base_url.rstrip('/')
|
||||
self.access_token = access_token
|
||||
self.account_id = account_id
|
||||
self.user_agent = user_agent
|
||||
if not self.user_agent:
|
||||
raise ValueError("Must provide `user_agent` when creating API instance")
|
||||
|
||||
def _request(self, request_method, api_method, params=None):
|
||||
"""
|
||||
Perform a request for the given API method, and return the response.
|
||||
"""
|
||||
api_method = api_method.lstrip('/')
|
||||
headers = {
|
||||
'Authorization': 'Bearer {}'.format(self.access_token),
|
||||
'Harvest-Account-Id': self.account_id,
|
||||
'User-Agent': self.user_agent,
|
||||
}
|
||||
if request_method == 'GET':
|
||||
response = requests.get('{}/{}'.format(self.base_url, api_method),
|
||||
headers=headers, params=params)
|
||||
elif request_method == 'POST':
|
||||
response = requests.post('{}/{}'.format(self.base_url, api_method),
|
||||
headers=headers, params=params)
|
||||
else:
|
||||
raise NotImplementedError("unknown request method: {}".format(
|
||||
request_method))
|
||||
response.raise_for_status()
|
||||
return response
|
||||
|
||||
def get(self, api_method, params=None):
|
||||
"""
|
||||
Perform a GET request for the given API method, and return the response.
|
||||
"""
|
||||
return self._request('GET', api_method, params=params)
|
||||
|
||||
def post(self, api_method, params=None):
|
||||
"""
|
||||
Perform a POST request for the given API method, and return the response.
|
||||
"""
|
||||
return self._request('POST', api_method, params=params)
|
||||
|
||||
def get_company(self):
|
||||
"""
|
||||
Retrieves the company for the currently authenticated user.
|
||||
|
||||
https://help.getharvest.com/api-v2/company-api/company/company/#retrieve-a-company
|
||||
"""
|
||||
response = self.get('/company')
|
||||
return response.json()
|
||||
|
||||
def get_users(self, **kwargs):
|
||||
"""
|
||||
Retrieve all users. Any kwargs are passed on as URL query
|
||||
string parameters.
|
||||
|
||||
https://help.getharvest.com/api-v2/users-api/users/users/#list-all-users
|
||||
"""
|
||||
response = self.get('/users', params=kwargs)
|
||||
return response.json()
|
||||
|
||||
def get_clients(self, **kwargs):
|
||||
"""
|
||||
Retrieve all clients. Any kwargs are passed on as URL query string
|
||||
parameters.
|
||||
|
||||
https://help.getharvest.com/api-v2/clients-api/clients/clients/#list-all-clients
|
||||
"""
|
||||
response = self.get('/clients', params=kwargs)
|
||||
return response.json()
|
||||
|
||||
def get_projects(self, **kwargs):
|
||||
"""
|
||||
Retrieve all projects. Any kwargs are passed on as URL query string
|
||||
parameters.
|
||||
|
||||
https://help.getharvest.com/api-v2/projects-api/projects/projects/#list-all-projects
|
||||
"""
|
||||
response = self.get('/projects', params=kwargs)
|
||||
return response.json()
|
||||
|
||||
def get_tasks(self, **kwargs):
|
||||
"""
|
||||
Retrieve all tasks. Any kwargs are passed on as URL query string
|
||||
parameters.
|
||||
|
||||
https://help.getharvest.com/api-v2/tasks-api/tasks/tasks/#list-all-tasks
|
||||
"""
|
||||
response = self.get('/tasks', params=kwargs)
|
||||
return response.json()
|
||||
|
||||
def get_time_entries(self, **kwargs):
|
||||
"""
|
||||
List all time entries. Any kwargs are passed on as URL query string
|
||||
parameters.
|
||||
|
||||
https://help.getharvest.com/api-v2/timesheets-api/timesheets/time-entries/#list-all-time-entries
|
||||
"""
|
||||
response = self.get('/time_entries', params=kwargs)
|
||||
data = response.json()
|
||||
entries = data['time_entries']
|
||||
while data['next_page']:
|
||||
|
||||
kw = dict(kwargs)
|
||||
kw['page'] = data['next_page']
|
||||
response = self.get('/time_entries', params=kw)
|
||||
data = response.json()
|
||||
entries.extend(data['time_entries'])
|
||||
|
||||
return entries
|
||||
|
||||
def get_time_entry(self, time_entry_id):
|
||||
"""
|
||||
Retrieve a time entry.
|
||||
|
||||
https://help.getharvest.com/api-v2/timesheets-api/timesheets/time-entries/#retrieve-a-time-entry
|
||||
"""
|
||||
response = self.get('/time_entries/{}'.format(time_entry_id))
|
||||
return response.json()
|
||||
|
||||
def put_time_entry(self, **kwargs):
|
||||
"""
|
||||
Create a new time entry. All kwargs are passed on as POST parameters.
|
||||
|
||||
https://help.getharvest.com/api-v2/timesheets-api/timesheets/time-entries/#create-a-time-entry-via-duration
|
||||
https://help.getharvest.com/api-v2/timesheets-api/timesheets/time-entries/#create-a-time-entry-via-start-and-end-time
|
||||
"""
|
||||
required = ('project_id', 'task_id', 'spent_date')
|
||||
for key in required:
|
||||
if key not in kwargs or not kwargs[key]:
|
||||
raise ValueError("must provide all of: {}".format(', '.join(required)))
|
||||
response = self.post('/time_entries', params=kwargs)
|
||||
return response.json()
|
27
rattail_harvest/importing/__init__.py
Normal file
27
rattail_harvest/importing/__init__.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
rattail-harvest importing
|
||||
"""
|
||||
|
||||
from . import model
|
227
rattail_harvest/importing/harvest.py
Normal file
227
rattail_harvest/importing/harvest.py
Normal file
|
@ -0,0 +1,227 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
#
|
||||
# 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 -> Rattail "cache" data import
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import decimal
|
||||
import logging
|
||||
|
||||
from rattail import importing
|
||||
from rattail.util import OrderedDict
|
||||
from rattail_harvest import importing as rattail_harvest_importing
|
||||
from rattail_harvest.harvest.webapi import HarvestWebAPI
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FromHarvestToRattail(importing.ToRattailHandler):
|
||||
"""
|
||||
Import handler for data coming from the Harvest API
|
||||
"""
|
||||
host_key = 'harvest'
|
||||
host_title = "Harvest (API)"
|
||||
generic_host_title = "Harvest (API)"
|
||||
|
||||
def get_importers(self):
|
||||
importers = OrderedDict()
|
||||
importers['HarvestUser'] = HarvestUserImporter
|
||||
importers['HarvestClient'] = HarvestClientImporter
|
||||
importers['HarvestProject'] = HarvestProjectImporter
|
||||
importers['HarvestTask'] = HarvestTaskImporter
|
||||
importers['HarvestTimeEntry'] = HarvestTimeEntryImporter
|
||||
return importers
|
||||
|
||||
|
||||
class FromHarvest(importing.Importer):
|
||||
"""
|
||||
Base class for all Harvest importers
|
||||
"""
|
||||
key = 'id'
|
||||
|
||||
@property
|
||||
def supported_fields(self):
|
||||
fields = list(super(FromHarvest, self).supported_fields)
|
||||
fields.remove('uuid')
|
||||
return fields
|
||||
|
||||
def setup(self):
|
||||
super(FromHarvest, self).setup()
|
||||
|
||||
access_token = self.config.require('harvest', 'api.access_token')
|
||||
account_id = self.config.require('harvest', 'api.account_id')
|
||||
user_agent = self.config.require('harvest', 'api.user_agent')
|
||||
self.webapi = HarvestWebAPI(access_token=access_token,
|
||||
account_id=account_id,
|
||||
user_agent=user_agent)
|
||||
|
||||
def time_from_harvest(self, value):
|
||||
# all harvest times appear to come as UTC, so no conversion needed
|
||||
value = datetime.datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ')
|
||||
return value
|
||||
|
||||
def normalize_host_object(self, obj):
|
||||
data = dict(obj)
|
||||
|
||||
if 'created_at' in self.fields:
|
||||
data['created_at'] = self.time_from_harvest(data['created_at'])
|
||||
|
||||
if 'updated_at' in self.fields:
|
||||
data['updated_at'] = self.time_from_harvest(data['updated_at'])
|
||||
|
||||
return data
|
||||
|
||||
|
||||
class HarvestUserImporter(FromHarvest, rattail_harvest_importing.model.HarvestUserImporter):
|
||||
"""
|
||||
Import user data from Harvest
|
||||
"""
|
||||
|
||||
@property
|
||||
def supported_fields(self):
|
||||
fields = list(super(HarvestUserImporter, self).supported_fields)
|
||||
|
||||
# this used to be in harvest i thought, but is no longer?
|
||||
fields.remove('name')
|
||||
|
||||
return fields
|
||||
|
||||
def get_host_objects(self):
|
||||
return self.webapi.get_users()['users']
|
||||
|
||||
|
||||
class HarvestClientImporter(FromHarvest, rattail_harvest_importing.model.HarvestClientImporter):
|
||||
"""
|
||||
Import client data from Harvest
|
||||
"""
|
||||
|
||||
def get_host_objects(self):
|
||||
return self.webapi.get_clients()['clients']
|
||||
|
||||
|
||||
class HarvestProjectImporter(FromHarvest, rattail_harvest_importing.model.HarvestProjectImporter):
|
||||
"""
|
||||
Import project data from Harvest
|
||||
"""
|
||||
|
||||
def get_host_objects(self):
|
||||
return self.webapi.get_projects()['projects']
|
||||
|
||||
def normalize_host_object(self, project):
|
||||
data = super(HarvestProjectImporter, self).normalize_host_object(project)
|
||||
if not data:
|
||||
return
|
||||
|
||||
data['client_id'] = project['client']['id']
|
||||
|
||||
# cost_budget
|
||||
cost_budget = data['cost_budget']
|
||||
if cost_budget is not None:
|
||||
cost_budget = decimal.Decimal('{:0.2f}'.format(cost_budget))
|
||||
data['cost_budget'] = cost_budget
|
||||
|
||||
# fee
|
||||
fee = data['fee']
|
||||
if fee is not None:
|
||||
fee = decimal.Decimal('{:0.2f}'.format(fee))
|
||||
data['fee'] = fee
|
||||
|
||||
# starts_on
|
||||
starts_on = data['starts_on']
|
||||
if starts_on:
|
||||
starts_on = datetime.datetime.strptime(starts_on, '%Y-%m-%d')
|
||||
data['starts_on'] = starts_on.date()
|
||||
|
||||
# ends_on
|
||||
ends_on = data['ends_on']
|
||||
if ends_on:
|
||||
ends_on = datetime.datetime.strptime(ends_on, '%Y-%m-%d')
|
||||
data['ends_on'] = ends_on.date()
|
||||
|
||||
# over_budget_notification_date
|
||||
date = data['over_budget_notification_date']
|
||||
if date:
|
||||
date = datetime.datetime.strptime(date, '%Y-%m-%d')
|
||||
data['over_budget_notification_date'] = date.date()
|
||||
|
||||
return data
|
||||
|
||||
|
||||
class HarvestTaskImporter(FromHarvest, rattail_harvest_importing.model.HarvestTaskImporter):
|
||||
"""
|
||||
Import task data from Harvest
|
||||
"""
|
||||
|
||||
def get_host_objects(self):
|
||||
return self.webapi.get_tasks()['tasks']
|
||||
|
||||
|
||||
class HarvestTimeEntryImporter(FromHarvest, rattail_harvest_importing.model.HarvestTimeEntryImporter):
|
||||
"""
|
||||
Import time entry data from Harvest
|
||||
"""
|
||||
|
||||
def setup(self):
|
||||
super(HarvestTimeEntryImporter, self).setup()
|
||||
model = self.model
|
||||
|
||||
self.harvest_projects_by_id = self.app.cache_model(self.session,
|
||||
model.HarvestProject,
|
||||
key='id')
|
||||
|
||||
def get_host_objects(self):
|
||||
return self.webapi.get_time_entries(**{'from': self.start_date,
|
||||
'to': self.end_date})
|
||||
|
||||
def normalize_host_object(self, entry):
|
||||
data = super(HarvestTimeEntryImporter, self).normalize_host_object(entry)
|
||||
if not data:
|
||||
return
|
||||
|
||||
data['user_id'] = entry['user']['id']
|
||||
data['client_id'] = entry['client']['id']
|
||||
|
||||
data['project_id'] = entry['project']['id']
|
||||
if data['project_id'] not in self.harvest_projects_by_id:
|
||||
log.warning("time entry references non-existent project id %s: %s",
|
||||
data['project_id'], entry)
|
||||
data['project_id'] = None
|
||||
|
||||
data['task_id'] = entry['task']['id']
|
||||
data['invoice_id'] = entry['invoice']['id'] if entry['invoice'] else None
|
||||
|
||||
# spent_date
|
||||
spent_date = data['spent_date']
|
||||
if spent_date:
|
||||
spent_date = datetime.datetime.strptime(spent_date, '%Y-%m-%d')
|
||||
data['spent_date'] = spent_date.date()
|
||||
|
||||
# hours
|
||||
hours = data['hours']
|
||||
if hours is not None:
|
||||
hours = decimal.Decimal('{:0.2f}'.format(hours))
|
||||
data['hours'] = hours
|
||||
|
||||
return data
|
53
rattail_harvest/importing/model.py
Normal file
53
rattail_harvest/importing/model.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
rattail-harvest model importers
|
||||
"""
|
||||
|
||||
from rattail.importing.model import ToRattail
|
||||
from rattail_harvest.db import model
|
||||
|
||||
|
||||
##############################
|
||||
# harvest cache models
|
||||
##############################
|
||||
|
||||
class HarvestUserImporter(ToRattail):
|
||||
model_class = model.HarvestUser
|
||||
|
||||
class HarvestClientImporter(ToRattail):
|
||||
model_class = model.HarvestClient
|
||||
|
||||
class HarvestProjectImporter(ToRattail):
|
||||
model_class = model.HarvestProject
|
||||
|
||||
class HarvestTaskImporter(ToRattail):
|
||||
model_class = model.HarvestTask
|
||||
|
||||
class HarvestTimeEntryImporter(ToRattail):
|
||||
model_class = model.HarvestTimeEntry
|
||||
|
||||
def cache_query(self):
|
||||
query = super(HarvestTimeEntryImporter, self).cache_query()
|
||||
return query.filter(self.model_class.spent_date >= self.start_date)\
|
||||
.filter(self.model_class.spent_date <= self.end_date)
|
106
setup.py
Normal file
106
setup.py
Normal file
|
@ -0,0 +1,106 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
rattail-harvest setup script
|
||||
"""
|
||||
|
||||
import os
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
|
||||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
exec(open(os.path.join(here, 'rattail_harvest', '_version.py')).read())
|
||||
README = open(os.path.join(here, 'README.rst')).read()
|
||||
|
||||
|
||||
requires = [
|
||||
#
|
||||
# Version numbers within comments below have specific meanings.
|
||||
# Basically the 'low' value is a "soft low," and 'high' a "soft high."
|
||||
# In other words:
|
||||
#
|
||||
# If either a 'low' or 'high' value exists, the primary point to be
|
||||
# made about the value is that it represents the most current (stable)
|
||||
# version available for the package (assuming typical public access
|
||||
# methods) whenever this project was started and/or documented.
|
||||
# Therefore:
|
||||
#
|
||||
# If a 'low' version is present, you should know that attempts to use
|
||||
# versions of the package significantly older than the 'low' version
|
||||
# may not yield happy results. (A "hard" high limit may or may not be
|
||||
# indicated by a true version requirement.)
|
||||
#
|
||||
# Similarly, if a 'high' version is present, and especially if this
|
||||
# project has laid dormant for a while, you may need to refactor a bit
|
||||
# when attempting to support a more recent version of the package. (A
|
||||
# "hard" low limit should be indicated by a true version requirement
|
||||
# when a 'high' version is present.)
|
||||
#
|
||||
# In any case, developers and other users are encouraged to play
|
||||
# outside the lines with regard to these soft limits. If bugs are
|
||||
# encountered then they should be filed as such.
|
||||
#
|
||||
# package # low high
|
||||
|
||||
'invoke', # 1.5.0
|
||||
'rattail[db]', # 0.9.246
|
||||
]
|
||||
|
||||
|
||||
setup(
|
||||
name = "rattail-harvest",
|
||||
version = __version__,
|
||||
author = "Lance Edgar",
|
||||
author_email = "lance@edbob.org",
|
||||
url = "https://rattailproject.org/",
|
||||
description = "Rattail integration package for Harvest",
|
||||
long_description = README,
|
||||
|
||||
classifiers = [
|
||||
'Development Status :: 3 - Alpha',
|
||||
'Environment :: Console',
|
||||
'Intended Audience :: Developers',
|
||||
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
|
||||
'Natural Language :: English',
|
||||
'Operating System :: OS Independent',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Topic :: Office/Business',
|
||||
'Topic :: Software Development :: Libraries :: Python Modules',
|
||||
],
|
||||
|
||||
install_requires = requires,
|
||||
packages = find_packages(),
|
||||
include_package_data = True,
|
||||
|
||||
entry_points = {
|
||||
|
||||
'rattail.commands': [
|
||||
'import-harvest = rattail_harvest.commands:ImportHarvest',
|
||||
],
|
||||
|
||||
'rattail.importing': [
|
||||
'to_rattail.from_harvest.import = rattail_harvest.importing.harvest:FromHarvestToRattail',
|
||||
],
|
||||
},
|
||||
)
|
48
tasks.py
Normal file
48
tasks.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2022 Lance Edgar
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
################################################################################
|
||||
"""
|
||||
Tasks for rattail-harvest
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from invoke import task
|
||||
|
||||
|
||||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
exec(open(os.path.join(here, 'rattail_harvest', '_version.py')).read())
|
||||
|
||||
|
||||
@task
|
||||
def release(ctx):
|
||||
"""
|
||||
Release a new version of rattail-harvest
|
||||
"""
|
||||
# rebuild local tar.gz file for distribution
|
||||
shutil.rmtree('rattail_harvest.egg-info')
|
||||
ctx.run('python setup.py sdist --formats=gztar')
|
||||
|
||||
# upload to public PyPI
|
||||
filename = 'rattail-harvest-{}.tar.gz'.format(__version__)
|
||||
ctx.run('twine upload dist/{}'.format(filename))
|
Loading…
Reference in a new issue