Fix (more) start/end date defaults for importers, per upstream changes
This commit is contained in:
parent
2f21e574ae
commit
e58d843ee4
|
@ -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']:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue