def employees(): # TODO: Only list clients that are assigned to salesperson or one a # a director/manager manages. employees = flatten_hierarchy(current_user.employee, lambda employee: employee.clients) title = 'All Employees' return render_template('employees.html', title=title, employees=employees)
def sales(): # TODO: Needs QA - particularly worried about getting all sales in a # management hierarchy emp = current_user.employee order_ids = flatten_hierarchy(emp, lambda e: [order.id for order in e.orders]) orders = Order.query.filter(Order.id.in_(tuple(order_ids))).all() return render_template('sales.html', title='Sales', orders=orders)
def employee_orders(employee): if employee.title == 'Salesperson': order_list = employee.orders else: order_list = flatten_hierarchy(employee, lambda e: e.orders) return render_template('employee_orders.html', title='All Orders', orders=order_list)
def sales(): emp = current_user.employee order_ids = flatten_hierarchy(emp, lambda e: [order.id for order in e.orders]) orders = Order.query.filter(Order.id.in_(tuple(order_ids))).all() return render_template('sales.html', title='Sales', orders=orders)
def view_employee_order(employee, order_id): all_orders = flatten_hierarchy(employee, lambda e: e.orders) matches = [order for order in all_orders if order.id == order_id] if matches == []: abort(404) order = matches[0] return render_template('employee_view_order.html', title='Order Details', order=order)
def add_client(): form = AddClientForm() all_reports = flatten_hierarchy(current_user.employee, lambda e: [e]) salesperson_ids = [(s.employee_id, s.username) for s in all_reports if s.title == 'Salesperson'] form.salesperson_id.choices = salesperson_ids if form.validate_on_submit(): cli = Client() cli.username = form.username.data cli.password_hash = unicode(bcrypt.generate_password_hash(form.password1.data)) cli.active = True cli.is_employee = False cli.company = form.company.data cli.salesperson_id = form.salesperson_id.data db.session.add(cli) db.session.commit() flash('Client added successfully') return redirect(url_for('clients')) flash_form_errors(form) return render_template('add_client.html', title='Add Client', form=form)
def edit_client(client_id): cli = Client.query.filter_by(client_id=client_id).first() if cli is None: abort(404) form = EditClientForm(obj = cli) title = 'Edit Client' all_reports = flatten_hierarchy(current_user.employee, lambda e: [e]) salesperson_ids = [(s.employee_id, s.username) for s in all_reports if s.title == 'Salesperson'] form.salesperson_id.choices = salesperson_ids new_salesperson = form.salesperson_id.data if form.validate_on_submit(): cli.salesperson_id = new_salesperson db.session.commit() flash('Client updated successfully') return redirect('/clients/') return render_template('edit_client.html', title = 'Edit Client - %s' % (cli.username), form=form)
def clients(): clients = flatten_hierarchy(current_user.employee, lambda employee: employee.clients) title = 'All Clients' return render_template('clients.html', title=title, clients=clients)