Example #1
0
    def get(self):

        product = Product()
        cart = Cart()
        cart.product_id = self.get_argument("product_id", "")
        cart.quantity = int(self.get_argument("quantity", 0))

        if cart.quantity > 0:

            if cart.product_id != "":

                response_obj = product.InitById(cart.product_id)

                if "success" in response_obj:

                    if product.promotion_price != 0:
                        subtotal = int(product.promotion_price) * cart.quantity
                        cart.price = product.promotion_price
                    else:
                        subtotal = int(product.sell_price) * cart.quantity
                        cart.price = product.sell_price

                    if self.current_user:
                        if self.current_user["type_id"] == 4:
                            subtotal = int(product.bulk_price) * cart.quantity
                            cart.price = product.bulk_price

                    size_id = self.get_argument("size", "")

                    size = Size()
                    size.id = size_id
                    res_name = size.initById()

                    if "error" in res_name:
                        self.write(res_name["error"])
                    else:
                        cart.size = size.name

                    cart.date = datetime.now(
                        pytz.timezone('Chile/Continental')).isoformat()
                    cart.subtotal = subtotal
                    cart.user_id = self.get_argument("user_id", -1)

                    if self.current_user:
                        cart.user_id = self.current_user["id"]

                    response_obj = cart.Save()

                    product.updateAdded(product.sku)

                    if "success" in response_obj:
                        self.write("ok")
                    else:
                        self.write(response_obj["error"])
                else:
                    self.write(response_obj["error"])
            else:
                self.write("Product ID is empty")
        else:
            self.write("ok")
Example #2
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)