def sync_categories(self, active_only: bool): """ Get categories from fyle """ categories = self.connection.Categories.get( active_only=active_only)['data'] category_attributes = [] for category in categories: if category['name'] != category['sub_category']: category['name'] = '{0} / {1}'.format(category['name'], category['sub_category']) category_attributes.append({ 'attribute_type': 'CATEGORY', 'display_name': 'Category', 'value': category['name'], 'source_id': category['id'] }) ExpenseAttribute.bulk_create_or_update_expense_attributes( category_attributes, 'CATEGORY', self.workspace_id) return []
def sync_expense_custom_fields(self, active_only: bool): """ Get Expense Custom Fields from Fyle (Type = Select) """ expense_custom_fields = self.connection.ExpensesCustomFields.get( active=active_only)['data'] expense_custom_fields = filter(lambda field: field['type'] == 'SELECT', expense_custom_fields) for custom_field in expense_custom_fields: expense_custom_field_attributes = [] count = 1 for option in custom_field['options']: expense_custom_field_attributes.append({ 'attribute_type': custom_field['name'].upper().replace(' ', '_'), 'display_name': custom_field['name'], 'value': option, 'source_id': 'expense_custom_field.{}.{}'.format( custom_field['name'].lower(), count) }) count = count + 1 ExpenseAttribute.bulk_create_or_update_expense_attributes( expense_custom_field_attributes, custom_field['name'].upper().replace(' ', '_'), self.workspace_id) return []
def sync_employees(self): """ Get employees from fyle """ employees = self.connection.Employees.get_all() employee_attributes = [] for employee in employees: employee_attributes.append({ 'attribute_type': 'EMPLOYEE', 'display_name': 'Employee', 'value': employee['employee_email'], 'source_id': employee['id'], 'detail': { 'employee_code': employee['employee_code'], 'full_name': employee['full_name'], 'location': employee['location'], 'department': employee['department'], 'department_id': employee['department_id'], 'department_code': employee['department_code'] } }) ExpenseAttribute.bulk_create_or_update_expense_attributes( employee_attributes, 'EMPLOYEE', self.workspace_id, True) return []
def sync_projects(self): """ Get projects from fyle """ existing_db_count = self.existing_db_count('PROJECT') existing_category_count = self.connection.Projects.count()['count'] if existing_db_count == existing_category_count: return projects = self.connection.Projects.get_all() project_attributes = [] for project in projects: project_attributes.append({ 'attribute_type': 'PROJECT', 'display_name': 'Project', 'value': project['name'], 'source_id': project['id'] }) ExpenseAttribute.bulk_create_or_update_expense_attributes( project_attributes, 'PROJECT', self.workspace_id) return []
def sync_cost_centers(self): """ Get cost centers from fyle """ existing_db_count = self.existing_db_count('COST_CENTER') existing_category_count = self.connection.CostCenters.count()['count'] if existing_db_count == existing_category_count: return cost_centers = self.connection.CostCenters.get()['data'] cost_center_attributes = [] for cost_center in cost_centers: cost_center_attributes.append({ 'attribute_type': 'COST_CENTER', 'display_name': 'Cost Center', 'value': cost_center['name'], 'source_id': cost_center['id'] }) ExpenseAttribute.bulk_create_or_update_expense_attributes( cost_center_attributes, 'COST_CENTER', self.workspace_id) return []
def sync_categories(self): """ Get categories from fyle """ existing_db_count = self.existing_db_count('CATEGORY') existing_category_count = self.connection.Categories.count()['count'] if existing_db_count == existing_category_count: return categories = self.connection.Categories.get_all() category_attributes = [] for category in categories: if category['name'] != category['sub_category']: category['name'] = '{0} / {1}'.format(category['name'], category['sub_category']) category_attributes.append({ 'attribute_type': 'CATEGORY', 'display_name': 'Category', 'value': category['name'], 'source_id': category['id'] }) ExpenseAttribute.bulk_create_or_update_expense_attributes( category_attributes, 'CATEGORY', self.workspace_id) return []
def sync_projects(self, active_only: bool): """ Get projects from fyle """ projects = self.connection.Projects.get( active_only=active_only)['data'] project_attributes = [] for project in projects: project_attributes.append({ 'attribute_type': 'PROJECT', 'display_name': 'Project', 'value': project['name'], 'source_id': project['id'] }) ExpenseAttribute.bulk_create_or_update_expense_attributes( project_attributes, 'PROJECT', self.workspace_id) return []
def sync_cost_centers(self, active_only: bool): """ Get cost centers from fyle """ cost_centers = self.connection.CostCenters.get( active_only=active_only)['data'] cost_center_attributes = [] for cost_center in cost_centers: cost_center_attributes.append({ 'attribute_type': 'COST_CENTER', 'display_name': 'Cost Center', 'value': cost_center['name'], 'source_id': cost_center['id'] }) ExpenseAttribute.bulk_create_or_update_expense_attributes( cost_center_attributes, 'COST_CENTER', self.workspace_id) return []
def sync_employees(self): """ Get employees from fyle """ employees = self.connection.Employees.get_all() employee_attributes = [] for employee in employees: employee_attributes.append({ 'attribute_type': 'EMPLOYEE', 'display_name': 'Employee', 'value': employee['employee_email'], 'source_id': employee['id'] }) employee_attributes = ExpenseAttribute.bulk_upsert_expense_attributes(employee_attributes, self.workspace_id) return employee_attributes