diff --git a/pype/ftrack/actions/ftrack_action_handler.py b/pype/ftrack/actions/ftrack_action_handler.py index d147a2630b..bfa297790e 100644 --- a/pype/ftrack/actions/ftrack_action_handler.py +++ b/pype/ftrack/actions/ftrack_action_handler.py @@ -10,7 +10,7 @@ import toml from avalon import io, lib, pipeline from avalon import session as sess import acre - +from pype.ftrack import ftrack_utils from pype import api as pype @@ -345,15 +345,36 @@ class AppAction(object): } pass - - # RUN TIMER IN FTRACK username = event['source']['user']['username'] - user = session.query('User where username is "{}"'.format(username)).one() - task = session.query('Task where id is {}'.format(entity['id'])).one() + query_user = 'User where username is "{}"'.format(username) + query_task = 'Task where id is {}'.format(entity['id']) + user = session.query(query_user).one() + task = session.query(query_task).one() self.log.info('Starting timer for task: ' + task['name']) user.start_timer(task, force=True) + # Change status of task to In progress + config = ftrack_utils.get_config_data() + + if ( + 'status_on_app_launch' in config and + 'sync_to_avalon' in config and + 'statuses_name_change' in config['sync_to_avalon'] + ): + statuses = config['sync_to_avalon']['statuses_name_change'] + if entity['status']['name'].lower() in statuses: + status_name = config['status_on_app_launch'] + + try: + query = 'Status where name is "{}"'.format(status_name) + status = session.query(query).one() + task['status'] = status + session.commit() + except Exception as e: + msg = "Status '{}' in config wasn't found on Ftrack".format(status_name) + self.log.warning(msg) + return { 'success': True, 'message': "Launching {0}".format(self.label) diff --git a/pype/ftrack/ftrack_utils.py b/pype/ftrack/ftrack_utils.py index 2177b3f8c3..74b50f45fb 100644 --- a/pype/ftrack/ftrack_utils.py +++ b/pype/ftrack/ftrack_utils.py @@ -39,13 +39,20 @@ def get_data(parent, entity, session, custom_attributes): for cust_attr in custom_attributes: key = cust_attr['key'] - if cust_attr['entity_type'].lower() in ['asset']: + if ( + cust_attr['is_hierarchical'] is True or + cust_attr['entity_type'].lower() in ['asset'] or + ( + cust_attr['entity_type'].lower() in ['show'] and + entity_type.lower() == 'project' + ) + ): data[key] = entity['custom_attributes'][key] - elif cust_attr['entity_type'].lower() in ['show'] and entity_type.lower() == 'project': - data[key] = entity['custom_attributes'][key] - - elif cust_attr['entity_type'].lower() in ['task'] and entity_type.lower() != 'project': + elif ( + cust_attr['entity_type'].lower() in ['task'] and + entity_type.lower() != 'project' + ): # Put space between capitals (e.g. 'AssetBuild' -> 'Asset Build') entity_type_full = re.sub(r"(\w)([A-Z])", r"\1 \2", entity_type) # Get object id of entity type