Fix (more) start/end date defaults for importers, per upstream changes

This commit is contained in:
Lance Edgar 2023-09-25 13:26:58 -05:00
parent 2f21e574ae
commit e58d843ee4
3 changed files with 22 additions and 9 deletions

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -60,11 +60,15 @@ class TimeEntryImporter(ToHarvest):
Fetch existing time entries from Harvest. Fetch existing time entries from Harvest.
""" """
cache = {} cache = {}
# TODO: we try to avoid entries w/ timer still running here, # TODO: we try to avoid entries w/ timer still running here,
# but for some reason they still come back, so double-check # but for some reason they still come back, so double-check
entries = self.webapi.get_time_entries(**{'from': self.start_date, kw = {'is_running': False}
'to': self.end_date, if self.start_date:
'is_running': False}) kw['from'] = self.start_date
if self.end_date:
kw['to'] = self.end_date
entries = self.webapi.get_time_entries(**kw)
for entry in entries: for entry in entries:
# double-check here # double-check here
if not entry['is_running']: if not entry['is_running']:

View file

@ -226,8 +226,12 @@ class HarvestTimeEntryImporter(FromHarvest, rattail_harvest_importing.model.Harv
""" """
def get_host_objects(self): def get_host_objects(self):
return self.webapi.get_time_entries(**{'from': self.start_date, kw = {}
'to': self.end_date}) if self.start_date:
kw['from'] = self.start_date
if self.end_date:
kw['to'] = self.end_date
return self.webapi.get_time_entries(**kw)
def normalize_host_object(self, entry): def normalize_host_object(self, entry):
data = super(HarvestTimeEntryImporter, self).normalize_host_object(entry) data = super(HarvestTimeEntryImporter, self).normalize_host_object(entry)

View file

@ -61,6 +61,11 @@ class HarvestTaskImporter(base.FromRattail, rattail_harvest_importing.model.Harv
class HarvestTimeEntryImporter(base.FromRattail, rattail_harvest_importing.model.HarvestTimeEntryImporter): class HarvestTimeEntryImporter(base.FromRattail, rattail_harvest_importing.model.HarvestTimeEntryImporter):
def query(self): def query(self):
query = super(HarvestTimeEntryImporter, self).query() query = super().query()
return query.filter(self.model_class.spent_date >= self.start_date)\
.filter(self.model_class.spent_date <= self.end_date) if self.start_date:
query = query.filter(self.model_class.spent_date >= self.start_date)
if self.end_date:
query = query.filter(self.model_class.spent_date <= self.end_date)
return query