Пример #1
0
    def test_move_order_ok(self):

        cart = Cart()
        cart.product_id = 129
        cart.quantity = 1
        cart.subtotal = 34950
        cart.user_id = 733
        cart.size = '37'
        cart.price = 34950
        cart.Save()
        order = Order()
        order.voucher = ''
        order.type = 1
        order.subtotal = 34950
        order.shipping = 2490
        order.tax = 0
        order.total = 37440
        order.items_quantity = 1
        order.products_quantity = 1
        order.user_id = 733
        order.billing_id = 69
        order.shipping_id = 69
        order.payment_type = 2
        order.Save()

        order_detail = OrderDetail()
        order_detail.order_id = order.id
        order_detail.quantity = 1
        order_detail.product_id = 129
        order_detail.subtotal = 34950
        order_detail.size = '37'
        order_detail.price = 34950
        order_detail.Save()

        od = order_detail.ListByOrderId(order.id, 0, 0)

        ExitoHandler.moveStock(od, 733)

        query = '''\
                select * from "Kardex" 
                where cellar_id = 5 
                and product_sku = 'GDF-PV14-Lile-C9' 
                and size_id = 3 
                order by date desc limit 1'''
        kardex = BaseModel.execute_query(query)

        if len(kardex) > 0:
            self.assertEqual(kardex[0]["balance_units"], 3)

            query = '''\
                select * from "Kardex" 
                where cellar_id = 12 
                and product_sku = 'GDF-PV14-Lile-C9' 
                and size_id = 3 
                order by date desc limit 1'''
        kardex = BaseModel.execute_query(query)

        if len(kardex) > 0:
            self.assertEqual(kardex[0]["balance_units"], 2)
Пример #2
0
    def test_insert_order(self):


        user = User()
        user.name = 'Yi Chun'
        user.email = '*****@*****.**'
        user.user_type = 'Visita'
        user.Save()

        contact = Contact()
        contact.user_id = user.id
        contact.name = 'Casa'
        contact.telephone = '123456'
        contact.email = '*****@*****.**'
        contact.user_id = user.id
        contact.address = 'some address'
        contact.lastname = 'lin'
        contact.city = 1
        contact.zip_code = '734628347632'
        contact.additional_info = 'skjahjdahk'
        contact.town = 'sadjahsdkjah'
        contact.rut = '35172617356'
        contact.Save()

        # create a new user instance
        order = Order()
        order.date = datetime.now(pytz.timezone('Chile/Continental')).isoformat()
        order.type = Order.TIPO_WEB
        order.subtotal = 20000
        order.shipping = 2000
        order.tax = 0
        order.total = 22000
        order.items_quantity = 1
        order.products_quantity = 1
        order.user_id = user.id
        order.billing_id = contact.id
        order.shipping_id = contact.id
        order.payment_type = 1
        order.voucher = "image.png"
        order.state = Order.ESTADO_PENDIENTE
        res = order.Save()
        print order.date
        self.assertTrue('success' in res)
Пример #3
0
    def post(self):

        TBK_TIPO_TRANSACCION = self.get_argument("TBK_TIPO_TRANSACCION", "")
        TBK_MONTO = self.get_argument("TBK_MONTO", "")
        TBK_ID_SESION = self.get_argument("TBK_ID_SESION", "")
        TBK_URL_EXITO = self.get_argument("TBK_URL_EXITO", "")
        TBK_URL_FRACASO = self.get_argument("TBK_URL_FRACASO", "")

        payment_type = self.get_argument("payment_type", 2)
        costo_despacho = int(self.get_argument("shipping_price", 0))
        iva = int(self.get_argument("tax", 0))

        user_id = self.current_user["id"]

        order = Order()

        cart = Cart()
        cart.user_id = user_id

        lista = cart.GetCartByUserId()

        if len(lista) > 0:

            subtotal = 0
            cantidad_items = 0
            cantidad_productos = 0
            id_facturacion = 0
            id_despacho = 0
            total = 0
            info_despacho = ''
            info_facturacion = ''

            for l in lista:
                c = Cart()
                c.InitById(l["id"])
                c.payment_type = payment_type
                c.Edit()
                subtotal += l["subtotal"]
                cantidad_items += l["quantity"]
                cantidad_productos += 1
                id_facturacion = l["billing_id"]
                id_despacho = l["shipping_id"]
                total += l["subtotal"]
                info_despacho = l['shipping_info']
                info_facturacion = l['billing_info']

            order.date = datetime.now(
                pytz.timezone('Chile/Continental')).isoformat()
            order.type = Order.TIPO_WEB
            order.subtotal = subtotal
            order.shipping = costo_despacho
            order.tax = iva
            order.total = total + costo_despacho + iva
            order.items_quantity = cantidad_items
            order.products_quantity = cantidad_productos
            order.user_id = user_id
            order.billing_id = id_facturacion
            order.shipping_id = id_despacho
            order.payment_type = payment_type
            order.voucher = ""
            order.state = Order.ESTADO_PENDIENTE
            order.shipping_info = info_despacho
            order.billing_info = info_facturacion

            response_obj = order.Save()

            if "success" in response_obj:

                for l in lista:

                    detail = OrderDetail()
                    detail.order_id = order.id
                    detail.quantity = l["quantity"]
                    detail.subtotal = l["subtotal"]
                    detail.product_id = l["product_id"]
                    detail.size = l["size"]
                    detail.price = l["price"]
                    detail.Save()

                    # res_obj = detail.Save()
                    # if "error" in res_obj:
                    #     print "{}".format(res_obj["error"])

            # else:

            #     self.write(response_obj["error"])
            #     return

        if os.name != "nt":
            myPath = "{}webpay/dato{}.log" \
                .format(project_path, TBK_ID_SESION)
        else:
            myPath = "C:\Users\YiChun\Documents\giani\webpay\dato{}.log" \
                .format(TBK_ID_SESION)

        f = open(myPath, "w+")
        linea = "{};{}".format(TBK_MONTO, order.id)
        f.write(linea)
        f.close()

        data = {
            "TBK_TIPO_TRANSACCION": TBK_TIPO_TRANSACCION,
            "TBK_MONTO": TBK_MONTO,
            "TBK_ORDEN_COMPRA": order.id,
            "TBK_ID_SESION": TBK_ID_SESION,
            "TBK_URL_EXITO": TBK_URL_EXITO,
            "TBK_URL_FRACASO": TBK_URL_FRACASO,
            "shipping": costo_despacho,
            "subtotal": subtotal
        }

        # self.write(json_util.dumps(data))
        user_id = self.current_user["id"]
        cart = Cart()
        cart.user_id = user_id
        lista = cart.GetCartByUserId()

        self.render("transbank.html", data=data, lista=lista)