def get(self, country_id: UUID): try: result = super(CountryStore, self).runProc('common.countries_get', [country_id]) if len(result) > 0: return result[0] else: raise StoreException('No country found with specified Id') except Exception as e: log.error(e) raise StoreException('Unable to retrieve country')
def get(self, client_id: UUID, project_id: UUID) -> dict: try: result = super(ProjectStore, self).runProc('work.project_get', [client_id, project_id]) if len(result) > 0: return result[0] else: raise StoreException('Project not found') except Exception as e: log.error(e) raise StoreException('Unable to retrieve project')
def get(self, client_id: UUID, dimension: str, uom_id: int) -> {}: try: result = super(UOMStore, self).runProc('common.uom_get', [client_id, dimension, uom_id]) if len(result) > 0: return result[0] else: raise StoreException('Unable to find unit of measure') except Exception as e: log.error(e) raise StoreException('Unable to retrieve unit of measure')
def get(self, client_id: UUID, facility_id: UUID): try: result = super(FacilityStore, self).runProc('inventory.facility_get', [client_id, facility_id]) if len(result) > 0: return result[0] else: raise StoreException('Facility not found') except Exception as e: log.error(e) raise StoreException('Unable to retrieve facility')
def get(self, client_id: UUID, account_id: UUID) -> {}: try: result = super(AccountsStore, self).runProc('accounting.account_get', [client_id, account_id]) if len(result) > 0: return result[0] else: raise StoreException('Missing account') except Exception as e: log.error(e) raise StoreException('Unable to retrieve account')
def get(self, client_id: UUID, location_id: UUID) -> {}: try: result = super(LocationStore, self).runProc('inventory.location_get', [client_id, location_id]) if len(result) > 0: return result[0] else: raise StoreException('No location found') except Exception as e: log.error(e) raise StoreException('Unable to retrieve location')
def get(self, client_id: UUID, group_id: UUID) -> {}: try: result = super(GroupStore, self).runProc('accounting.account_group_get', [ client_id, group_id ]) if len(result) > 0: return result[0] else: raise StoreException('No account group found') except Exception as e: log.error(e) raise StoreException('Unable to retrieve account group')
def get(self, client_id: UUID, project_id: UUID, task_id: UUID) -> dict: try: result = super(TaskStore, self).runProc('work.task_get', [ client_id, project_id, task_id ]) if len(result) > 0: return result[0] else: raise StoreException('Missing project task') except Exception as e: log.error(e) raise StoreException('Unable to retrieve project task')
def by_name(self, name: str) -> UUID: try: result = super(ClientStore, self).runProc('clients.client_by_name', [ super(ClientStore, self).remove_wildcards(name) ]) if len(result) > 0: client = result[0] client_id = client[0] return client_id else: raise StoreException('Unable to find client account using name') except Exception as e: log.error(e) raise StoreException('Unable to find client using name')
def add(self, transaction={}): try: client_id = transaction['clientId'] transaction_id = transaction['transactionId'] cn = super(TransactionStore, self).begin() c = cn.cursor() c.callproc('accounting.transaction_add', [ client_id, transaction_id, transaction['currencyId'], transaction['description'] ]) # process transaction items entries = transaction['entries'] for e in entries: c.callproc('accounting.transaction_item_add', [ client_id, transaction_id, e['id'], e['accountId'], e['debit'], e['credit'] ]) # process transaction attachments attachments = transaction[ 'attachments'] if 'attachments' in transaction else [] for a in attachments: c.callproc('accounting.transaction_attachment_add', [ client_id, transaction_id, a['id'], a['filename'], a['type'], a['size'], a['data'] ]) super(TransactionStore, self).commit(cn) except Exception as e: log.error(e) super(TransactionStore, self).rollback(cn) raise StoreException(e)
def update(self, client_id: UUID, project_id: UUID, name: str, description: str, planned_start: datetime, planned_end: datetime, actual_start: datetime, actual_end: datetime, tasks: list) -> None: cn = super(ProjectStore, self).begin() try: c = cn.cursor() c.callproc('work.project_update', [ client_id, project_id, name, description, planned_start, planned_end, actual_start, actual_end ]) for t in tasks: current_task_id = t['taskId'] status = t['status'] if status is None: c.callproc('work.task_add', [ client_id, project_id, current_task_id, t['name'], t['description'] ]) elif status == 'update': c.callproc('work.task_update', []) elif status == 'remove': c.callproc('work.task_remove', [client_id, project_id, current_task_id]) else: log.warning('Unhandled case %s', status) super(ProjectStore, self).commit(cn) except Exception as e: super(ProjectStore, self).rollback(cn) log.error(e) raise StoreException('Unable to update project')
def post(self, client_id: UUID, transaction_id: UUID) -> None: try: super(TransactionStore, self).runProcTransactional('accounting.transaction_post', [client_id, transaction_id]) except Exception as e: log.error(e) raise StoreException(e)
def assign_group(self, client_id: UUID, account_id: UUID, group_id: UUID): try: super(AccountsStore, self).runProcTransactional('accounting.account_assign_group', [client_id, account_id, group_id]) except Exception as e: log.error(e) raise StoreException('Unable to assign account to group')
def add(self, client_id: UUID, role_id: UUID, name: str) -> None: try: super(RolesStore, self).runProcTransactional( 'iam.role_add', [str(client_id), str(role_id), name]) except Exception as e: log.error(e) raise StoreException('Unable to add client role')
def filter(self, filter: str) -> []: try: return super(CountryStore, self).runProc('common.countries_filter', [f'%{filter}%']) except Exception as e: log.error(e) raise StoreException( 'Unable to retrieve a filtered list of countries')
def get(self, currency_id: int): try: return super(CurrencyStore, self).runProc('common.currency_get', [ currency_id, ]) except StoreException as e: log.error(e) raise StoreException('Unable to retrieve currency')
def filter(self, client_id: UUID, filter: str): try: return super(FacilityStore, self).runProc('inventory.facility_filter', [client_id, f'%{filter}%']) except Exception as e: log.error(e) raise StoreException('Unable to retrieve facilities')
def filter(self, client_id: UUID, filter: str) -> list: try: result = super(ProjectStore, self).runProc('work.project_filter', [client_id, f'%{filter}%']) return result except Exception as e: log.error(e) raise StoreException('Unable to retrieve projects')
def userByEmail(self, email: str): '''find user account by email address ''' try: [result, ] = super(UserStore, self).runProcTransactional('iam.user_get_by_email', [email, ]) return result except Exception as e: log.error(e) raise StoreException("Unable to find user account by email address")
def tree(self, client_id: UUID): try: result = super(GroupStore, self).runProc('accounting.account_group_tree', [ client_id, ]) return result except Exception as e: log.error(e) raise StoreException('Unable to retrieve account group tree')
def join(self, client_id: UUID, user_id: UUID) -> None: try: super(ClientStore, self).runProcTransactional('iam.client_user_join', [ str(client_id), str(user_id) ]) except Exception as e: log.error(e) raise StoreException('Unable to join client')
def update(self, client_id: UUID, account_id: UUID, name: str, description: str) -> None: try: super(AccountsStore, self).runProc('accounting.account_update', [client_id, account_id, name, description]) except Exception as e: log.error(e) raise StoreException('Unable to update account')
def filter(self, client_id: UUID, dimension: str, filter: str) -> []: try: return super(UOMStore, self).runProc('common.uom_filter', [client_id, dimension, f'%{filter}%']) except Exception as e: log.error(e) raise StoreException( 'Unable to retrieve filter list of units of measure')
def client_user_set_active(self, client_id: UUID, user_id: UUID, active: bool) -> None: try: super(UsersStore, self).runProcTransactional( 'iam.client_user_set_active', [str(client_id), str(user_id), active]) except Exception as e: log.error(e) raise StoreException('Unable to set client user to active')
def filter(self, client_id: UUID, filter: str): try: result = super(TransactionStore, self).runProc('accounting.transactions_filter', [client_id, f'%{filter}%']) return result except Exception as e: log.error(e) raise StoreException(e)
def accounts(self, client_id: UUID, group_id: UUID) -> []: try: result = super(GroupStore, self).runProc('accounting.account_group_accounts', [ client_id, group_id ]) return result except Exception as e: log.error(e) raise StoreException('Unable to retrieve account group accounts')
def assignParent(self, client_id: UUID, group_id: UUID, parent_group_id: UUID): try: super(GroupStore, self).runProcTransactional('accounting.account_group_assign_parent', [ client_id, group_id, parent_group_id ]) except Exception as e: log.error(e) raise StoreException(e)
def permissions(self, client_id: UUID, user_id: UUID) -> List[str]: try: result = super(UserStore, self).runProc('iam.client_user_permissions', [ str(client_id), str(user_id) ]) permissions = [r[0] for r in result] return permissions except Exception as e: log.error(e) raise StoreException('Unable to retrieve user permissions')
def userClients(self, user_id: UUID) -> list: '''retrieve clients allowed/available to user ''' try: result = super(UserStore, self).runProc('iam.user_clients_all', [ str(user_id), ]) return result except Exception as e: log.error(e) raise StoreException("Unable to retrieve user clients")
def userAdd(self, user_id: UUID, email: str, name: str) -> None: ''' add user ''' try: super(UserStore, self).runProcTransactional('iam.user_add', [ str(user_id), email, name ]) except Exception as e: log.error(e) raise StoreException('Unable to add user')