Add HarvestProject.deleted flag to track deletions in Harvest

set this flag instead of deleting project, so we do not lose other
info about it.  can delete manually if truly unwanted
This commit is contained in:
Lance Edgar 2022-01-30 12:14:42 -06:00
parent 259d3b0f33
commit 3883a8551f
3 changed files with 62 additions and 0 deletions

View file

@ -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')

View file

@ -190,6 +190,10 @@ class HarvestProject(model.Base):
updated_at = sa.Column(sa.DateTime(), nullable=True) 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): def __str__(self):
return self.name or '' return self.name or ''

View file

@ -28,6 +28,8 @@ import datetime
import decimal import decimal
import logging import logging
import sqlalchemy as sa
from rattail import importing from rattail import importing
from rattail.util import OrderedDict from rattail.util import OrderedDict
from rattail_harvest import importing as rattail_harvest_importing 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 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): def get_host_objects(self):
return self.webapi.get_projects()['projects'] return self.webapi.get_projects()['projects']
@ -168,6 +186,13 @@ class HarvestProjectImporter(FromHarvest, rattail_harvest_importing.model.Harves
return data 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): class HarvestTaskImporter(FromHarvest, rattail_harvest_importing.model.HarvestTaskImporter):
""" """