当前位置: 首页>>代码示例>>Python>>正文


Python Customer.order_no方法代码示例

本文整理汇总了Python中models.Customer.order_no方法的典型用法代码示例。如果您正苦于以下问题:Python Customer.order_no方法的具体用法?Python Customer.order_no怎么用?Python Customer.order_no使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Customer的用法示例。


在下文中一共展示了Customer.order_no方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createRequest

# 需要导入模块: from models import Customer [as 别名]
# 或者: from models.Customer import order_no [as 别名]
def createRequest():
    cust = flask.request.args.get('cust')
    if not cust:
        cust = 'cust'
    if cust == 'cust':
        formCustomer = SelectCustomerForm()
        cust_customers = Customer.query.filter_by(customer_type=CUSTOMER_TYPES['TYPE_CUSTOMER']).all()
        cust_customers = [(a.id, a.name) for a in cust_customers]
        cust_customers = [(0, '')] + cust_customers
        formCustomer.customer.choices = cust_customers
    else:
        formCustomer = OrderNumberForm()
    makers = Maker.query.all()
    maker_choices = [(a.id, a.name) for a in makers]
    maker_choices = [(0, '')] + maker_choices
    formCustomer.maker.choices = maker_choices
    if formCustomer.is_submitted():
        ids = {}
        for attr in flask.request.form:
            if attr.startswith("req_qty-"):
                key = attr.split('-')[1]
                ids[key] = flask.request.form[attr]
        if ids:
            if cust == 'cust':
                cust_id = int(formCustomer.customer.data)
                if not cust_id:
                    flash(gettext("No customer id."))
                    return redirect(url_for("requests"))
                req_cust = db.session.query(Customer).filter_by(id=cust_id).first()
                if not req_cust:
                    flash(gettext("Customer not found."))
                    return redirect(url_for("requests"))
                if req_cust.customer_type != CUSTOMER_TYPES['TYPE_CUSTOMER']:
                    flash(gettext("Invalid customer!"))
                    return redirect(url_for("requests"))

            elif cust == 'axm':
                order_no = formCustomer.order_no.data
                if not order_no:
                    flash(gettext("No order number."))
                    return redirect(url_for("axm_requests"))
                req_cust = db.session.query(Customer).filter_by(order_no=order_no).first()
                if req_cust:
                    flash(gettext("Order number already exists!"))
                    return redirect(url_for("axm_requests"))
                req_cust = Customer()
                req_cust.customer_type = CUSTOMER_TYPES['TYPE_AXM']
                req_cust.order_no = order_no
                db.session.add(req_cust)
                db.session.commit()
            else:
                flash(gettext("Invalid data received!"))
                return redirect(url_for("requests"))

            new_request = Request()
            new_request.user_id = g.user.id
            new_request.customer_id = req_cust.id
            if formCustomer.datetime.data:
                new_request.created_dt = formCustomer.datetime.data
            else:
                flash("Date and time date of request was entered incorrectly, request saved with current date and time.")

            if cust == 'axm':
                if formCustomer.payment_method.data is not None:
                    new_request.payment_method = formCustomer.payment_method.data
                else:
                    new_request.payment_method = 1
                if formCustomer.paid_for_flg is not None:
                    new_request.paid_for_flg = formCustomer.paid_for_flg.data
                else:
                    new_request.paid_for_flg = 0

            new_request.active_flg = True
            db.session.add(new_request)
            db.session.commit()

            for id in ids:
                new_product = db.session.query(Product).filter_by(id=id).first()
                if not new_product:
                    flash(gettext("Product not found."))
                    return redirect(url_for("requests"))
                rp = RequestedProducts(quantity=int(ids[id]))
                rp.product = new_product
                rp.request_id = new_request.id
                new_request.products.append(rp)

            db.session.commit()
            flash(gettext("Order created successfully."))
            if cust == 'axm':
                return redirect(url_for("axm_requests"))
            return redirect(url_for("requests"))

        else:
            flash(gettext("Order data not sent."))
            return redirect(url_for("requests"))

    formCustomer.datetime.data = datetime.utcnow()
    return render_template('requests/createRequest.html',
                           title=gettext("Accept order from customer"),
                           formCustomer=formCustomer,
#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:


注:本文中的models.Customer.order_no方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。