示例#1
0
文件: cart.py 项目: canhuayin/hunter
def cart_to_order():
    try:
        shipping_id = int(request.form.get("shipping_id", 0))
        invoice_id = int(request.form.get("invoice_id", 0))
        if shipping_id == 0:
            raise LocalException("请选择收货地址")
        if invoice_id == 0:
            raise LocalException("请选择发票地址")
        cart_id = OBJ.execute(
            session["db"],
            1,
            admin_pwd,
            "sale.order",
            "search",
            [
                ("partner_id", "=", User(db=session["db"]).read(session["uid"])["partner_id"][0]),
                ("state", "=", "draft"),
            ],
        )
        flag = OBJ.execute(
            session["db"],
            1,
            admin_pwd,
            "sale.order",
            "write",
            cart_id,
            {"partner_invoice_id": invoice_id, "partner_shipping_id": shipping_id, "state": "sale"},
        )
        return make_response(json.dumps({"flag": "True", "msg": cart_id[0], "status": 200}))
    except LocalException as e:
        return make_response(json.dumps({"flag": "False", "msg": e.message, "status": 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({"flag": "False", "msg": u"生成订单失败,请稍后再试!", "status": 200}))
示例#2
0
文件: user.py 项目: canhuayin/hunter
def user_address_add():
    try:
        user = User(db=session['db']).read(session['uid'])
        partner_id = user['partner_id']
        form = request.form
        formtype = form['formtype']
        if formtype == 'add':
            address = OBJ.execute(session['db'], 1, admin_pwd, 'res.partner', 'create',
                                  {'name': form['name'], 'street': form['street'], 'city': form['city'],
                                   'zip': form['zip'], 'parent_id': partner_id[0],
                                   'phone': form['phone'], 'mobile': form['mobile'], 'email': form['email'],
                                   'user_id': session['uid'], 'type': 'delivery'})
        else:
            flag = OBJ.execute(session['db'], 1, admin_pwd, 'res.partner', 'write', [int(form['id'])],
                               {'name': form['name'], 'street': form['street'], 'city': form['city'],
                                'zip': form['zip'], 'parent_id': partner_id[0],
                                'phone': form['phone'], 'mobile': form['mobile'], 'email': form['email'],
                                'user_id': session['uid'], 'type': form['type']})

        return make_response(json.dumps({'flag': 'True', 'msg': '', 'status': 200}))
    except LocalException as e:
        return make_response(json.dumps({'flag': 'False', 'msg': e.message, 'status': 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({'flag': 'False', 'msg': u'地址更新失败,请稍后再试!', 'status': 200}))
示例#3
0
文件: user.py 项目: zhishan33/hunter
def user_address_update():
    try:
        pass
    except LocalException as e:
        return make_response(json.dumps({"flag": "False", "msg": e.message, "status": 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({"flag": "False", "msg": u"修改产品数量失败,请稍后再试!", "status": 200}))
示例#4
0
文件: order.py 项目: zhishan33/hunter
def order_delete():
    try:
        pass
    except LocalException as e:
        return make_response(json.dumps({'flag': 'False', 'msg': e.message, 'status': 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({'flag': 'False', 'msg': u'删除订单失败,请稍后再试!', 'status': 200}))
示例#5
0
def product_share():
    try:
        pass
    except LocalException as e:
        return make_response(json.dumps({'flag': 'False', 'msg': e.message, 'status': 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({'flag': 'False', 'msg': u'产品分享失败,请稍后再试!', 'status': 200}))
示例#6
0
文件: cart.py 项目: canhuayin/hunter
def cart_alipay(order_id):
    try:
        return render_template("hunter_order_alipay.html", order_id=order_id)
    except LocalException as e:
        return make_response(json.dumps({"flag": "False", "msg": e.message, "status": 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({"flag": "False", "msg": u"生成订单失败,请稍后再试!", "status": 200}))
示例#7
0
def product_category():
    try:
        pass
    except LocalException as e:
        return make_response(json.dumps({'flag': 'False', 'msg': e.message, 'status': 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({'flag': 'False', 'msg': u'获取产品分类失败,请稍后再试!', 'status': 200}))  # 添加商品至购物车
示例#8
0
def reception_repayment():
    try:
        pass
    except LocalException as e:
        return make_response(json.dumps({'flag': 'False', 'msg': e.message, 'status': 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({'flag': 'False', 'msg': u'添加购物车失败,请稍后再试!', 'status': 200}))
示例#9
0
def reception_scan():
    try:
        pass
    except LocalException as e:
        return make_response(json.dumps({"flag": "False", "msg": e.message, "status": 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({"flag": "False", "msg": u"添加购物车失败,请稍后再试!", "status": 200}))
示例#10
0
文件: cart.py 项目: canhuayin/hunter
def cart_delete():
    try:
        OBJ.execute(session["db"], 1, admin_pwd, "sale.order.line", "unlink", [int(request.form["id"])])
        return make_response(json.dumps({"flag": "True", "msg": "", "status": 200}))
    except LocalException as e:
        return make_response(json.dumps({"flag": "False", "msg": e.message, "status": 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({"flag": "False", "msg": u"删除产品失败,请稍后再试!", "status": 200}))
示例#11
0
文件: order.py 项目: canhuayin/hunter
def order_delete():
    try:
        OBJ.execute(session['db'], 1, admin_pwd, 'sale.order', 'write', int(request.form['id']), {'state': 'draft'})
        OBJ.execute(session['db'], 1, admin_pwd, 'sale.order', 'unlink', int(request.form['id']), )
        return make_response(json.dumps({'flag': 'True', 'msg': '', 'status': 200}))
    except LocalException as e:
        return make_response(json.dumps({'flag': 'False', 'msg': e.message, 'status': 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({'flag': 'False', 'msg': u'删除订单失败,请稍后再试!', 'status': 200}))
示例#12
0
文件: user.py 项目: canhuayin/hunter
def user_address_delete():
    try:
        id = request.form['id']
        Address(db=session['db']).unlink([int(id)])
        return make_response(json.dumps({'flag': 'True', 'msg': '', 'status': 200}))
    except LocalException as e:
        return make_response(json.dumps({'flag': 'False', 'msg': e.message, 'status': 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({'flag': 'False', 'msg': u'地址删除失败,请稍后再试!', 'status': 200}))
示例#13
0
文件: cart.py 项目: canhuayin/hunter
def cart_wechatpay(order_id):
    try:
        sale_order = OBJ.execute(session["db"], 1, admin_pwd, "sale.order", "read", order_id, ["name", "amount_total"])
        para = wechatpay_form_generate_values(ordername=sale_order["name"], total_fee=sale_order["amount_total"])
        flag, url = createqrimage(para=para)
        if flag:
            return render_template("hunter_order_wechatpay.html", payurl=url)
        else:
            return render_template("hunter_order_wechatpay.html", payurl=url, errmsg=url)
    except LocalException as e:
        return make_response(json.dumps({"flag": "False", "msg": e.message, "status": 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({"flag": "False", "msg": u"生成订单失败,请稍后再试!", "status": 200}))
示例#14
0
文件: cart.py 项目: canhuayin/hunter
def cart_update():
    try:
        cartline = int(request.form["cartline"])
        quantity = int(request.form["qty"])
        flag = OBJ.execute(
            session["db"], 1, admin_pwd, "sale.order.line", "write", cartline, {"product_uom_qty": quantity}
        )
        if flag:
            return make_response(json.dumps({"flag": "True", "msg": "", "status": 200}))
        else:
            raise LocalException(u"修改产品数量失败,请稍后再试")
    except LocalException as e:
        return make_response(json.dumps({"flag": "False", "msg": e.message, "status": 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({"flag": "False", "msg": u"修改产品数量失败,请稍后再试!", "status": 200}))
示例#15
0
def reception_surround():
    try:
        pass
    except LocalException as e:
        return make_response(
            json.dumps({
                'flag': 'False',
                'msg': e.message,
                'status': 200
            }))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(
            json.dumps({
                'flag': 'False',
                'msg': u'添加购物车失败,请稍后再试!',
                'status': 200
            }))
示例#16
0
文件: user.py 项目: zhishan33/hunter
def user_address_delete():
    try:
        pass
    except LocalException as e:
        return make_response(
            json.dumps({
                'flag': 'False',
                'msg': e.message,
                'status': 200
            }))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(
            json.dumps({
                'flag': 'False',
                'msg': u'修改产品数量失败,请稍后再试!',
                'status': 200
            }))
示例#17
0
文件: user.py 项目: canhuayin/hunter
def user_update():
    try:
        form = request.form
        name = form.get('name', '')
        email = form.get('email', '')
        birthdate = form.get('birthdate', '')
        city = form.get('city', '')
        street = form.get('street', '')
        image = request.files.get('image', False)
        # import pdb
        # pdb.set_trace()
        if image:
            image = base64.b64encode(image.read())
        else:
            image = None
        User(db=session['db']).update_info(name, email, session['uid'], city, birthdate, street, image)
        return make_response(json.dumps({'flag': 'True', 'msg': '', 'status': 200}))
    except LocalException as e:
        return make_response(json.dumps({'flag': 'False', 'msg': e.message, 'status': 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({'flag': 'False', 'msg': u'更新信息失败,请稍后再试!', 'status': 200}))
示例#18
0
def product_search():
    try:
        limit = 15
        count = OBJ.execute(session['db'], 1, admin_pwd, 'product.template', 'search_count', [])

        offset = int(request.form.get('offset', 0))

        category = int(request.form.get('category', 0))
        domain = []
        if category != 0:
            domain.append(('categ_id', '=', category))
        if count <= offset:
            products = []
        else:
            product_ids = OBJ.execute(session['db'], 1, admin_pwd, 'product.template', 'search', domain)[
                          offset:offset + limit]
            products = OBJ.execute(session['db'], 1, admin_pwd, 'product.template', 'read', product_ids)
        return make_response(json.dumps(
            {'flag': 'True', 'html': render_template('hunter_product_search.html', products=products), 'status': 200}))
    except LocalException as e:
        return make_response(json.dumps({'flag': 'False', 'msg': e.message, 'status': 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({'flag': 'False', 'msg': u'搜索失败,请稍后再试!', 'status': 200}))  # 添加商品至购物车
示例#19
0
文件: cart.py 项目: canhuayin/hunter
def cart_add():
    try:
        if not session.get("uid", False):
            raise LocalException("请登陆后操作")
        product_id = int(request.form["product_id"])
        quantity = int(request.form["quantity"])
        partner_id = User(db=session["db"]).read(session["uid"])["partner_id"][0]
        cart = SaleOrder(db=session["db"]).search([("partner_id", "=", partner_id), ("state", "=", "draft")])
        product = Product(db=session["db"]).read(product_id)
        if not cart:
            cart = [
                OBJ.execute(
                    session["db"], 1, admin_pwd, "sale.order", "create", {"state": "draft", "partner_id": partner_id}
                )
            ]
        else:
            orderline_id = OBJ.execute(
                session["db"],
                1,
                admin_pwd,
                "sale.order.line",
                "search",
                [("order_id", "=", cart[0]), ("product_id", "=", product_id)],
            )
            if orderline_id:
                quantity += OBJ.execute(
                    session["db"], 1, admin_pwd, "sale.order.line", "read", orderline_id[0], ["product_uom_qty"]
                )["product_uom_qty"]
                flag = OBJ.execute(
                    session["db"],
                    1,
                    admin_pwd,
                    "sale.order.line",
                    "write",
                    orderline_id[0],
                    {"product_uom_qty": quantity},
                )
                return make_response(json.dumps({"flag": "True", "msg": "", "status": 200}))
        saleline = OBJ.execute(
            session["db"],
            1,
            admin_pwd,
            "sale.order.line",
            "create",
            {
                "product_id": product["id"],
                "order_id": cart[0],
                "order_partner_id": partner_id,
                "product_uom_qty": quantity,
                "price_unit": product["list_price"],
                "state": "draft",
                "name": product["name"],
                "product_uom": 1,
            },
        )
        return make_response(json.dumps({"flag": "True", "msg": "", "status": 200}))
    except LocalException as e:
        return make_response(json.dumps({"flag": "False", "msg": e.message, "status": 200}))
    except Exception as e:
        PrintLog.print_normal_log(request.form)
        return make_response(json.dumps({"flag": "False", "msg": u"添加购物车失败,请稍后再试!", "status": 200}))