def get(self): """Return salesperson of an account """ context = pecan.request.context user_id = self.user_id conn = pecan.request.db_conn account = conn.get_account(context, user_id) sales_id = account.sales_id if not sales_id: # Only allow sales admin to know that an account # belongs to no salesperson. check_policy(context, 'uos_sales_admin') return models.SalesPerson() # Only allow salesperson to get account that # belongs to himself/herself. if not acl.limit_to_sales(context, sales_id): raise exception.NotAuthorized() try: sales_user = keystone.get_uos_user(sales_id) return models.SalesPerson( user_id=sales_id, user_name=sales_user['name'], user_email=sales_user.get('email', ''), real_name=sales_user.get('real_name', ''), mobile_number=sales_user.get('mobile_number', ''), company=sales_user.get('company', '') ) except (exception.NotFound): msg = _('Could not find salesperson %s of account %s' ' from keystone' % (sales_id, user_id)) LOG.error(msg) raise exception.NotFound(msg)
def get(self): """Return salesperson of an account """ context = pecan.request.context user_id = self.user_id conn = pecan.request.db_conn account = conn.get_account(context, user_id) sales_id = account.sales_id if not sales_id: # Only allow sales admin to know that an account # belongs to no salesperson. check_policy(context, 'uos_sales_admin') return models.SalesPerson() # Only allow salesperson to get account that # belongs to himself/herself. if not acl.limit_to_sales(context, sales_id): raise exception.NotAuthorized() try: sales_user = keystone.get_uos_user(sales_id) return models.SalesPerson( user_id=sales_id, user_name=sales_user['name'], user_email=sales_user.get('email', ''), real_name=sales_user.get('real_name', ''), mobile_number=sales_user.get('mobile_number', ''), company=sales_user.get('company', '')) except (exception.NotFound): msg = _('Could not find salesperson %s of account %s' ' from keystone' % (sales_id, user_id)) LOG.error(msg) raise exception.NotFound(msg)
def get(self, offset=None, limit=None): """Get the accounts of this sales person.""" context = pecan.request.context if not acl.limit_to_sales(context, self.sales_id): raise exception.NotAuthorized() if limit and limit < 0: raise exception.InvalidParameterValue(err="Invalid limit") if offset and offset < 0: raise exception.InvalidParameterValue(err="Invalid offset") conn = pecan.request.db_conn accounts_number, sales_amount = conn.get_salesperson_amount( context, self.sales_id) accounts = conn.get_salesperson_customer_accounts( context, self.sales_id, offset, limit) account_list = [] for account in accounts: user = keystone.get_uos_user(account.user_id) account_list.append( models.SalesPersonAccount( user_id=account.user_id, user_name=user['name'], user_email=user.get('email', ''), real_name=user.get('real_name', ''), mobile_number=user.get('mobile_number', ''), company=user.get('company', ''), balance=account.balance, consumption=account.consumption, owed=account.owed ) ) return models.SalesPersonAccounts( total_count=accounts_number, accounts=account_list)
def get(self, offset=None, limit=None): """Get the accounts of this sales person.""" context = pecan.request.context if not acl.limit_to_sales(context, self.sales_id): raise exception.NotAuthorized() if limit and limit < 0: raise exception.InvalidParameterValue(err="Invalid limit") if offset and offset < 0: raise exception.InvalidParameterValue(err="Invalid offset") conn = pecan.request.db_conn accounts_number, sales_amount = conn.get_salesperson_amount( context, self.sales_id) accounts = conn.get_salesperson_customer_accounts( context, self.sales_id, offset, limit) account_list = [] for account in accounts: user = kunkka.get_uos_user(account.user_id) account_list.append( models.SalesPersonAccount(user_id=account.user_id, user_name=user['name'], user_email=user.get('email', ''), real_name=user.get('real_name', ''), mobile_number=user.get('phone', ''), company=user.get('company', ''), balance=account.balance, consumption=account.consumption, owed=account.owed)) return models.SalesPersonAccounts(total_count=accounts_number, accounts=account_list)
def amount(self): """Get the sales amount of this sales person.""" context = pecan.request.context if not acl.limit_to_sales(context, self.sales_id): raise exception.NotAuthorized() conn = pecan.request.db_conn accounts_number, sales_amount = conn.get_salesperson_amount( context, self.sales_id) return models.SalesPersonAmount( sales_amount=sales_amount, accounts_number=accounts_number)
def amount(self): """Get the sales amount of this sales person.""" context = pecan.request.context if not acl.limit_to_sales(context, self.sales_id): raise exception.NotAuthorized() conn = pecan.request.db_conn accounts_number, sales_amount = conn.get_salesperson_amount( context, self.sales_id) return models.SalesPersonAmount(sales_amount=sales_amount, accounts_number=accounts_number)