Exemplo n.º 1
0
def requests():
    trans = EnterpriseAPI.GetRequests()
    itms = EnterpriseAPI.ItemPicker()
    pkgs = EnterpriseAPI.PackagePicker()
    wh = EnterpriseAPI.GetWareHouses()
    appr = EnterpriseAPI.InvApprovers()
    if request.method == 'POST':
        if request.form['submit'] == 'Submit':
            if (request.form['status'] == 'Approved'
                    or request.form['status'] == 'Rejected'
                ) and request.form['approver'] != session['username']:
                flash(
                    "Can't proceed with request, approver's permission is required.",
                    category='fail')
                return redirect(url_for('logistics.requests'))
            else:
                try:
                    data, code = EnterpriseAPI.CreateRequest(
                        session['username'], session['password'],
                        request.form['type'], request.form['status'],
                        request.form['approver'], request.form['comments'],
                        request.form.getlist('code'),
                        request.form.getlist('Name'),
                        request.form.getlist('unit'),
                        request.form.getlist('quantity'))

                    msg = Message('New Inventory request',
                                  recipients=[data[2]])
                    msg.body = "Dear {}, \n Please note that new inventory request, code: {} has been created and requires your approval or rejection.".format(
                        data[0], code)
                    app.mail.send(msg)

                    flash('Request successfully added.', category='success')
                    return redirect(url_for('logistics.requests'))
                except Exception as e:
                    flash(str(e), category='fail')
                    return redirect(url_for('logistics.requests'))
    return render_template('logistics/requests.html',
                           username=session['username'],
                           role=session['role'],
                           trans=trans,
                           wh=wh,
                           itms=itms,
                           pkgs=pkgs,
                           appr=appr)
Exemplo n.º 2
0
def edit_request(reqid):
    trans = EnterpriseAPI.GetRequests()
    itms = EnterpriseAPI.ItemPicker()
    pkgs = EnterpriseAPI.PackagePicker()
    wh = EnterpriseAPI.GetWareHouses()
    appr = EnterpriseAPI.InvApprovers()
    head, details, aprv = EnterpriseAPI.ReqInfo(reqid)
    if request.method == 'POST':
        if request.form['submit'] == 'Submit':
            if (request.form['status'] == 'Approved'
                    or request.form['status'] == 'Rejected'
                ) and request.form['approver'] != session['username']:
                flash(
                    "Can't proceed with request, approver's permission is required.",
                    category='fail')
                return redirect(url_for('logistics.requests'))
            else:
                try:
                    EnterpriseAPI.UpdateRequest(session['username'],
                                                session['password'],
                                                request.form['status'],
                                                request.form['comments'],
                                                reqid)
                    flash('Request Updated', category='success')
                    return redirect(url_for('logistics.requests'))
                except Exception as e:
                    flash(str(e), category='fail')
                    return redirect(url_for('logistics.requests'))
    return render_template('logistics/edit_request.html',
                           username=session['username'],
                           role=session['role'],
                           trans=trans,
                           wh=wh,
                           appr=appr,
                           head=head,
                           details=details,
                           aprv=aprv)