Allow import of harvest time entries w/ missing project
This commit is contained in:
parent
2a0c9bf015
commit
259d3b0f33
2 changed files with 62 additions and 15 deletions
|
@ -183,14 +183,6 @@ class HarvestTimeEntryImporter(FromHarvest, rattail_harvest_importing.model.Harv
|
|||
Import time entry data from Harvest
|
||||
"""
|
||||
|
||||
def setup(self):
|
||||
super(HarvestTimeEntryImporter, self).setup()
|
||||
model = self.model
|
||||
|
||||
self.harvest_projects_by_id = self.app.cache_model(self.session,
|
||||
model.HarvestProject,
|
||||
key='id')
|
||||
|
||||
def get_host_objects(self):
|
||||
return self.webapi.get_time_entries(**{'from': self.start_date,
|
||||
'to': self.end_date})
|
||||
|
@ -202,16 +194,20 @@ class HarvestTimeEntryImporter(FromHarvest, rattail_harvest_importing.model.Harv
|
|||
|
||||
data['user_id'] = entry['user']['id']
|
||||
data['client_id'] = entry['client']['id']
|
||||
|
||||
data['project_id'] = entry['project']['id']
|
||||
if data['project_id'] not in self.harvest_projects_by_id:
|
||||
log.warning("time entry references non-existent project id %s: %s",
|
||||
data['project_id'], entry)
|
||||
data['project_id'] = None
|
||||
|
||||
data['task_id'] = entry['task']['id']
|
||||
data['invoice_id'] = entry['invoice']['id'] if entry['invoice'] else None
|
||||
|
||||
# project_id
|
||||
if 'project_id' in self.fields:
|
||||
data['project_id'] = entry['project']['id']
|
||||
project = self.get_harvest_project(data['project_id'])
|
||||
if not project:
|
||||
logger = log.warning if self.warn_for_unknown_project else log.debug
|
||||
logger("time entry references non-existent project id %s: %s",
|
||||
data['project_id'], entry)
|
||||
if not self.auto_create_unknown_project:
|
||||
data['project_id'] = None
|
||||
|
||||
# spent_date
|
||||
spent_date = data['spent_date']
|
||||
if spent_date:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue