diff --git a/rattail_harvest/db/alembic/versions/5505c0e60d28_add_project_deleted.py b/rattail_harvest/db/alembic/versions/5505c0e60d28_add_project_deleted.py new file mode 100644 index 0000000..042663d --- /dev/null +++ b/rattail_harvest/db/alembic/versions/5505c0e60d28_add_project_deleted.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8; -*- +"""add project.deleted + +Revision ID: 5505c0e60d28 +Revises: d59ce24c2f9f +Create Date: 2022-01-30 12:08:04.338229 + +""" + +# revision identifiers, used by Alembic. +revision = '5505c0e60d28' +down_revision = 'd59ce24c2f9f' +branch_labels = None +depends_on = None + +from alembic import op +import sqlalchemy as sa +import rattail.db.types + + + +def upgrade(): + + # harvest_project + op.add_column('harvest_project', sa.Column('deleted', sa.Boolean(), nullable=True)) + op.add_column('harvest_project_version', sa.Column('deleted', sa.Boolean(), autoincrement=False, nullable=True)) + + +def downgrade(): + + # harvest_project + op.drop_column('harvest_project_version', 'deleted') + op.drop_column('harvest_project', 'deleted') diff --git a/rattail_harvest/db/model/harvest.py b/rattail_harvest/db/model/harvest.py index d7a098c..4d0e80e 100644 --- a/rattail_harvest/db/model/harvest.py +++ b/rattail_harvest/db/model/harvest.py @@ -190,6 +190,10 @@ class HarvestProject(model.Base): updated_at = sa.Column(sa.DateTime(), nullable=True) + deleted = sa.Column(sa.Boolean(), nullable=True, doc=""" + Flag indicating the record has been deleted in Harvest. + """) + def __str__(self): return self.name or '' diff --git a/rattail_harvest/importing/harvest.py b/rattail_harvest/importing/harvest.py index c686e84..cde1e1c 100644 --- a/rattail_harvest/importing/harvest.py +++ b/rattail_harvest/importing/harvest.py @@ -28,6 +28,8 @@ import datetime import decimal import logging +import sqlalchemy as sa + from rattail import importing from rattail.util import OrderedDict from rattail_harvest import importing as rattail_harvest_importing @@ -126,6 +128,22 @@ class HarvestProjectImporter(FromHarvest, rattail_harvest_importing.model.Harves Import project data from Harvest """ + @property + def supported_fields(self): + fields = list(super(HarvestProjectImporter, self).supported_fields) + + # this is for local tracking only; is not in harvest + fields.remove('deleted') + + return fields + + def cache_query(self): + model = self.model + return self.session.query(model.HarvestProject)\ + .filter(sa.or_( + model.HarvestProject.deleted == False, + model.HarvestProject.deleted == None)) + def get_host_objects(self): return self.webapi.get_projects()['projects'] @@ -168,6 +186,13 @@ class HarvestProjectImporter(FromHarvest, rattail_harvest_importing.model.Harves return data + def can_delete_object(self, project, data): + return not project.deleted + + def delete_object(self, project): + project.deleted = True + return True + class HarvestTaskImporter(FromHarvest, rattail_harvest_importing.model.HarvestTaskImporter): """