diff --git a/rattail_harvest/harvest/importing/model.py b/rattail_harvest/harvest/importing/model.py index d445def..3a874c5 100644 --- a/rattail_harvest/harvest/importing/model.py +++ b/rattail_harvest/harvest/importing/model.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2022 Lance Edgar +# Copyright © 2010-2023 Lance Edgar # # This file is part of Rattail. # @@ -60,11 +60,15 @@ class TimeEntryImporter(ToHarvest): Fetch existing time entries from Harvest. """ cache = {} + # TODO: we try to avoid entries w/ timer still running here, # but for some reason they still come back, so double-check - entries = self.webapi.get_time_entries(**{'from': self.start_date, - 'to': self.end_date, - 'is_running': False}) + kw = {'is_running': False} + if self.start_date: + 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: # double-check here if not entry['is_running']: diff --git a/rattail_harvest/importing/harvest.py b/rattail_harvest/importing/harvest.py index 348c24b..1e706a2 100644 --- a/rattail_harvest/importing/harvest.py +++ b/rattail_harvest/importing/harvest.py @@ -226,8 +226,12 @@ class HarvestTimeEntryImporter(FromHarvest, rattail_harvest_importing.model.Harv """ def get_host_objects(self): - return self.webapi.get_time_entries(**{'from': self.start_date, - 'to': self.end_date}) + kw = {} + 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): data = super(HarvestTimeEntryImporter, self).normalize_host_object(entry) diff --git a/rattail_harvest/importing/rattail.py b/rattail_harvest/importing/rattail.py index 54ce310..d61f3d8 100644 --- a/rattail_harvest/importing/rattail.py +++ b/rattail_harvest/importing/rattail.py @@ -61,6 +61,11 @@ class HarvestTaskImporter(base.FromRattail, rattail_harvest_importing.model.Harv class HarvestTimeEntryImporter(base.FromRattail, rattail_harvest_importing.model.HarvestTimeEntryImporter): def query(self): - query = super(HarvestTimeEntryImporter, self).query() - return query.filter(self.model_class.spent_date >= self.start_date)\ - .filter(self.model_class.spent_date <= self.end_date) + query = super().query() + + 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