コード例 #1
0
def customers_update(customer_id):
    page = request.args.get('page', 1, type=int)
    form = CustomerForm(request.form)
    customer = Customer.query.get_or_404(customer_id)
    orders = Order.query.filter(Order.customer_id == customer.id).order_by(Order.date_created.desc()).paginate(page=page, per_page=8)
    available_organizations = Organization.query.all()
    form.organization_id.choices = [(o.id, o.name) for o in available_organizations]

    if not form.validate():
        now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        user_block = Block.query.filter(Block.customer_id == customer_id).filter(Block.date_end >= now).order_by(Block.date_end.desc()).first()
        block_form = CustomerBlockForm()
        block_end_date = customer.get_block_status()

        return render_template("/customers/details.html", customer=customer, orders=orders, form=form, visibility="visible", block_end_date=block_end_date, user_block=user_block, block_form=block_form)

    customer.first_name = form.first_name.data.lower().capitalize()
    customer.last_name = form.last_name.data.lower().capitalize()
    customer.birthday = form.birthday.data
    customer.balance = int(round(form.balance.data * 100, 2))
    customer.organization_id = form.organization_id.data

    db.session().commit()

    return redirect(url_for("customers_details", customer_id=customer_id))
コード例 #2
0
ファイル: views.py プロジェクト: emmalait/project-time-mgmt
def customers_create():
    form = CustomerForm(request.form)

    if not form.validate():
        return render_template("customers/new.html", form=form)

    c = Customer(form.name.data, form.business_id.data)

    db.session().add(c)
    db.session().commit()

    return redirect(url_for("customers_index"))
コード例 #3
0
def customers_form():
    available_organizations = Organization.query.all()
    organizations_list = [(o.id, o.name) for o in available_organizations]
    form = CustomerForm()
    form.organization_id.choices = organizations_list

    return render_template("customers/new.html", form=form)
コード例 #4
0
def customers_create():
    form = CustomerForm(request.form)
    available_organizations = Organization.query.all()
    form.organization_id.choices = [(o.id, o.name) for o in available_organizations]    

    if not form.validate():
        return render_template("customers/new.html", form=form)

    new_customer = Customer (
        form.first_name.data.lower().capitalize(),
        form.last_name.data.lower().capitalize(),
        form.birthday.data,
        int(round(form.balance.data * 100, 2)),
        form.organization_id.data
    )

    db.session().add(new_customer)
    db.session().commit()

    return redirect(url_for("customers_index"))
コード例 #5
0
ファイル: views.py プロジェクト: juusotaneli/simple-crm
def customer_update(id):
    customer = Customer.query.get(id)
    form = CustomerForm(request.form)

    # jos käyttäjä antaa uuden nimen ja / tai erp_id:m, tarkastetaan ettei nimeä/idtä ole jo käytössä jollain muulla asiakkaalla.
    # jos molemmat arvot ovat muuttumattomat, tallennetaan suoraan tietokantaan.
    if request.method == "POST":
        if request.form.get("name").upper(
        ) != customer.name and Customer.query.filter_by(
                name=request.form.get("name").upper()).scalar() is not None:
            return render_template("customers/updatepage.html",
                                   error1=True,
                                   form=form,
                                   customer=customer)

        elif request.form.get(
                "erp_id") != customer.erp_id and Customer.query.filter_by(
                    erp_id=request.form.get("erp_id")).scalar() is not None:
            return render_template("customers/updatepage.html",
                                   error2=True,
                                   form=form,
                                   customer=customer)

        else:
            customer.name = request.form.get("name").upper()
            customer.erp_id = request.form.get("erp_id")
            customer.route = request.form.get("route")
            customer.contact_person = request.form.get("contact_person")
            customer.phone_number = request.form.get("phone_number")
            customer.email = request.form.get("email")

            db.session().commit()

            return redirect(url_for("customer_page", id=customer.id))

    else:
        form = CustomerForm(request.form)
        return render_template("customers/updatepage.html",
                               form=form,
                               customer=customer)
コード例 #6
0
def customers_details(customer_id):
    page = request.args.get('page', 1, type=int)
    customer = Customer.query.get_or_404(customer_id)
    orders = Order.query.filter(Order.customer_id == customer.id).order_by(Order.date_created.desc()).paginate(page=page, per_page=8)
    block_end_date = customer.get_block_status()

    form = CustomerForm()
    available_organizations = Organization.query.all()
    organizations_list = [(o.id, o.name) for o in available_organizations]
    form.organization_id.choices = organizations_list

    block_form = CustomerBlockForm()

    return render_template("/customers/details.html", customer=customer, orders=orders, form=form, visibility="hidden", block_end_date=block_end_date, block_form=block_form)
コード例 #7
0
ファイル: views.py プロジェクト: juusotaneli/simple-crm
def customers_create():
    form = CustomerForm(request.form)

    if not form.validate():
        return render_template("customers/new.html", form=form)
    # tarkistaa että lisättyä asiakasta ei ole vielä tarkistamalla tietokannasta
    # löytyykö asiakas syötetyllä nimellä tai erp_idellä --purkkaratkaisu--
    # todo: validaattorit formiin.
    elif Customer.query.filter_by(
            name=request.form.get("name").upper()).scalar() is not None:
        return render_template("customers/new.html", error1=True, form=form)
    elif Customer.query.filter_by(
            erp_id=request.form.get("erp_id")).scalar() is not None:
        return render_template("customers/new.html", error2=True, form=form)

    c = Customer(form.name.data.upper(), form.erp_id.data, form.route.data,
                 form.contact_person.data, form.phone_number.data,
                 form.email.data)

    db.session().add(c)
    db.session().commit()

    return redirect(url_for("customer_page", id=c.id))
コード例 #8
0
ファイル: views.py プロジェクト: emmalait/project-time-mgmt
def customers_form():
    return render_template("customers/new.html", form=CustomerForm())