Skip to content

Commit

Permalink
Merge pull request #433 from KerkhoffTechnologies/3526-keep-closed-co…
Browse files Browse the repository at this point in the history
…nnectwise-projects-for-a-period-after-closing

[ISSUE-3526] Keep closed ConnectWise projects for a period after closing
  • Loading branch information
kti-sam authored May 30, 2024
2 parents 46cf159 + 80824e1 commit 1791ffe
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion djconnectwise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
VERSION = (1, 5, 5, 'final')
VERSION = (1, 5, 6, 'final')

# pragma: no cover
if VERSION[-1] != "final":
Expand Down
41 changes: 35 additions & 6 deletions djconnectwise/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,8 @@ def parent_object_ids(self):


class ProjectSynchronizer(CreateRecordMixin,
UpdateRecordMixin, Synchronizer):
UpdateRecordMixin,
Synchronizer):
client_class = api.ProjectAPIClient
model_class = models.ProjectTracker
related_meta = {
Expand Down Expand Up @@ -2183,12 +2184,40 @@ def __init__(self, *args, **kwargs):
# Only sync projects in non-closed statuses. We could simply use
# closedFlag=False but API versions before 2019.5 don't support the
# closedFlag field and we need to support those versions for now.
self.api_conditions = ['status/id in ({})'.format(
','.join(
str(i.id) for
i in models.ProjectStatus.objects.filter(closed_flag=False)
project_conditions = [
'status/id in ({})'.format(
','.join(
str(status.id)
for status in models.ProjectStatus.objects.filter(
closed_flag=False
)
)
)
]
request_settings = DjconnectwiseSettings().get_settings()
keep_closed_days = request_settings.get('keep_closed_ticket_days')
if keep_closed_days:
project_conditions = self.format_conditions(
keep_closed_days, project_conditions, request_settings
)
)]

self.api_conditions = project_conditions

def format_conditions(self, keep_closed_days,
project_conditions, request_settings):
closed_date = \
timezone.now() - timezone.timedelta(days=keep_closed_days)
condition = 'lastUpdated>[{}]'.format(closed_date)

keep_closed_board_ids = \
request_settings.get('keep_closed_status_board_ids')
if keep_closed_board_ids:
condition = '{} and board/id in ({})'.format(
condition, keep_closed_board_ids
)

project_conditions.append(condition)
return project_conditions

def _assign_field_data(self, instance, json_data):
actual_start = json_data.get('actualStart')
Expand Down

0 comments on commit 1791ffe

Please sign in to comment.